capint
11/21/2016 - 4:47 PM

Eclipse >> Project nature

Eclipse >> Project nature

<extension
    point="org.eclipse.core.expressions.definitions">
    <definition
        id="com.example.project.hasNature">
        <adapt
            type="org.eclipse.core.resources.IProject">
            <test
                property="org.eclipse.core.resources.projectNature"
                value="com.example.project.examplenature">
            </test>
        </adapt>
    </definition>
</extension>

<!-- This can be referenced by a condition (e.g. visibleWhen)-->
IProject project = // get project...
IProjectDescription description = project.getDescription();

String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = ExampleProjectNature.NATURE_ID;

// validate the natures
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = workspace.validateNatureSet(newNatures);

// only apply new nature, if the status is ok
if (status.getCode() == IStatus.OK) {
        description.setNatureIds(newNatures);
        project.setDescription(description, null);
}
//*** Source: http://www.vogella.com/tutorials/EclipseProjectNatures/article.html#project-natures-in-eclipse
<extension
  id="examplenature"
  name="Example nature"
  point="org.eclipse.core.resources.natures">
  <runtime>
    <run
      class="com.example.product.ExampleProductNature">
    </run>
  </runtime>
</extension>

public class ExampleProjectNature implements IProjectNature {
   // ID of the natures, which consists of Bundle-SymbolicName + ID
   public static final String NATURE_ID = "com.example.project.examplenature";
  ...
}