Article Index
Commands Tutorial
Selection and Enablement of Commands
Parameters for Commands
Authentication in RCP Application
Misc Items
Misc Items
Toggle & Radio Commands
All Pages

As you would have seen, there are two different ways to contributing to the Workbench: Actions and Commands. Although Commands are newer and advanced, I've always preferred using Actions, simply because of my comfort level in using them. Now that I've started fixing some bugs in the Command framework, I'm forced to look into the details. The more deeper I look into the Commands, the more I'm loving it. So I decided to write a series of on the Commands and this is the first one in the series. Many of the information presented here is obtained by looking some old bugs, wiki and digging into CVS history. If I'm missing anything or wrong about something let me know.

Lets start with Actions. We are able to contribute to the menus, toolbars, pull down menu, etc. We are able to specify the UI details like label or tooltip in the plugin.xml itself, which helps in lazy loading. So whats wrong with them?

 

  • The UI and handling are always tied. There is no way you can separate each other
  • While Actions can be contributed to different parts of the workbench (popup menu/tool bar), all of them were different extension points and so you end up duplicating the XML in multiple places. The worst of it is that not all the extension points expect the same configuration.
  • Specifying Actions in multiple places is a maintenance nightmare. If you have to change the icon of an action, you need to change in all the places.
  • Another issue with duplicating Actions in plugin.xml is that multiple instance of the same Actions will be created in the memory

Lets see how the Commands Framework eliminates all this. Commands are defined by the org.eclipse.ui.commands extension point. A typical command would look like:

<command 
id="com.eclipse-tips.commands.someCommand"
name="Some Command">
</command>

Yeah thats it. That defines a Command! If you want to place this in a tool bar, you have to use the extension point org.eclipse.ui.menus:

<menuContribution 
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="com.eclipse-tips.commands.toolbar1">
<command
commandId="com.eclipse-tips.commands.someCommand"
id="com.eclipse-tips.commands.someCommandInToolBar"/>
 </toolbar>
</menuContribution>

Now that takes of the placement in the UI. But what about the code that gets executed? That goes into a another extension point, org.eclipse.ui.handlers:

<handler
class="com.eclipse_tips.commads.SomeCommandHandler"
    commandId="com.eclipse-tips.commands.someCommand">
</handler>

One last piece is to add an icon to the Command No price for guessing that you need to use another extension point, org.eclipse.ui.commandImages:

<image
commandId="com.eclipse-tips.commands.someCommand"
icon="icons/sample.gif">
</image>

 

All set. Lets see the Command in action:

image

 

 

 

 



More articles :

» e4: First e4 RCP Application

The next big thing in Eclipse is Eclipse 4.0 dubbed as e4. It will be released in 2010. That doesn't mean that the 3.x stream will be deprecated or discontinued. The 3.x releases will go on for "few" years till everyone boards the 4.0. But clearly...

» Selection Dialogs in Eclipse

If you are an Eclipse Plug-in developer, you must have used the MessageDialog. There are many other Dialogs provided by Eclipse Platform are reusable and part of the API. I'll try to explain the various selection dialogs that I know of. In case I've...

» Opening an editor without IFile

When we use Eclipse, we are used to the notion of editors operating on a workspace file. But workspace and resources are optional for an RCP application. You might have to invoke an editor on a non-file object like a database record or an in-memory...

» Reload your plugins without restarting Eclipse

When you are developing Eclipse plugins, sometimes its annoying that the changes in the plugin.xml won't reflect immediately. You need to restart the target Eclipse to see the changes. This will be painful if you are playing with trial-n-error stuff...

» Progress Bars in Eclipse UI

In the "" article, I said the top most mistake is running long running operations in the UI thread. Assuming that you are running it in a non-UI thread, how to show the progress of the execution? Obviously thru progress monitors. But how many...

Subscribe To

Unless stated, all the text contents of this site is available under Eclipse Public License