FAQ How do I add actions to a view's menu and toolbar?
Each view has a drop-down menu in two locations:
- under the icon on the views tab item.
This menu contains layout and view-manipulation actions. You dont have any control over this menu; its actions are all added by the platform.
- in the views toolbar.
The drop-down menu on the right-hand side, a small downward-pointing triangle, is controlled by your view. This menu will exist only if you add actions to it.
Actions are added to the menu and toolbar by using the IActionBars interface. This interface is used to access the standard JFace menu and toolbar manager objects used for creating menus throughout Eclipse. The following code, usually invoked from the views createPartControl method, adds a single action to the views menu and toolbar:
Action action = ...; IActionBars actionBars = getViewSite().getActionBars(); IMenuManager dropDownMenu = actionBars.getMenuManager(); IToolBarManager toolBar = actionBars.getToolBarManager(); dropDownMenu.add(action); toolBar.add(action);
This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.