Java, Eclipse and Web programming Tutorials
Follow me on twitter About Lars Vogel

Eclipse e4 - Tutorial

Lars Vogel

Version 2.8

13.03.2010

Revision History
Revision 0.114.02.2009Lars Vogel
First version of Eclipse e4
Revision 0.216.02.2009Lars Vogel
Added XWT example
Revision 0.304.03.2009Lars Vogel
Added CSS example
Revision 0.404.04.2009Lars Vogel
Updated to e4 Milestone 2
Revision 0.512.07.2009Lars Vogel
Added links to news and noteworthy e4 M3, M4 and M5
Revision 0.629.07.2009Lars Vogel
Updated install description
Revision 0.717.08.2009Lars Vogel
Link to blog for how to create a first E4 application
Revision 0.824.08.2009Lars Vogel
Link to blog for using css styling
Revision 0.904.11.2009Lars Vogel
Added link to OpenSocial Gadgets
Revision 1.021.11.2009Lars Vogel
Updated XWT example
Revision 1.124.11.2009Lars Vogel
More infos to OpenSocial Gadgets
Revision 1.225.11.2009Lars Vogel
Moved OpenSocial Gadgets to separate article
Revision 1.303.01.2010Lars Vogel
Changed E4 to e4, moved XWT to own article
Revision 1.413.01.2010Lars Vogel
Updated e4 description to upcoming e4 milestone
Revision 1.515.01.2010Lars Vogel
Fixed errors, added e4 M4 New and noteworthy
Revision 1.617.01.2010Lars Vogel
Toolbar and menu, first version
Revision 1.719.01.2010Lars Vogel
Menu now working
Revision 1.821.01.2010Lars Vogel
css styling for widgets
Revision 1.923.01.2010Lars Vogel
Added service and dependency injection
Revision 2.025.01.2010Lars Vogel
Fixed typo
Revision 2.111.02.2010Lars Vogel
Making view look a little bit nicer
Revision 2.223.02.2010Lars Vogel
Adding e4 wizard and deployment
Revision 2.327.02.2010Lars Vogel
Update to M4
Revision 2.301.03.2010Lars Vogel
UI designer added
Revision 2.403.03.2010Lars Vogel
Added Eclipse RAP
Revision 2.507.03.2010Lars Vogel
the modeled workbench
Revision 2.610.03.2010Lars Vogel
more info on modeled workbench
Revision 2.712.03.2010Lars Vogel
how to add model components based on extension
Revision 2.813.03.2010Lars Vogel
added link to wiki for compatibility layer

Eclipse e4

This article gives an overview about Eclipse e4 and describes how to create your first Eclipse e4 application.


Table of Contents

1. Eclipse e4
2. Installation
3. Your first e4 application via the wizard
3.1. Create project
3.2. Launch
4. UI designer
5. The modeled workbench
5.1. The meta model
5.2. Contributing to the e4 model
5.3. Merging model elements
6. Create your first e4 application manually
6.1. Create project
6.2. Add dependencies
6.3. Create product configuration
6.4. Maintain Extension points
6.5. Create the workbench model
6.6. Run your application
6.7. Add a view
6.8. Run your updated application
7. Toolbar and Menu
7.1. Create command handler
7.2. Menu and Toolbar
8. Contribute model elements
8.1. Contribute a model elements
8.2. Project
8.3. Launch
9. Styling your UI with css
9.1. Overview
9.2. Gradients
9.3. Example
10. Using Services
10.1. Overview
10.2. Example
11. e4 and Eclipse RAP
12. Examples
13. Deployment
14. Thank you
15. Questions and Discussion
16. Links and Literature
16.1. Source Code

1. Eclipse e4

The Eclipse e4 project was started shortly before EclipseCon 2008 and the main reason was that the old code base was getting harder and harder to maintain. Eclipse e4 brings a new set of technologies into the existing Eclipse platform that make Eclipse components easier to write, more configurable by application developers and integrators, and easier to reuse in diverse runtime environments.

