IProjectDescription projectDescription = project.getDescription();
description is a description of the project . It gives a lot of information including the entire list of
nature ids and build commands.
String[] ids = projectDescription.getNatureIds();
String[] newIds = new String[ids.length + 1];
System.arraycopy(ids,0,newIds,0,ids.length);
newIds[ids.length] = YOUR_NATURE_ID;
projectDescription.setNatureIds(newIds);
project.setDescription(projectDescription,null);
the remove nature id code is kind of similar .
To actually implement your nature , you need to contribute to the extension point
org.eclipse.core.resources.natures
Basically that boils down to adding something like this in your plugin.xml
name="Your Nature Name">
"id" here represents the id of the nature .
"name" represents the name of the nature .
"class" represents the class implements the IProjectNature .
the requires-nature here represents the nature id that is required for this nature to be successfully installed .
Next , finally the class that implements the IProjectNature interface.
public class YourProjectNature implements IProjectNature {
IProject project;
public YourProjectTestNature() {
}
public IProject getProject() {
return project;
}
public void setProject(IProject project) {
this.project= project;
}
}