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.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.