The major changes in Eclipse e4 are:

  • The Eclipse workbench UI is described by an EMF model

  • Eclipse widgets can be styled via CSS style sheets

  • The existing Eclipse API's are re-worked to make them simpler

  • Eclipse e4 supports dependency injection.

For an overview of the targets of Eclipse e4 please see the Eclipse e4 Whitepaper

.

2. Installation

Eclipse e4 comes as a complete all-in-one download version, you find the latest version in http://download.eclipse.org/e4/downloads/ . Unfortunately Eclipse e4 is still a bit of a moving target. The following description is based on Eclipse e4 Milestone 4.

3. Your first e4 application via the wizard

3.1. Create project

Eclipse e4 provides a wizard for creating e4 application. Start Eclipse e4 and select File -> New -> Others -> e4 -> e4 Application Project

Create the project "de.vogella.e4.rcp.wizard" and follow the screenshots.

Select the file "de.vogella.e4.rcp.wizard.product" and select the "Dependencies" tab. Press "Add required plugins".

3.2. Launch

Switch to the overview tab and launch your product.

The first time the launch may fail. Open the launch configuration.

and press "Add required plugins". Also select "Validate plugins prior to launching".

Launch your application again.

4. UI designer

Eclipse e4 ships with a graphical UI designer. It is supposed to allow the user to maintain the Application.e4xmi via a graphical editor.

Create a new e4 project "de.vogella.e4.rcp.uidesigner" via the wizard. Double click on "Application.e4xmi", this should open the graphical editor. In case the editor is not opened you can select the editor via.

Tip

Alternatively you can maintain your file "Application.e4xmi" via the the Ecore reflective editor via right-mouse click -> "Open With"-> Other -> "Sample Reflective Ecore Model Editor".

Switch to the "XWT" perspective.

You can now add via drag-and-drop elements to the UI.

Tip

In my example the UI editor did not always work stable. I assume that is because this feature is very new. I expect that over time the editor will become more stable.

5. The modeled workbench

Tip

This chapter explains the fundamentals of the Eclipse e4 workbench model. If you are more a hands-one person feel free to skip this chapter and continue with the next one.

5.1. The meta model

The Eclipse e4 workbench is modeled via Eclipse EMF . The models contains the graphical elements of the workbench, e.g. the parts (views, editors, menu bars) and some non-visual parts of the command framework, e.g. handlers, commands and keybindings. This scope of the model does not contain information about the individual UI elements within one part.

The Eclipse e4 model structure is defined via the plugin "org.eclipse.e4.ui.model.workbench" which contains the "UIElements.ecore" meta-model.

The meta-model contains basically the following elements:

  • Menus and Toolbars

  • RCP - Elements for building an RCP application

  • Commands: The e4 commands version

  • Trim: Allow to add trim container for other UI elements on any side of a window

  • Shared Elements: elements allowing the reuse of model elements in different parts of the model. Used in the compartibility layer for sharing views and editors in different perspectives.

The "UIElements.genmodel" defines among other things that interfaces for the workbench model starts with M.

5.2. Contributing to the e4 model

The base e4 application model is placed in an XMI file. This file is provided the e4 application via the parameter "applicationXMI" of the extension point "org.eclipse.core.runtime.products". This file is a standard XMI / text file which can be defined and modified by a text editor, the standard EMF editors or via the e4 wizard.

Model elements can also be supplied via the extension point "org.eclipse.e4.workbench.model". These elements are then read and merged by the application into one application model.

This file and is read during startup from the application. The contained information in the model is used by the application to construct the workbench. Changes during runtime are written back to the model and are available during runtime.

5.3. Merging model elements

