Eclipse New Menu Item

On this page we create a menu UI extension point, it assumes you have already created a new Plug-in Project (If you have not allready done this you can go back to this page for a guide to doing this).

Creating a Menu UI Extension Point.

In MANIFEST-MF Extensions click on Add.

and add org.eclipse.ui.commands

menu2

Click on the "Hello, World" template.

enter the:

  • Pacage Name
  • Class Name
  • Message text

and click on finish,

menu3

This creates various extensions to the UI

menu4

When we run the project in a new instance of Eclipse we can see a 'Sample Menu' entry in the menu and an ICON which has the same action.

menu5

plugin.xml file

Here is the plugin.xml file produced

So what has the above done to the project code?

Running the code from the extensions page, as described above, creates entries in the plugin.xmi which create extensions to the Eclipse UI.

 

<?xml version="1.0" encoding="UTF-8"?>
          <?eclipse version="3.4"?>
          <plugin> 
  <extension
          point="org.eclipse.ui.commands">
  <category
          id="com.euclideanspace.modelText.commands.category"
          name="Sample Category">
  </category>
  <command
          categoryId="com.euclideanspace.modelText.commands.category"
          id="com.euclideanspace.modelText.commands.sampleCommand"
          name="Sample Command">
  </command>
  </extension>
  <extension
          point="org.eclipse.ui.handlers">
  <handler
          class="com.euclideanspace.modeltext.handlers.SampleHandler"
          commandId="com.euclideanspace.modelText.commands.sampleCommand">
  </handler>
  </extension>
  <extension
          point="org.eclipse.ui.bindings">
  <key
          commandId="com.euclideanspace.modelText.commands.sampleCommand"
          contextId="org.eclipse.ui.contexts.window"
          schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
          sequence="M1+6">
  </key>
  </extension>
  <extension
          point="org.eclipse.ui.menus">
  <menuContribution
          locationURI="menu:org.eclipse.ui.main.menu?after=additions">
  <menu
          id="com.euclideanspace.modelText.menus.sampleMenu"
          label="Sample Menu"
          mnemonic="M">
  <command
          commandId="com.euclideanspace.modelText.commands.sampleCommand"
          id="com.euclideanspace.modelText.menus.sampleCommand"
          mnemonic="S">
  </command>
  </menu>
  </menuContribution>
  <menuContribution
          locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
  <toolbar
          id="com.euclideanspace.modelText.toolbars.sampleToolbar">
  <command
          commandId="com.euclideanspace.modelText.commands.sampleCommand"
          icon="icons/sample.gif"
          id="com.euclideanspace.modelText.toolbars.sampleCommand"
          tooltip="Say hello world">
  </command>
  </toolbar>
  </menuContribution>
  </extension>
        </plugin>

Here is the plugin.xml file produced by the 'hello, world' template in File->New->plug-in

NOTE: actionSets are depreciated

So what has the above done to the project code?

Running the code from the extensions page, as described above, creates entries in the plugin.xmi which create extensions to the Eclipse UI.

 

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
       <extension
          point="org.eclipse.ui.actionSets">
        <actionSet
            label="Sample Action Set"
            visible="true"
            id="com.euclideanspace.modelText2.actionSet">
           <menu
             label="Sample &amp;Menu"
             id="sampleMenu">
            <separator
name="sampleGroup"> </separator> </menu> <action label="&amp;Sample Action" icon="icons/sample.gif" class="com.euclideanspace.modeltext2.actions.SampleAction" tooltip="Hello, Eclipse world" menubarPath="sampleMenu/sampleGroup" toolbarPath="sampleGroup" id="com.euclideanspace.modeltext2.actions.SampleAction"> </action> </actionSet> </extension> </plugin>

 


metadata block
see also:
Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2022 Martin John Baker - All rights reserved - privacy policy.