Rational Developer for System z

Filtering actions and property pages by project nature

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.

Sample Scenario

Create a new z/OS® project and MVS™ subproject according to the instructions in the following topics:

To add the sample project nature to the subproject, right-click the subproject and select the API Sample Actions > Add Project Nature action.

Sample Code Walk-through

Subproject Nature Definition

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:

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.

Adding a Project Nature

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>

Removing a Project Nature and Contributing Menu Items Filtered by Project Natures

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>

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)