The e4 model has three components which will be combined.

  1. The application defines in its application.e4xmi file a base model (for example, main menu, perhaps UI elements like views that are always there, etc). This file changes over time as new versions of the application are being developed and released.

  2. Other plug-ins add to that model through our model extension point. Plug-ins can be installed and uninstalled. This means that we have a model that results from combining the base model with these contributions. Of course, this means that there is an additional source of change to the model, but it is pretty clear how these contributions get merged into the model.

  3. While the application is running, the model objects are being changed. For example, views that were there when the application first started got closed, or menus/toolbars were customized, new views were opened, etc. These changes need to be persisted across sessions, and ideally even across updating plug-ins or the base application. The model delta are captured based on the difference to the real model, e.g. if you move View A to another place and move it back to the original position no delta is saved

The workbench model needs to the user changes and must be able to react to changes in the Application.e4xmi and the model contributions. The workbench models handles this as follows: On first startup, populate the model as described under 1 and 2. Changes during the session will be recorded as deltas, and we persist these deltas instead of the whole model when we shut down. Then, for subsequent startups, populate the model as described under 1 and 2 and then apply any persisted deltas from 3. If there are deltas that don't make any sense then skip them. The delta are applied to the model based on the ID's of the UI component.

6. Create your first e4 application manually

The wizard from the previous chapter allow to create fast a running e4 application. The following chapter describes the individual steps required to create an e4 application without the wizard. I assume you will rarely use this but it might be helpful to understand some details.

6.1. Create project

Create a new Plugin project "de.vogella.e4.rcp.first". Do not select "Generate an activator", nor "This plug-in will make contributions to the UI" nor "Would you like to create a rich client application". Do not select a template.

Create the package "de.vogella.e4.rcp.first".

6.2. Add dependencies

Add the following dependencies to your MANIFEST.MF.

  • org.eclipse.core.runtime

  • org.eclipse.e4.ui.workbench

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

  • org.eclipse.e4.ui.workbench.renderers.swt

  • org.eclipse.e4.ui.workbench.renderers.swt.contributions

  • org.eclipse.e4.core.services

  • org.eclipse.e4.ui.services

  • javax.inject

  • org.eclipse.equinox.ds

  • org.eclipse.equinox.event

This should result in the following entries in MANIFEST.MF. Your version of the plugins may be different.

				
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: First
Bundle-SymbolicName: de.vogella.e4.rcp.first;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.6.0",
 org.eclipse.e4.ui.workbench;bundle-version="0.9.1",
 org.eclipse.e4.ui.workbench.swt;bundle-version="0.9.1",
 org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.9.1",
 org.eclipse.e4.ui.workbench.renderers.swt.contributions;bundle-version="0.9.1",
 org.eclipse.e4.core.services;bundle-version="0.9.1",
 org.eclipse.e4.ui.services;bundle-version="0.9.1",
 javax.inject;bundle-version="1.0.0",
 org.eclipse.equinox.ds;bundle-version="1.2.0",
 org.eclipse.equinox.event;bundle-version="1.2.0"

			

6.3. Create product configuration

Create a new product configuration "de.vogella.e4.rcp.first.product".

Make sure you select "org.eclipse.e4.ui.workbench.swt.E4Application" as the application.

Add as dependency the plugin "de.vogella.e4.first".

6.4. Maintain Extension points

The product creation should have created the extension point "org.eclipse.core.runtime.products" in the file "plugin.xml". Currently there is a bug please see Creating a product configuration and "org.eclipse.core.runtime.products" .

Verify that "org.eclipse.e4.ui.workbench.swt.E4Application" is selected as application and maintain the properties "appName" and "applicationXMI".

Table 1. Sample Table

propertyvalue
appNameFirst e4 application
applicationXMIde.vogella.e4.rcp.first/Application.e4xmi

The resulting plugin.xml should look like the following.

				
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            application="org.eclipse.e4.ui.workbench.swt.E4Application"
            name="First e4 application">
         <property
               name="applicationXMI"
               value="de.vogella.e4.rcp.first/Application.e4xmi">
         </property>
         <property
               name="appName"
               value="First e4 application">
         </property>
      </product>
   </extension>
</plugin>

			

6.5. Create the workbench model

