Over a million developers have joined DZone.

e4: First e4 RCP Application

DZone's Guide to

e4: First e4 RCP Application

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

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 the future of Eclipse is e4 and its already here. I'll be writing a series of blog posts on e4 and this will be the first. You can follow this blog in RSS, or email or even in twitter. I'm still learning about e4, so feel free to correct me if you find any mistakes :-)

First set up your e4 Environment:

1) Download e4 1.0 M1
2) Click e4->Generate e4 Example Project

3) Right click e4-examples.psf and click 'Import Project Set'. This should import the contacts and the photo projects from the CVS to your workspace
4) Open the contacts.product file and click the "Launch an Eclipse Application" link in the Overview page
5) Thats it. You should be running the Contacts demo.

You can play around with the css theme or code and check out the effects. When you are done, lets start an app from the scratch. The first app will have nothing more than a view (something like the 'RCP Application with a View', created by PDE Wizard). Note: If you find it hard to work with e4, you can grab a latest 3.6 build and set the e4 as the target platform and proceed with the following steps)

Step 1:

Use the New Plug-in wizard and create a new plugin. (No RCP - just plain old plugin)

Step 2:

You don't need an Activator. In the Overview tab, remove the Activator class and also delete the Activator.java file from the sources.

Step 3:

The default dependencies of this would have o.e.core.runtime and o.e.ui. In e4, we still need the core.runtime in e4, but not the o.e.ui. Remove it. Now add the following dependencies:

  • org.eclipse.swt,
  • org.eclipse.jface,
  • org.eclipse.e4.ui.workbench
  • org.eclipse.e4.ui.workbench.swt

Step 4:

Lets create a view. Instead of o.e.ui.views, now we have to use org.eclipse.e4.workbench.parts extension (which should now serve both the editors and views). The extension point would look like

<extensio point="org.eclipse.e4.workbench.parts">
<part class="com.eclipse_tips.e4.firstapp.MyFirstView" />

The implementation class would be:

public class MyFirstView {

public MyFirstView(Composite parent){

// this shouldn't be there ideally, investigating
if(parent.getLayout() == null)
parent.setLayout(new FillLayout());

Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FillLayout());

Button button = new Button(composite, SWT.PUSH);
button.setText("Hello World");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
MessageDialog.openInformation(new Shell(), "e4", "Hello e4 World!");


Yes, what you are seeing it correct. It doesn't implement the IWorkbenchView or extend ViewPart. Further more, it appears that I've done one of the top 10 mistakes by not having a default constructor. Don't worry, e4 is smart. When it instantiates an object like this thru reflection, it identifies the parameters for the constructor and will pass them from the context. If more than one constructor is present, it can even identify the right one to use (more on this later)

Step 5:

Now, we have the view, lets create an RCP product that will use this view. Fire up the New Wizard and create a Product Configuration file with the basic settings. In the Product Configuration editor, give it some name and click the New for the Product. Specify some id and select 'org.eclipse.e4.ui.workbench.swt.application' for Application.

Step 6:

Go back to your plugin.xml. You should see the newly created application there. Now lets create the missing link between the product and the view - the UI model. In a typical 3.x RCP, you would have specified an application that has a run method, an initial perspective id, the layout for that perspective, the views, menus, actions thru the ActionFactory constants etc. This whole setup would require a little bit of both java coding and plugin.xml configuration. In e4, you can specify the entire UI in a model. Thats the applicationXMI. It can get as complex as your UI can be, but the simplest one looks like this:

<?xml version="1.0" encoding="ASCII"?>
<application:MApplication xmi:version="2.0"

<windows name="Main Window" width="200" height="100">
<children xsi:type="application:MContributedPart"

There is nothing much to explain. It has got nothing more than a window and a view in it. (no menus,no tool bars, no status lines and even no stacks to hold the view) Specify this file in the parameter of the product extension:

name="My First e4 RCP">

Step 7:

You are all set to go. Switch to the Dependencies tab of the Product Editor and add your plugin. Click 'Add Required plugins' and launch. The launch will fail, because we have not included few more plugins that are required, but not specified in the dependencies (from databinding beans to renderers will be missing) The simplest way to get thru the error, is to edit the launch configuration and launch with 'all workspace and enabled target plugins'.

Now launch again, voila - there comes your first e4 RCP!

So what has happened till now? With the product & launch configuration, we are basically running the org.eclipse.e4.ui.workbench.swt.application. The application looks for the model of the UI in the applicationXMI parameter. It creates the Workbench, and asks it to render the UI from that model. Recursively, an appropriate renderer for every element in the XMI file is found, and its asked to create the UI. Finally you get the app:

From http://blog.eclipse-tips.com

MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}