Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse menus in RCP application for Eclipse 4.2?

I'm using Eclipse 4.2 with compatibility layer to reuse existing part for my RCP application.

I want to reuse New from File menu and Run menu in my RCP application, so for that I opens EMF editor for Eclipse and its look like this:

enter image description here

But for New menu its showing something like this: org.eclipse.e4.model.application....

My application is look-like this (it is just the Java Script debugger with some extra features):

enter image description here

So how I can reuse those menus in my RCP application?

like image 811
Sumit Singh Avatar asked Oct 30 '12 11:10

Sumit Singh


1 Answers

I think I understand what you are saying. You opened the E4 Live Editor on your Eclipse Juno, to get the commands for New and Run menu items so that you can reuse it in your own code?

If I am correct, then in E4 you can no longer use the default commands provided by Eclipse. You need to define your own commands. See here for details.

If you know Eclipse 3.x you are probably searching for the predefined commands which you can re-use. The Eclipse 4 platform tries to be as lean as possible.

Eclipse 4 does not include standard commands anymore. You have to define all your commands.

So if you try to add these commands via the .e4xmi file, then you must define your own commands with its own handlers.

There is a way out if you still wish to use the commands given by Eclipse and that will have to be done via the plugin.xml file. Since you said you are using the compatibility layer, you probably still have a lot of legacy code, and it might be ok to add these menu items via the plugin.xml. Although, once you do a hard migration, I believe Eclipse is trying to reduce the use of extensions in plugin.xml and in that case you will have to define your own commands.

So if you want to add these commands then you must do it via the extensions in the plugin.xml.

To add the New menu item, go to your plugin.xml, in the Extensions tab, add org.eclipse.ui.menus. Create a menucontribution with a locationURI of menu:org.eclipse.ui.main.menu. Then you must add a menu and give it the label File.

This will add the menu File to your RCP. Then to this you must add the New command. In order to do this, you add a command to the File menu you just created. Once you add a command, in commandID you select Browse and look for org.eclipse.ui.file.newQuickMenu.

So your plugin.xml will have the following code.

<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="fileMenu"
               label="File">
            <command
                  commandId="org.eclipse.ui.file.newQuickMenu"
                  style="push">
            </command>....
like image 161
nbz Avatar answered Nov 02 '22 01:11

nbz