Eclipse RCP 4 Tutorial for Beginners - E4 Workbench Application

1- Introduction

This document is based on:
  • Eclipse 4.5 (MARS)

  • Eclipse e4 RCP  (RCP 4)

Document History:
  • 27-08-2014: Based on Eclipse 4.4 LUNA + RCP 3.x
  • 10-07-2015: Update to Eclipse 4.5 MARS + Eclipse E4 RCP.


You can see Eclipse RCP 3.x tutorial at:

2- The installation requires

2.1- Installing WindowBuilder

Install WindowBuilder plugin, there is a plugin that allows you to design SWT GUI applications using drag and drop convenience.
See installation instructions at:

2.2- Installing e4 Tools Developer Sources

You can see installation instructions at:

3- Create new Java Workspace

To programme RCP application you should create a new Java Workspace:
  • File/Switch Workspace/Other..

4- Create RCP Project

In this document, I will guide you to build an RCP application from the beginning (Do not follow the available template), so I'll create a blank Eclipse RCP application.
In Eclipse select:
  • File/New/Other...
  1. Check selected on (1)
  2. On the (2) select "Yes" to create Eclipse RCP Project (Running on Desktop), otherwise it will create RAP Project (Running on the Web).
Select "Eclipse 4 RCP Application"
  • Java package name: org.o7planning.tutorial.rcp
Project was created:

Run application:

Right click EclipseRCPTutorial.product and select Run As/Eclipse Application

5- Structure of Empty Eclipse 4 RCP application

Empty  Eclipse 4 RCP applications was created by Eclipse, see its structure. Open  Application.e4xmi file:
Change the title of the application into "Eclipse E4 RCP Application" as shown below.
And rerun application:

6- Handler and Command

RCP Framework built a lot of Command, for example 4 commands with the following ID:
  1. org.eclipse.ui.file.exit
    • Close the workbench
    • Open file
    • Save the active editor.
    • Displays the About dialog.

You can see a list of built-in command of the RCP framework at:

Create a Command named  quiteCommand , called to exit the application command which was built by RCP Framework.
Similarly we create 3 other Commands:
Open selected file.
  • ID:
  • Name: openCommand
Save the active editor (or part).
  • ID:
  • Name: saveCommand
  • ID:
  • Name: aboutCommand
Handler is the classes handling for the commands of Menu or Toolbar. When you click on MenuItem or ToolItem, it means that the call to execute a command,Handler will be executed before the Command is executed, you can cancel (cancel) the command is executed in Handler.

Handler is the classes that when executed, it will execute the task is written in method annotated by @Execute.

I will create 4  Handler classes:
package org.o7planning.tutorial.rcp.handler;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;

public class AboutHandler {
   public void execute(Shell shell) {
       MessageDialog.openInformation(shell, "About", "Eclipse 4 RCP Application");
package org.o7planning.tutorial.rcp.handler;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

public class OpenHandler {

   public void execute(Shell shell){
       FileDialog dialog = new FileDialog(shell);;
package org.o7planning.tutorial.rcp.handler;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;

public class QuitHandler {
   public void execute(IWorkbench workbench, Shell shell){
       if (MessageDialog.openConfirm(shell, "Confirmation",
               "Do you want to exit?")) {
package org.o7planning.tutorial.rcp.handler;

import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.workbench.modeling.EPartService;

public class SaveHandler {

   public boolean canExecute(EPartService partService) {
       if (partService != null) {
           return !partService.getDirtyParts().isEmpty();
       return false;

   public void execute(EPartService partService) {

Declaring  Handler classes with applications.

Declaring a Handler with Application, you must declare the ID, Handler class and Command.

For example, the user closes the application by clicking the menuItem Exit, the MenuItem associated with quiteCommand, QuiteHandler is class handling for this command (as declared above), class QuiteHandler will ask users really want to close the application or not,  if yes, q uiteCommand Command will be executed.
Similarly declare other Handler.

7- Create Menus

Create Main Menu:
Enter the ID of Main Menu, It must be named:
Create 3 submenus:
  • File, Function, Help
Create submenus of File menu.
  • Open
  • Save
  • Exit
Rerun your application:

8- Create Toolbar

Create Main Toolbar, with ID:
  • ID: toolbar:org.eclipse.ui.main.toolbar
Add 2 Toolitem: open & save
Rerun your application:

9- Part
 * Copyright (c) 2010 - 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Lars Vogel <> - Bug 419770
package org.o7planning.tutorial.rcp.part;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

public class SamplePart {

    private Text txtInput;
    private TableViewer tableViewer;

    private MDirtyable dirty;

    public void createComposite(Composite parent) {
        parent.setLayout(new GridLayout(1, false));

        txtInput = new Text(parent, SWT.BORDER);
        txtInput.setMessage("Enter text to mark part as dirty");
        txtInput.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
        txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        tableViewer = new TableViewer(parent);

        tableViewer.add("Sample item 1");
        tableViewer.add("Sample item 2");
        tableViewer.add("Sample item 3");
        tableViewer.add("Sample item 4");
        tableViewer.add("Sample item 5");
        tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));

    public void setFocus() {

    public void save() {
Add new PerspectiveStack. This is a stack, it can contain the perspective.
Add new Perspective:
Rerun Application:
The change in the Part, may do SAVE button lights up.