Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Vasanthi Sathyanarayanan
Senior Software Developer at Genuitec
Posted on Jan 28th 2016

Introduction to Command Handlers in Eclipse

A command is the declaration of a behavior by id.  Commands are used to declare semantic behavior and the corresponding action implementations can be defined elsewhere by handlers.

There are several advantages of command handlers:

  • Defining menu contribution and commands uses same set of extensions points for multiple scenarios.
  • UI and handling are not tied, like in Actions framework.
  • Multiple handler declarations for the same command with activeWhen and enableWhen conditions defined.

Complete the following steps to contribute a menu and define its action through command-handlers:

  1. Define the menu contribution—find the right locationURI
  2. Define the command id—required label, icon, tooltip
  3. Define the command extension—with/without default handler
  4. Define the handler extension—if default handler was not defined

A simple example of menu contributions


Sample Menu Contributions

Use the following table to view sample menu contributions.  Refer to the image that follows the table to view where the menu contributions appear in the RCP application; the corresponding example number is listed in the table.

Note: The required command and handler extension code is given after the table and images. 


main toolbar action


Main toolbar – Ex2


NOTE: A toolbar element needs to be created for adding a main toolbar item.


view context menu action


View context/popup menu – Ex6




view toolbar action


View toolbar – Ex3




main menu action

Main menu item with submenus – Ex4 & 5



main menu action direct menu

Direct Main menu item – Ex1



View Sample Menu Contributions

Examples of menu contributions


Defining Command and Handler Extension Points

In the examples below, the rcp.demo.actions.searchcommand command is defined a defaultHandler, whereas the rcp.demo.actions.runcommand command defines its handler using the org.eclipse.ui.handlers extension. Using the second method, we can define multiple handlers for the same command based on condition and also have more control when the handler has to be active based on the conditions defined.

Note: Additional details can be found at and

Handler class

Let Us Hear from You!

If you have any comments or questions, we would love to hear from you @MyEclipseIDE on twitter or via the MyEclipse forum