Adding to an existing menu: Difference between revisions

(Created page with 'We use the Eclipse Command Framework. This document describes how you can add a menu item "Open Website" to one of the ProB submenus (in this case Contact). 1. Create an exten…')
 
No edit summary
Line 40: Line 40:
             </parameter>
             </parameter>
         </command>
         </command>
This will show a menu item in the contact submenu and it will pass the parameter into the command.
        </menuContribution>
</extension>
This will show a menu item in the contact submenu and it will pass the parameter into the command. We can instantiate the same command with a different URL and add it to the same menu
<extension
        point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:contact">
      <command
              commandId="de.prob.ui.openWebsite"
              label="Open Google"
              mnemonic="G"
              style="push">
            <parameter
                  name="de.prob.ui.openwebsite.url"
                  value="http://www.google.com">
            </parameter>
        </command>
        </menuContribution>
</extension>

Revision as of 16:21, 14 April 2010

We use the Eclipse Command Framework. This document describes how you can add a menu item "Open Website" to one of the ProB submenus (in this case Contact).


1. Create an extension to org.eclipse.ui.commands and add a new command.
You will end up with something like

<extension point="org.eclipse.ui.commands">
    <command
           categoryId="de.prob.ui.commands.category"
           id="de.prob.ui.openWebsite"
           name="Open Website">
        <commandParameter
              id="de.prob.ui.openwebsite.url"
              name="URL"
              optional="false">
        </commandParameter>
     </command>
</extension>

The example also shows that commands can have parameters. In this case we want to provide different URLs. Section 3 will explain how the command is parameterized.

2. Create an extension to org.eclipse.ui.handlers and add a handler. The handler will link the command with its implementation, i.e., if the command is triggered the execute method of the handler is being called.

<extension point="org.eclipse.ui.handlers">
     <handler
           class="myplugin.mycontributionCommand"
           commandId="myplugin.mycontribution">
     </handler>
</extension>

3. Now we add an instance of the command to the menu bar

 <extension
        point="org.eclipse.ui.menus">
     <menuContribution
           locationURI="menu:contact">
        <command
              commandId="de.prob.ui.openWebsite"
              label="Open ProB Website"
              mnemonic="W"
              style="push">
           <parameter
                 name="de.prob.ui.openwebsite.url"
                 value="http://www.stups.uni-duesseldorf.de/ProB">
           </parameter>
        </command>
       </menuContribution>
</extension>

This will show a menu item in the contact submenu and it will pass the parameter into the command. We can instantiate the same command with a different URL and add it to the same menu

<extension
        point="org.eclipse.ui.menus">
     <menuContribution
           locationURI="menu:contact">
     <command
              commandId="de.prob.ui.openWebsite"
              label="Open Google"
              mnemonic="G"
              style="push">
           <parameter
                 name="de.prob.ui.openwebsite.url"
                 value="http://www.google.com">
           </parameter>
        </command>
       </menuContribution>
</extension>