Demonstration 2 – Adding an action to a
pop-up menu
Introduction
This task explains how to add an action to an existing pop-up menu in the CICS Explorer.
Sample code
The second sample project adds an action to existing pop-up menus in the CICS Explorer. The code is included in the following compressed file. See the Introduction topic for instructions on installing the project in your Eclipse environment. demo2-popup-project-code.zip
Task
1. Create a new plug-in project using the following options:
· Ensure that the check box This plug-in will make contributions to the UI is selected in the Plug-in Content wizard.
· Select the template Plug-in with a popup menu in the Templates wizard
· Use com.ibm.cics.model.IRegion as the interface for the target object class in the Sample Popup Menu wizard, to ensure that the pop-up menu is displayed only when the currently selected object is a CICS region.
When the plug-in is created the plug-in editor opens, however an error is displayed in the Problems view. The reason for this, is that the wizard has created a plug-in that is not aware of the plug-ins contributed by the CICS Explorer SDK. To resolve this problem and to allow our new code to access the CICS Explorer API, you must add a dependency to the plug-in com.ibm.cics.model in the dependencies tab, then save, but do not close, the plug-in.
You must now edit the code for the action invoked by the popup menu:
2. Click the Extensions tab. Expand the org.eclipse.ui.popupMenus tree until New Action (or whatever Action Label you chose) is displayed, then click the label.
3. Click the class* hyperlink to open the Java editor and customize the code for the desired action.
You can save the first element in the selection in the method to an instance variable:
public void selectionChanged(IAction action, ISelection selection)
and then display some information about that object in a dialog in the method
public void run(IAction action)
See the enclose sample project for the details.
To add a variation of the action, add another object contribution, this time on ICICSobject, which is the supertype interface for all CICS objects in the CICS Explorer API
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="com.ibm.cics.model.ICICSObject"
id="com.ibm.cics.explorer.sdk.demo2.contribution2">
<menu
The popup menu contribution for IRegion will be shown only when a CICS region is selected (in the region view), the one for ICICSObject will appear in every CICS Explorer view.