Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Vasanthi Sathyanarayanan
Senior Software Developer at Genuitec

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

Related Posts

CodeMix – Better with You! Thanks to detailed feedback from our awesome users, our team has been hard at work adding stability, reliability and performance fixes, and enhancements, to CodeMix. Read on for the deets on what’s new in CodeMix over the last month.Editing & ValidationWhen editing TypeScript files, error markers were sometimes not cleared when the error was fi...
A Day with Dani: Eclipse Plugin for Awesome Worksp... DevStyle Rescued My Workspace!As a new developer working in Eclipse, nothing was worse than doing a project and looking at an outdated, plain workspace. It was boring, and took away from the excitement and learning these projects had to offer. This was an IDE I would be using almost every day, so when I learned about the DevStyle plugin for Eclipse...
Happy Holidays – from Our Family to Yours! It’s that time of the year again - the time to enjoy a break from the everyday duties, accompanied by our loved ones! At Genuitec we would like to wish you a wonderful holiday season filled with great times and awesome food! We already got our party hats out (as you can see)! Our U.S. offices will be closed on December 25th and 26th, as well as Jan...
30% off sale, including Angular IDE and more! Step away from the leftovers and come take advantage of our Cyber Monday sale for Angular IDE, Webclipse, MyEclipse and more!   Thanksgiving is a great time for getting together with family, but perhaps more importantly, it’s about the SALES!  Whether it’s Buen Fin or Cyber Monday, we all love a bargain. Now is the time to get the software you alwa...

Posted on Jan 28th 2016