Create the file "Application.e4xmi" with the following content.

				
<?xml version="1.0" encoding="ASCII"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2008/UIModel" id="Application">
  <children xsi:type="application:Window" id="Window"/>
</application:Application>


			

Tip

After creating it you may have to open it with the text editor.

Open this file with the EMF model editor.

For every model element you can maintain its model properties via the property view.

Tip

Please note that this is of course only a minimal e4 application.

6.6. Run your application

Create a launch configuration based for your product and run your application. The result should look like the following.

6.7. Add a view

Now we will add some SWT UI elements. Add therefore a dependencies to "org.eclipse.swt" in MANIFEST.MF.

Create the following class.

				
package de.vogella.e4.rcp.first.parts;

import javax.inject.Inject;

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.Label;
import org.eclipse.swt.widgets.Text;

public class View1 {

	private final Composite parent;

	// e4 will inject the composite "parent" into the view
	@Inject
	public View1(Composite parent) {
		// the following is standard SWT Stuff
		this.parent = parent;
		
		final GridLayout layout = new GridLayout(2, false);
		parent.setLayout(layout);
		
		createLable("Release");
		createText("E4");
		createLable("Purpose");
		createText("Doing awesome stuff");
	}

	// Standard SWT Stuff
	private void createLable(String text) {
		Label label = new Label(parent, SWT.NONE);
		label.setText(text);
		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gridData.horizontalIndent = 20;
		label.setLayoutData(gridData);
	}

	// Standard SWT Stuff
	private void createText(String text) {
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
		Text textField = new Text(parent, SWT.NONE);
		textField.setText(text);
		textField.setLayoutData(gridData);
	}

}

			

Tip

Notice that the View1.java code does not have any dependency to the Eclipse / OSGi framework. Just a simple POJO. By using the @inject annotation you are telling the Eclipse framework to inject a composite into the view.

To add this view to your application, select your Application.xmi and right-click on Window. Select New Children -> Children Part

Maintain the properties. Use the URI "platform:/plugin/de.vogella.e4.rcp.first/de.vogella.e4.rcp.first.parts.View1". The first part of this URI is the plugin and the second one the package. Make sure you don't have a typo here.

6.8. Run your updated application

Run again your application you it should look like the following.

Congratulations. You have hand-crafted your first full featured Eclipse e4 application.

7. Toolbar and Menu

7.1. Create command handler

Create the class which will handle the command.

				
package de.vogella.e4.rcp.first.handlers;

import org.eclipse.e4.workbench.ui.IWorkbench;

public class ExitHandler {
	public void execute(IWorkbench workbench) {
		workbench.close();
	}
}

			

7.2. Menu and Toolbar

Select Application.xmi and create the following.

Tip

For the menu select the entry "Main Menu Menu" not the one starting with "Children".

The resulting Application.xmi looks like the following.

				
<?xml version="1.0" encoding="ASCII"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2008/UIModel" id="Application">
  <children xsi:type="application:Window" label="My first e4 application" iconURI="" tooltip="" id="Window" onTop="true" width="200" height="200">
    <children xsi:type="application:Part" id="View1" style="" URI="platform:/plugin/de.vogella.e4.rcp.first/de.vogella.e4.rcp.first.parts.View1" containerData="" label="Hallo" tooltip=""/>
    <children xsi:type="application:WindowTrim">
      <children xsi:type="application:ToolBar">
        <children xsi:type="application:DirectToolItem" URI="platform:/plugin/de.vogella.e4.rcp.first/de.vogella.e4.rcp.first.handlers.ExitHandler" label="Exit"/>
      </children>
    </children>
    <mainMenu>
      <children xsi:type="application:MenuItem" id="" label="File">
        <children xsi:type="application:DirectMenuItem" URI="platform:/plugin/de.vogella.e4.rcp.first/de.vogella.e4.rcp.first.handlers.ExitHandler" label="Exit"/>
      </children>
    </mainMenu>
  </children>
</application:Application>

			

