Main components of an Eclipse RCP application

The minimal required plug-ins to create and run an minimal Eclipse RCP application (with UI) are the two plugins “org.eclipse.core.runtime” and “org.eclipse.ui”.

Based on these components an Eclipse RCP application must define the following elements:

  1. Main program - A RCP main application class implements the interface IApplication. This class can be viewed as the equivalent to the main method for standard Java application. Eclipse expects that the application class is defined via the extension point org.eclipse.core.runtime.application.

  2. A Perspective - defines the layout of your application. Must be declared via the extension point "org.eclipse.ui.perspective".

  3. Workbench Advisor - invisible technical component which controls the appearance of the application (menus, toolbars, perspectives, etc)

Application

This class is typically called Application and must implement the interface IApplication.

Display display = PlatformUI.createDisplay();
PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());

WorkbenchAdvisor

PlatformUI.createAndRunWorkbench() creates and runs a Workbench. The Workbench represents the graphical user interface of Eclipse. The visual part of the Workbench is represented via the WorkbenchWindow class. A Workbench can have several WorkbenchWindows opened. The inner part of the WorkbenchWindow is represented via the class WorkbenchPage.

The Workbench is configured via a class of type WorkbenchAdvisor. This class defines the initial Perspective and defines the WorkbenchWindowAdvisor class.

WorkbenchWindowAdvisor

WorkbenchWindowAdvisor calls the class ActionBarAdvisor which configures Actions for the Workbench and defines initial attribute for the WorkbenchWindow as initial size, title and visibility of the statusline.

public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
    return new ApplicationActionBarAdvisor(configurer);
}

public void preWindowOpen() {
    IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
    configurer.setInitialSize(new Point(400, 300));
    configurer.setShowCoolBar(false);
    configurer.setShowStatusLine(false);
    configurer.setTitle("Todo"); //$NON-NLS-1$
}

WorkbenchPage

The WorkbenchPage contains Parts, which can be Views or Editors.

Views are used to display information in an RCP application; they can also be used to change data. Views extend the abstract class ViewPart. Editors extend the abstract EditorPart. Both extend WorkbenchPart.

An editor typically requires that the user explicitly select “save” to apply the changes to the data while a view typically changes the data immediately.

All editors are opened in the same area. Via the perspective you can configure if the editor area is visible or not.

Views and Editors are defined via extension points in the file plugin.xml via the tab “Extensions”.

Views are defined via the extension point "org.eclipse.ui.views" and Editors via the extension point "org.eclipse.ui.editors".

Views must implement the createPartControl() and setFocus() methods:

Note that RCP 4.x is not extends from ViewPart and EditorPart, composite() is annotated with @PostConstruct

Perspective

A Perspective is defined via "org.eclipse.ui.perspectives". The WorkbenchParts which are part of a Perspective are either defined via a Java class defined in the extension point the "org.eclipse.ui.perspectiveExtensions".

layout.addView() adds a view to the perspective. or directly on perspectiveExtensions

public class Perspective implements IPerspectiveFactory {
    public void createInitialLayout(IPageLayout layout) {
        layout.addView("de.vogella.rcp.intro.first.MyView", IPageLayout.TOP,
                IPageLayout.RATIO_MAX, IPageLayout.ID_EDITOR_AREA);
    }
}

You can also add placeholders for views via the layout.addPlaceholder() method call. This methods accepts wildcards and a View with a matching ID would open in this area.

For example if you want to open all views in a specific place you could use the layout.addPlaceholder("*", ) method call, or

layout.addPlaceholder("view_id",…​.) to open a View with the “view_id” ID in this placeholder.

You can also group view via a IFolderLayout which can be created via layout.createFolder() call and by adding Views to this folder via the addView(id) method on IFolderLayout.

Above all can be replace in RCP 4.x with application model .e4xmi