Extending the transformation view's menu
The following code sample shows how to extend your transformation view's menu. In the sample, a disconnect menu item is added which, when clicked, causes the host connection to be disconnected and the disconnect and stop events of the application to be run. You should only add actions to the view's menu that are applicable during the entire lifecycle of the view.
Follow these steps to extend the menu of your transformation
view class (the Java™ source
file for this class is located in the <project name>.views package
of your project):
- Since your action needs to be accessed in at least two methods
of your transformation view class, declare it as a private member
of your transformation view class.
private com.ibm.hats.rcp.ui.actions.DisconnectAction disconnectAction;
- Override the createViewActions() method of the transformation
view class, ensuring that you call super.createViewActions() if you
want the default actions provided by ZIETrans to be available on the view's
menu).
protected void createViewActions() { super.createViewActions(); //create an action and append the action to the view's menu. disconnectAction = new DisconnectAction("Disconnect",getSessionService()); getViewSite().getActionBars().getMenuManager().add(new Separator()); getViewSite().getActionBars().getMenuManager().add(disconnectAction); }
- Override the updateViewActions() method to cause your
new action to be enabled or disabled when the menu is updated.
protected void updateViewActions() { super.updateViewActions(); //enable the action based on the session state. disconnectAction.setEnabled(getSessionService().getSessionServiceState(). isOperational()); }
After adding the Disconnect action, when you click the menu button in the transformation view, you can see Disconnect on the menu:
Figure 1. Disconnect on the transformation view menu