This sample demonstrates how to add a custom project nature to a subproject. The presence or absence of the project nature can then be used to control the visibility of menu items.
To add the sample project nature to the subproject, right-click the subproject and select the API Sample Actions > Add Project Nature action.
Subproject natures in Rational® Developer for System z® are similar in concept to IProjectNature in base Eclipse. They provide a means to distinguish between remote subprojects based on the functionality that is to be enabled for each subproject.
To define a custom project nature for a remote subproject, you need to create a class that implements the ILogicalSubProjectNature interface. Thus the SampleNature class contains the following code:
public class SampleNature implements ILogicalSubProjectNature {
......
}
The ILogicalSubProjectNature interface is relatively simple. In SampleNature you simply add a private field project for the project property.
The complete source code can be found in SampleNature.java.
To complete the definition of the project nature, declare the SampleNature class in the plugin manifest as follows:
<extension
id=“samplenature”
name=“
point=“com.ibm.ftt.projects.core.natures”>
<nature class=“com.ibm.ftt.api.samples.natures.SampleNature”/>
</extension>
This snippet defines a project nature with the ID com.ibm.ftt.api.samples.samplenature, which is obtained by appending the extension ID samplenature to the ID of the defining plugin com.ibm.ftt.api.samples.
The Add Project Nature menu item is implemented by the AddSubProjectNatureAction class. Its run(IAction) method adds the SampleNature by passing the ID of the nature to the addNatureId(String) method of ILogicalSubProject.
try {
getSubProject().addNatureId("com.ibm.ftt.api.samples.samplenature");
} catch (CoreException e) {
// TODO: in production code exception should be handled for real
e.printStackTrace();
}
The complete source code can be found in AddSubProjectNatureAction.java.
The action is contributed using standard Eclipse contribution mechanisms.
<objectContribution
adaptable=“false”
objectClass=“com.ibm.ftt.projects.core.logical.ILogicalSubProject”
id=“com.ibm.ftt.api.samples.addnature”>
<action
label=“
class=“com.ibm.ftt.api.samples.natures.AddSubProjectNatureAction”
id=“com.ibm.ftt.api.samples.addnatureaction”/>
</objectContribution>
The Remove Project Nature menu item is implemented by the RemoveSubProjectNatureAction class. Its run(IAction) method removes the SampleNature by passing the ID of the nature to the removeNatureId(String) method of ILogicalSubProject.
try {
getSubProject().removeNatureId(“com.ibm.ftt.api.samples.samplenature”);
} catch (CoreException e) {
// TODO: in production code exception should be handled for real
e.printStackTrace();
}
The complete source code can be found at RemoveSubProjectAction.java.
The action is contributed using standard Eclipse contribution mechanisms, similar to the Add Project Nature menu item, with the additional use of action filters. This causes the Remove Project Nature action to appear only if the SampleNature has been added to the project in question.
<objectContribution
adaptable=“false”
objectClass=“com.ibm.ftt.projects.core.logical.ILogicalSubProject”
id=“com.ibm.ftt.api.samples.removenature”>
<filter
value=“com.ibm.ftt.api.samples.samplenature”
name=“projectNature”/>
<action
label=“
class=“com.ibm.ftt.api.samples.natures.RemoveSubProjectNatureAction”
id=“com.ibm.ftt.api.samples.removenatureaction”/>
</objectContribution>