Difference between revisions of "Add Menu to RCP Application"

From CDOT Wiki
Jump to: navigation, search
(Add Menu to RCP Application)
(Add Menu to RCP Application)
Line 20: Line 20:
 
* Modify the class so it now looks like this.
 
* Modify the class so it now looks like this.
 
[[Image:rcp-menu-8.png|left|thumb]]<br style="clear:left;" />
 
[[Image:rcp-menu-8.png|left|thumb]]<br style="clear:left;" />
 +
* Ok, we've created a command, so now we need a menu in which to add it.
 +
* Go back to the plugin,xml view and click the Add button. Then select the "org.eclipse.ui.menus" extension and click Finish.
 +
[[Image:rcp-menu-9.png|left|thumb]]<br style="clear:left;" />

Revision as of 09:08, 3 March 2011

Add Menu to RCP Application

In this example I'll be adding a menu to an RCP application checked out from Simple Sample from RCP Course Repository

  • Start Eclipse and check out the example from our course's SVN repository.
  • Run the example and you should get something like this:
Rcp-menu-1.png

  • We'll now create a command (Exit) which we will later add to the menu (File) that we have yet to create.
  • Start by double clicking plugin.xml in the Package window. This will bring the plugin.xml file into the edit window.
  • Now click on the Extensions tab. You should see this:
Rcp-menu-2.png

  • Click the Add button and select "org.eclipse.ui.commands" and click Finish.
Rcp-menu-3.png

  • Right click on the ui.commands extension you just added and select New -> Command.
Rcp-menu-4.png

  • Enter the id, name and defaultHandler as shown. i.e. id is cs.ecl.rcp.simple.book.Exit, name is Exit and defaultHandler is cs.ecl.rcp.simple.book.ExitHandler.
Rcp-menu-5.png

  • Click on the hyperlink "defaultHandler" to create the class which should extend "org.eclipse.core.commands.AbstractHandler". Remove any interfaces. You should have something like this.
Rcp-menu-6.png

  • Click Finish. You should now have this.
Rcp-menu-7.png

  • Modify the class so it now looks like this.
Rcp-menu-8.png

  • Ok, we've created a command, so now we need a menu in which to add it.
  • Go back to the plugin,xml view and click the Add button. Then select the "org.eclipse.ui.menus" extension and click Finish.
Rcp-menu-9.png