KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > $packageName$ > $natureClassName$


1 package $packageName$;
2
3 import org.eclipse.core.resources.ICommand;
4 import org.eclipse.core.resources.IProject;
5 import org.eclipse.core.resources.IProjectDescription;
6 import org.eclipse.core.resources.IProjectNature;
7 import org.eclipse.core.runtime.CoreException;
8
9 public class $natureClassName$ implements IProjectNature {
10
11     /**
12      * ID of this project nature
13      */

14     public static final String JavaDoc NATURE_ID = "$pluginId$.$natureId$";
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($builderClassName$.BUILDER_ID)) {
29                 return;
30             }
31         }
32
33         ICommand[] newCommands = new ICommand[commands.length + 1];
34         System.arraycopy(commands, 0, newCommands, 0, commands.length);
35         ICommand command = desc.newCommand();
36         command.setBuilderName($builderClassName$.BUILDER_ID);
37         newCommands[newCommands.length - 1] = command;
38         desc.setBuildSpec(newCommands);
39         project.setDescription(desc, null);
40     }
41
42     /*
43      * (non-Javadoc)
44      *
45      * @see org.eclipse.core.resources.IProjectNature#deconfigure()
46      */

47     public void deconfigure() throws CoreException {
48         IProjectDescription description = getProject().getDescription();
49         ICommand[] commands = description.getBuildSpec();
50         for (int i = 0; i < commands.length; ++i) {
51             if (commands[i].getBuilderName().equals($builderClassName$.BUILDER_ID)) {
52                 ICommand[] newCommands = new ICommand[commands.length - 1];
53                 System.arraycopy(commands, 0, newCommands, 0, i);
54                 System.arraycopy(commands, i + 1, newCommands, i,
55                         commands.length - i - 1);
56                 description.setBuildSpec(newCommands);
57                 return;
58             }
59         }
60     }
61
62     /*
63      * (non-Javadoc)
64      *
65      * @see org.eclipse.core.resources.IProjectNature#getProject()
66      */

67     public IProject getProject() {
68         return project;
69     }
70
71     /*
72      * (non-Javadoc)
73      *
74      * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
75      */

76     public void setProject(IProject project) {
77         this.project = project;
78     }
79
80 }
81
Popular Tags