Java - Eclipse-RCP

expansion of eclipse-menu/of toolbar under use of commands (from Eclipse 3.3)

The creation of menues and toolbars is almost identical and therefore, it will be explained together.



with one handler per menu item

In the example, a script with the menu item Tahoma 10 shall be created above a menu:

  1. open fragment.xml or plugin.xml and choose Register Extensions.
  2. if not available yet, add extension-point org.eclipse.ui.menus with <Add>.
  3. click with the right mouse button on the extension-point and choose New/menuContribution.
  4. As locationURI enter for menus menu:org.eclipse.ui.main.menu?after=additions or rather for toolbar menu:org.eclipse.ui.main.toolbar?after=additions.
  5. click on menu:org.eclipse.ui.main.menu?after=additions with the right mouse button and choose New/menu or rather New/toolbar.
  6. enter the term of the menu (font) on the right in the array label.
  7. now, click on the new menu on the left with the right mouse button and choose New/command.
  8. on the right, fill in the commandId (e.g. com.sowas.demo.tahoma10) and the label (Tahoma 10).
  9. if not available yet, add the extension-point org.eclipse.ui.commands with <Add>.
  10. with the right mouse button click on the extension-point and choose New/command.
  11. on the right in the array commandId enter the already under point 8 used commandId (com.sowas.demo.tahoma10).
  12. enter menu item name for name
  13. now, click on Defaulthandler and create a new handler. The handler is a method, which is called up when the user clicks on the menu item. The method has to implement the Interface IHandler.

with one handler for several menu items

In the example, to the created menu script at the top the submenu font with the menu items Tahoma and Verdana shall be added:

  1. carry out the steps 1 - 6 from above.
  2. click on the menu script on the left with the right mouse button and choose New/menu.
  3. on the right in the array label, enter the term of the submenu (here: font).
  4. now, click on the new submenu on the left with the right mouse button and choose New/command.
  5. enter a CommandId on the right (e.g.: com.sowas.demo.changefont).
  6. enter on the right as label the menu item (Tahoma).
  7. now, click on the new submenu on the left with the right mouse button again and choose New/command.
  8. enter the CommandId on the right again (e.g.: com.sowas.demo.changefont).
  9. and also enter on the right as label the menu item (Verdana).
  10. now, click on the extension org.eclipse.ui.commands on the left with the right mouse button.
  11. fill in the commandId (com.sowas.demo.changefont) and name (ChangeFont) on the right.
  12. now, click on defaulthandler and create a handler (e.g.: com.sowas.demo.ChangeFontHandler). The handler is the method which is called up when the user clicks on the menu item. The method must implement the Interface IHandler.
  13. on the left, click on ChangeFont with the right mouse button and choose New/commandParameter
  14. enter com.sowas.demo.schriftart as id on the right.
  15. enter font as name.
  16. in case of several parameters set optional on true.

general advice

Is a menu item not displayed, the reason is as a general rule, that the handler isn't found.


Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007