If you run the application it should look like.

8. Contribute model elements

8.1. Contribute a model elements

As describe earlier e4 allows that model elements are contributed via the extension point "org.eclipse.e4.workbench.model". Model components can be parts (views or editors), commands, handlers and most other elements from the e4 meta-model.

8.2. Project

Create a new e4 project "de.vogella.e4.rcp.modelcontribution". Create two views "de.vogella.e4.rcp.modelcontribution.parts.View1" and "de.vogella.e4.rcp.modelcontribution.parts.View2" .

Define the following "Application.e4xmi" file.

				
<?xml version="1.0" encoding="UTF-8"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2008/UIModel" xmi:id="a" id="myapplication">
  <children xsi:type="application:Window" xmi:id="_m-KkfC2LEd-RMdxMTPbEkQ" label="Window" id="_m-KkfC2LEd-RMdxMTPbEkQ" width="500" height="400">
    <children xsi:type="application:PartStack" xmi:id="_Uq3zAC4qEd-CRdAyrDY9Rw" id="_Uq3zAC4qEd-CRdAyrDY9Rw">
      <children xsi:type="application:Part" xmi:id="_Lzk0cC4lEd-xNPM3xY6yzA" id="de.vogella.e4.rcp.modelcontribution.parts.View1" URI="platform:/plugin/de.vogella.e4.rcp.modelcontribution/de.vogella.e4.rcp.modelcontribution.parts.View1" label="My View" iconURI="" tooltip=""/>
      <children xsi:type="application:Part" xmi:id="_r0NGEC4qEd-CRdAyrDY9Rw" id="de.vogella.e4.rcp.modelcontribution.parts.View1" URI="platform:/plugin/de.vogella.e4.rcp.modelcontribution/de.vogella.e4.rcp.modelcontribution.parts.View2" label="My second View" iconURI="" tooltip=""/>
    </children>
    <mainMenu xmi:id="_gK2vQS4oEd-CRdAyrDY9Rw" id="_gK2vQS4oEd-CRdAyrDY9Rw">
      <children xsi:type="application:MenuItem" xmi:id="_lpaKAC4lEd-xNPM3xY6yzA" id="_lpaKAC4lEd-xNPM3xY6yzA" label="File">
        <children xsi:type="application:DirectMenuItem" xmi:id="_mgPrYC4lEd-xNPM3xY6yzA" id="_mgPrYC4lEd-xNPM3xY6yzA" URI="platform:/plugin/de.vogella.e4.rcp.modelcontribution/de.vogella.e4.rcp.modelcontribution.handlers.ViewAddHandler" label="Add View"/>
      </children>
    </mainMenu>
  </children>
</application:Application>

			

Create a folder "xmi" in your project and create the following file".

				<?xml version="1.0" encoding="ASCII"?>
<application:ModelComponents xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2008/UIModel" xsi:schemaLocation="http://www.eclipse.org/ui/2008/UIModel ../../org.eclipse.e4.ui.model.workbench/model/UIElements.ecore" xmi:id="_UW9TZfr3Ed6gmo7caOxU9h">
  <components xmi:id="_UW9TZfr3Ed6gmo7caOxU9q" id="_UW9TZfr3Ed6gmo7caOxU9q" parentID="_m8-RoS2LEd-RMdxMTPbEkQ">
    <descriptors id="de.vogella.e4.rcp.modelcontribution.parts.View2" URI="platform:/plugin/de.vogella.e4.rcp.modelcontribution/de.vogella.e4.rcp.modelcontribution.parts.View2" label="My Model Component" category="_m-UVdy2LEd-RMdxMTPbEkQ"/>
  </components>
</application:ModelComponents>

			

