Rational Developer for System z, Version 7.6

Contributing an action

You can add an action to the CARMA Repositories view context menu so that the action can be executed on CARMA resources.

Before you can contribute a CARMA action, you must have the proper foundation for extending the Rational Developer for System z CARMA plug-in. Refer to the Eclipse Platform Plug-in Developer Guide for information on how to begin developing a plug-in extension.
To contribute a CARMA action to the Rational Developer for System z CARMA plug-in, follow these steps:
  1. Update your plugin.xml file to utilize the org.eclipse.ui.popupMenus extension point to define an object delegate class for resources that implement either the IResource or CARMAContent interface. Two common resource interfaces you might specify are IFile (which extends the IResource interface) and CARMAContent. Specifying IFile as the resource object class causes your menu item to appear on the context menu in the Navigator view, on local project content, while specifying CARMAContent as the resource object class causes your menu item to appear on the context menu in the CARMA Repositories view.

    Example markup to add a menu item to the Navigator view:

    You could include the following markup in your plugin.xml file if you were to define a menu item to appear for files managed by CARMA in the Navigator view:

    <extension point="org.eclipse.ui.popupMenus">
            <objectContribution
                    id="com.ibm.carma.action.disconnected.iFile"
                    objectClass="org.eclipse.core.resources.IFile"
                    adaptable="true">
                    <filter
                            name="projectPersistentProperty"
                            value="org.eclipse.team.core.repository=com.ibm.carma">
                    </filter>
                    <action
                            label="ABC Action"
                            class="com.xyz.ABCDelegate"
                            id="com.xyz.abc">
                    </action>
            </objectContribution>
    </extension>
    Notice that the objectClass attribute of the objectContribution tag is specified to be org.eclipse.core.resources.IFile, indicating that this menu item should appear on the context menu for the Navigator view. The id attribute of the objectContribution tag is simply a unique identifier for your action. The specified filter tag limits the menu item to appear only for those files in the Navigator view that are managed by CARMA. You can also add additional filter tags if necessary. Finally, the action tag specifies the object delegate class in its class attribute.

    Example markup to add a menu item to the CARMA Repositories view:

    You could include the following markup in your plugin.xml file if you were to define a menu item to appear for resources in the CARMA Repositories view:

    <extension point="org.eclipse.ui.popupMenus">
            <objectContribution
                    id="com.ibm.carma.action.disconnected.carmaContent"
                    objectClass="com.ibm.carma.model.CARMAContent
                    adaptable="true">
                    <filter
                            name="repositoryManager"
                            value="My RAM">
                    </filter>
                    <action
                            label="ABC Action"
                            class="com.xyz.ABCDelegate"
                            id="com.xyz.abc">
                    </action>
            </objectContribution>
    </extension>
    Here, the objectClass attribute of the objectContribution tag is instead specified to be com.ibm.carma.model.CARMAContent, indicating that this menu item should appear on the context menu for the CARMA Repositories view. Notice that a different filter is used in this example: This filter limits the menu item to appear only for resources under a RAM named "My RAM". The name attribute of the filter tag is used to specify the type of filter being applied. Refer to CarmaActionFilter for other relevant values for the name attribute. Finally, the action tag specifies the object delegate class in its class attribute.
  2. Define your object delegate class by either implementing the IObjectActionDelegate interface or extending CarmaObjectActionDelegate (a convenience class that implements the IObjectActionDelegate interface). It is recommended that your object delegate class extend CarmaObjectActionDelegate, since this class contains many useful helper functions.

    Example code for ABCDelegate:

    You can use the following code as a starting point for developing your own object delegate:
    public class ABCDelegate extends CarmaObjectActionDelegate {
    
            public void run(IAction action) {
                    CARMAContent[] members = (CARMAContent[]) getSelectedCarmaResources().toArray(new CARMAContent[0]);
    
                    //perform task, schedule job, etc.
            }
    
            public void selectionChanged(IAction action, ISelection selection) {
                    super.selectionChanged(action, selection);
    
                    //this is the ID assigned by the installation of the action
                    action.setEnabled(!isUnsupported("101"));
            }
    }

    The first line in the run method above obtains an array of the selected CARMA resources, which you can then use to perform your action. You might, for example, loop through all of the selected resources and set certain metadata properties. Although you only really need to override the run method, you may also find it useful to override the selectionChanged method to update the availability of your action as shown in the example above.

    As defined in the example, selectionChanged uses the isUnsupported helper function of CarmaObjectActionDelegate to enable the action with an action ID of 101 if the new selection of objects supports the action. Although a value of 101 is hard-coded into the example code, it is possible to resolve the action ID dynamically if the name of the action is known. Simply use the getActions method of the appropriate RepositoryManager object to retrieve a list of the actions available for that RAM, search through the list to find the appropriate action based on the name the action, and then use the getActionId method to retrieve the action ID from corresponding Action object. You might resolve the ID using this more dynamic method if you are unsure what the action ID of your action is.

Terms of use | Feedback

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