Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Profile photo of vasanthis
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

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...
Equifax Data Breach Advisory Many of you may have heard of the Equifax data breach, possibly affecting millions of consumers. Information accessed by hackers during the incident included Social Security numbers, personal details, driver’s license numbers, and even credit card numbers.Equifax has confirmed that the breach was made possible by a vulnerability in the Apache Strut...
Realtime Server Monitoring App with Angular 4 , No... This article will show you how to build a very simple monitor that allows you to observe some OS parameters, such as free memory available. We will be using Node.js, Angular 4, and Chart.js - and all you need is Angular IDE.We will be creating two applications; the first is a Node application that will monitor the OS parameters and send them via we...
Beware of Software Scams Even though imitation might be the best form of flattery, we are Genuitec, LLC, not Genuitec, Inc. Someone is using our name and old logo to run a number of scams, including real estate transactions and software sales, with the clear intent to hide behind Genuitec’s good name. We are, however, already taking action to demand an immediate cease and ...

Posted on Jan 28th 2016