Add the extension point ""org.eclipse.e4.workbench.model" to your plugin.xml with the uri "xmi/components.e4xmi".

				
<?xml version="1.0" encoding="UTF-8"?>
<plugin>

   <extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            name="de.vogella.e4.rcp.modelcontribution"
            application="org.eclipse.e4.ui.workbench.swt.E4Application">
         <property
               name="appName"
               value="de.vogella.e4.rcp.modelcontribution">
         </property>
         <property
               name="applicationXMI"
               value="de.vogella.e4.rcp.modelcontribution/Application.e4xmi">
         </property>
         <property
               name="applicationCSS"
               value="platform:/plugin/de.vogella.e4.rcp.modelcontribution/css/default.css">
         </property>
      </product>
   </extension>
   <extension
         id="id1"
         point="org.eclipse.e4.workbench.model">
      <snippet
            uri="xmi/components.e4xmi">
      </snippet>
   </extension>

</plugin>

			

Add now the "ViewAddHandler" class.

				
package de.vogella.e4.rcp.modelcontribution.handlers;

import javax.inject.Inject;

import org.eclipse.e4.core.services.context.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.MPart;
import org.eclipse.e4.ui.model.application.MPartDescriptor;
import org.eclipse.e4.ui.model.application.MUIElement;
import org.eclipse.e4.ui.model.application.MWindow;
import org.eclipse.e4.workbench.modeling.EPartService;
import org.eclipse.e4.workbench.modeling.EPartService.PartState;
import org.eclipse.e4.workbench.ui.IWorkbench;
import org.eclipse.emf.common.util.EList;

import de.vogella.e4.rcp.modelcontribution.parts.View2;

public class ViewAddHandler {
	@Inject
	private IEclipseContext context;
	@Inject
	private EPartService service;

	public void execute(IWorkbench workbench) {
		MWindow window = (MWindow) context.get(EPartService.PART_SERVICE_ROOT);
		MApplication app = (MApplication) (MUIElement) window.getParent();
		EList<MPartDescriptor> descriptorList = app.getDescriptors();
		for (MPartDescriptor partDesc : descriptorList) {
			System.out.println(partDesc.getId());
			if (partDesc.getId().equals(View2.ID)) {
				MPart part = service.showPart(partDesc.getId(),
						PartState.ACTIVATE);
				break;
			}
		}
	}
}

			

8.3. Launch

If you start the application then you should be able to select your menu and this should add the additional View to to application.

9. Styling your UI with css

9.1. Overview

The layout and the appearance of HTML Webpages can be styled via Cascading Style Sheets (CSS). Similar Eclipse e4 allows to style your UI widgets via CSS properties.

Each UI widget can be addressed via the corresponding CSS class. Colors of widgets can defined via differences ways, e.g. the color white can be described via #white, rgb(255,255,2555) or #ffffff.

It is also possible to set a data tag for a specific SWT UI element and use this data tag in the CSS. For example you can set the tag for an label via:

				
Label label = new Label(parenet, SWT.NONE);
label.setData("org.eclipse.e4.ui.css.id","MyCSSTagForLabel");
			

This element can be addressed in the CSS via:

				
#MyCSSTagForLabel{
	color:#blue;
}
			

9.2. Gradients

Styling supports gradients for the background color of UI controls. Linear and radial gradients are supported. To define a gradient use:

				
// linear gradient
background-color: gradient linear color_1 [color_2]* [percentage]*

// For example
background-color: gradient linear white black 
background-color: gradient linear white black blue
background-color: gradient linear white black 50%
background-color: gradient linear white black 50% 20%

// radial gradient
background-color: gradient linear color_1 color_2 [percentage]

// For example
background-color: gradient radial white black
background-color: gradient radial white black 50%

			

If you use the optional percentage in the definition then the color change will be done after the defined percentage.

9.3. Example

Create the folder "css" in your application and create the following file "myfirststylesheet.css".

				
Label {
	font: Verdana 20px;
	color:rgb(178,34,34);
	background-color:rgb(255,255,255) rgb(0,0,0) 60%;
}

CTabItem, ToolBar, Button, CBanner, CoolBar {
	font-size: 9;
	background-color: blue;
}

