Oct 27 2009

Adding menu item, command and handler

Published by at 12:12 am under Eclipse,IT,Java

Step by step in Eclipse IDE

  • Create new Eclipse plug-in: File -> New -> Other -> Plug-in Development -> Plug-in Project
  • Add dependency: MANIFEST.MF -> Dependencies tab -> Add -> org.eclipse.ui
  • Add extension point org.eclipse.ui.menus: plugin.xml -> Extension -> Add -> org.eclipse.ui.menus
    • Right-click -> New -> menuContribution
      • Enter locationURI: menu:file
        • Right click -> New -> command
        • Enter commandId: tk.urbas.eclipse.sample.sampleCommand
        • Enter label: Sample Menu Item
  • Add extension point org.eclipse.ui.commands: plugin.xml -> Extensions -> Add -> org.eclipse.ui.commands
    • Right-click -> New -> command
      • Enter id: tk.urbas.eclipse.sample.sampleCommand
      • Enter label: Sample Command
  • Add extension point org.eclipse.ui.handlers: plugin.xml -> Extensions -> Add -> org.eclipse.ui.handlers
    • Right-click -> New -> handler
      • Enter commandId: tk.urbas.eclipse.sample.sampleCommand
      • Enter class: tk.urbas.eclipse.sample.SampleHandler
      • Click class link and create class
      • Provide sample implementation of the handler class implementing org.eclipse.core.commands.IHandler or extending org.eclipse.core.commands.AbstractHandler

Menu, command, handler

Menu, command, handler


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Sample Handler
Bundle-SymbolicName: tk.urbas.eclipse.sample;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: urbas.tk
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.ui


<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
               label="Sample Menu Item"
            name="Sample Command">

Handler – sample implementation showing a message

package tk.urbas.eclipse.sample;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
public class SampleHandler extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
				"Sample Handler", "Sample Handler");
		return null;

2 responses so far

2 Responses to “Adding menu item, command and handler”

  1. Jacekon 27 Oct 2009 at 8:07 am

    nice, how about moving it to RCP FAQ? http://wiki.eclipse.org/RCP_FAQ

  2. Radoslaw Urbason 28 Oct 2009 at 12:27 am

    Done http://wiki.eclipse.org/RCP_FAQ#How_to_add_menu_item.2C_command_and_handler.3F

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.