1/*
2 *  FopNature.java
3 *  Copyright (C) 2005 Amin Ahmad.
4 *
5 *  This library is free software; you can redistribute it and/or
6 *  modify it under the terms of the GNU Lesser General Public
7 *  License as published by the Free Software Foundation; either
8 *  version 2.1 of the License, or (at your option) any later version.
9 *
10 *  This library is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 *  Lesser General Public License for more details.
14 *
15 *  You should have received a copy of the GNU Lesser General Public
16 *  License along with this library; if not, write to the Free Software
17 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 *
19 *  Amin Ahmad can be contacted at amin.ahmad@gmail.com or on the web at
20 *  www.ahmadsoft.org.
21 */
22package org.ahmadsoft.foprocessor.natures;
23
24import org.ahmadsoft.foprocessor.FoProcessorPlugin;
25import org.eclipse.core.resources.ICommand;
26import org.eclipse.core.resources.IProject;
27import org.eclipse.core.resources.IProjectDescription;
28import org.eclipse.core.resources.IProjectNature;
29import org.eclipse.core.runtime.CoreException;
30
31/**
32 * FOP project nature.
33 * @author Amin Ahmad
34 */
35public class FopNature implements IProjectNature {
36
37	private IProject project;
38
39	public void configure() throws CoreException {
40		IProjectDescription description = getProject().getDescription();
41		ICommand[] commands= description.getBuildSpec();
42		for (ICommand command: commands) {
43			if (command.getBuilderName().equals(FoProcessorPlugin.FOP_RENDERER))
44				return;
45		}
46
47		ICommand command = description.newCommand();
48		command.setBuilderName(FoProcessorPlugin.FOP_RENDERER);;
49		ICommand[] newCommands = new ICommand[commands.length+1];
50		System.arraycopy(commands, 0, newCommands, 0, commands.length);
51		newCommands[commands.length]= command;
52		description.setBuildSpec(newCommands);
53		getProject().setDescription(description, null);
54	}
55
56	public void deconfigure() throws CoreException {
57		IProjectDescription description = getProject().getDescription();
58		ICommand[] commands= description.getBuildSpec();
59		ICommand[] newCommands = new ICommand[commands.length-1];
60
61		for (int j=0;j<commands.length;++j) {
62			ICommand command = commands[j];
63			if (command.getBuilderName().equals(FoProcessorPlugin.FOP_RENDERER)) {
64				System.arraycopy(commands, 0, newCommands, 0, j);
65				System.arraycopy(commands, j, newCommands, j, commands.length - j - 1);
66				description.setBuildSpec(newCommands);
67				getProject().setDescription(description, null);
68				return;
69			}
70		}
71
72	}
73
74	public IProject getProject() {
75		return project;
76	}
77
78	public void setProject(IProject project) {
79		this.project=project;
80	}
81
82}
83