Button {
	font: Verdana 15px;
	background-color:rgb(255,255,255) rgb(0,0,0);
}

Text {
	font: Verdana 15px;
	background-color:radial rgb(255,255,255) rgb(0,0,0);
}

			

Add the property "applicationCSS" to your application in extension point "org.eclipse.core.runtime.products". This property which points to the css file to your product:

Run your application it should look like the following.

For more information about the available styling options please see Wiki for css styling .

10. Using Services

10.1. Overview

Eclipse e4 introduces also a new service concept and dependency injection for these services.

See Eclipse e4 services Wiki for an overview of the available services.

10.2.  Example

Change the code of your view to the following to inject the Logger service and to get the IEclipseContext injected into your view.

				
package de.vogella.e4.rcp.first.parts;

import javax.inject.Inject;

import org.eclipse.e4.core.services.Logger;
import org.eclipse.e4.core.services.annotations.PostConstruct;
import org.eclipse.e4.core.services.context.IEclipseContext;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class View1 {
	
	@Inject private Logger logger;
	@Inject private IEclipseContext context;
	@Inject private Composite parent;
	
	// PostConstruct ensures that the dependency injection has been finished 
	// this this method is called 
	@PostConstruct
	public void init() {
		// If you don't inject the Logger you could alternatively 
		// get it via the IEclipseContext with the following statement
		// Logger log= (Logger) context.get(Logger.class.getName());
		System.out.println(context!=null);
		System.out.println(logger!=null);
		logger.info("UI will start to build");
		
		Label label = new Label(parent, SWT.NONE);
		label.setText("E4 is new");
		Text text = new Text(parent, SWT.NONE);
		text.setText("and different");
	}

}

			

11. e4 and Eclipse RAP

If you want to run Eclipse e4 and the RAP runtime you can look at the following wike Eclipse e4 and Eclipse RAP integration .

12. Examples

Eclipse e4 comes with lots of examples for the several purposes.

http://wiki.eclipse.org/E4/Install contains a description how to run them.

13. Deployment

Deployment of an Eclipse e4 application works similar to the deployment of an Eclipse RCP application. Please see Eclipse RCP .

Please make sure that you include all the e4 artifacts in your "build.properties".

14. Thank you

Thank you for practicing with this tutorial.

Please note that I maintain this website in my private time. If you like the information I'm providing please help me by donating.

15. Questions and Discussion

For questions and discussion around this article please use the www.vogella.de Google Group. Also if you note an error in this article please post the error and if possible the correction to the Group.

I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.

16. Links and Literature

16.1. Source Code

http://www.vogella.de/code/codeeclipse.html Source Code of Examples

http://wiki.eclipse.org/E4 Eclipse E4 - Wiki

http://wiki.eclipse.org/E4/Install Eclipse E4 installation wiki

http://download.eclipse.org/e4/downloads/drops/S-0.9M1-200902061045/e4-news-M1.html e4 0.9 M1 - New and Noteworthy

http://download.eclipse.org/e4/downloads/drops/S-0.9M2-200903201930/e4-news-M2.html Eclipse e4 0.9 M2 - New and Noteworthy

http://download.eclipse.org/e4/downloads/drops/S-0.9M3-200905080830/e4-news-M3.html Eclipse e4 0.9 M3 - New and Noteworthy

http://download.eclipse.org/e4/downloads/drops/S-0.9M5-200907101930/e4-news-M5.html Eclipse e4 0.9 M4 and M5 - New and Noteworthy

http://download.eclipse.org/e4/downloads/drops/R-0.9-200907291930/e4-news-all.html Eclipse e4 0.9 Technical preview - New and Noteworthy

http://download.eclipse.org/e4/downloads/drops/S-1.0M3-201001142115/e4-news-M3.html Eclipse e4 1.0 M3 - New and Noteworthy

http://download.eclipse.org/e4/downloads/drops/S-1.0M4-201002271345/e4-news-M4.html Eclipse e4 1.0 M4 - New and Noteworthy