Tag Archives: eclipse rcp

Introduction to Eclipse Command

Command in Eclipse represents task. Anything can be a task. In the example in the picture above, I used ‘delete’ as example. A command can have several handlers, which are active on different conditions. In the previous example, I used three handlers which active depend on the type of the object.

Commands can be triggered from one or more place(s). We can define a menu that call a command or define a context menu for that. We can also bind a keyboard shortcut to call a command and we can as well programmatically call a command from our code. And that’s just some examples.

Command, architecturally, is representation of controller. Using command should made it easy for developer to get a big picture of what an application does. Just list all the command and that should be it.

You can find more about command in these links.

What is Eclipse-RCP-based Application?

To get the answer of that question, we need to take a look at the global architecture of an Eclipse-RCP-based application. This picture below can summarize the information.

SWT is Standard Widget Toolkit for Java. Developed by IBM and later by Eclipse Foundation, the purpose of SWT is to give native performance and look to Java application. SWT is implemented using JNI and so is not write-once-run-anywhere-library (WORA). This mean that each OS need specific SWT distribution.

JFaces is a layer above SWT which provides more convenience classes for generic application. JFaces is a WORA library.

OSGi is a standard developed by consortium with the same name to provide Java environment that is more dynamic. The goal is extensible, loosely-coupled applications with modules behind it.

Equinox is Eclipse implementation of OSGi.

Eclipse Core and Eclipse UI are classes that form the platform of Eclipse. All Eclipse-RCP-based applications will use this classes. Among other things, it provides extension framework, command framework (and somewhat-deprecated Action framework), and basic application-window management.

Eclipse RCP: Creating dynamic menu

Have you ever want to create a dynamic menu to your RCP application? Do you want to compute the contents of the menu on-the-fly at runtime? This is possible and many hacks can be done to do that.

But to do the correct thing is probably what annoyed your head every day. And actually, this has been supported by the framework.

First, what you need to do is creating a menu holder for your dynamic menu. This can be done by adding a new element named ‘dynamic’ under a menu contribution.


Now you need to implement a class that extends CompoundContributionItem.


Let’s make the menu like this;

public class ContributionItem1 extends CompoundContributionItem {

    protected IContributionItem[] getContributionItems() {
        List<IContributionItem> menuContributionList = new ArrayList<IContributionItem>();

        menuContributionList.add(new CommandContributionItem(new CommandContributionItemParameter(Activator
                .getDefault().getWorkbench(), null, ActionFactory.QUIT.getCommandId(),

        return menuContributionList.toArray(new IContributionItem[menuContributionList.size()]);


This is of course not a real example. In the reality, you will want to create a dynamic menu based on the condition. If the condition is changed, the menu will be automatically changed. I hope by using this small and unreal example, you will just get the idea.

Let’s try to run the application.