01: package gui;
02:
03: import org.eclipse.core.resources.ICommand;
04: import org.eclipse.core.resources.IProject;
05: import org.eclipse.core.resources.IProjectDescription;
06: import org.eclipse.core.resources.IProjectNature;
07: import org.eclipse.core.runtime.CoreException;
08:
09: public class RefactoringNature implements IProjectNature {
10:
11: /**
12: * ID of this project nature
13: */
14: public static final String NATURE_ID = "org.concept.generator.refactoringNature";
15:
16: private IProject project;
17:
18: /*
19: * (non-Javadoc)
20: *
21: * @see org.eclipse.core.resources.IProjectNature#configure()
22: */
23: public void configure() throws CoreException {
24: IProjectDescription desc = project.getDescription();
25: ICommand[] commands = desc.getBuildSpec();
26:
27: for (int i = 0; i < commands.length; ++i) {
28: if (commands[i].getBuilderName().equals(
29: RefactoringBuilder.BUILDER_ID)) {
30: return;
31: }
32: }
33:
34: ICommand[] newCommands = new ICommand[commands.length + 1];
35: System.arraycopy(commands, 0, newCommands, 0, commands.length);
36: ICommand command = desc.newCommand();
37: command.setBuilderName(RefactoringBuilder.BUILDER_ID);
38: newCommands[newCommands.length - 1] = command;
39: desc.setBuildSpec(newCommands);
40: project.setDescription(desc, null);
41: }
42:
43: /*
44: * (non-Javadoc)
45: *
46: * @see org.eclipse.core.resources.IProjectNature#deconfigure()
47: */
48: public void deconfigure() throws CoreException {
49: IProjectDescription description = getProject().getDescription();
50: ICommand[] commands = description.getBuildSpec();
51: for (int i = 0; i < commands.length; ++i) {
52: if (commands[i].getBuilderName().equals(
53: RefactoringBuilder.BUILDER_ID)) {
54: ICommand[] newCommands = new ICommand[commands.length - 1];
55: System.arraycopy(commands, 0, newCommands, 0, i);
56: System.arraycopy(commands, i + 1, newCommands, i,
57: commands.length - i - 1);
58: description.setBuildSpec(newCommands);
59: return;
60: }
61: }
62: }
63:
64: /*
65: * (non-Javadoc)
66: *
67: * @see org.eclipse.core.resources.IProjectNature#getProject()
68: */
69: public IProject getProject() {
70: return project;
71: }
72:
73: /*
74: * (non-Javadoc)
75: *
76: * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
77: */
78: public void setProject(IProject project) {
79: this.project = project;
80: }
81:
82: }
|