First steps with Eclipse 4

In June 2012 a very important thing happened in the Eclipse world: Eclipse 4 platform replaced the great and long lasting 3.x version , which started in 2004 with the release of  3.0 version. During these eight years great progress have been made. In fact Eclipse has become matchless both as an IDE and as a platform. Not to mention moreover that it is completely Open Source and with a particularly “commercially friendly” (EPL) license!

Eclipse 4 platform is kind of a revolution with respect of the previous version. To begin with it is completely EMF (Eclipse Modeling Framework) -based, it got rid of the heavy burden of the 3.x workbench class hierarchy (Application*) and pervasively exploits the Injection mechanism. These are of course just some of the main aspects: in fact here we aim to get in touch with this new platform.

Just a note before we start: despite the changes with this new platform, it is backward-compatible, that is, you can import and manage 3.x projects, thanks to the Compatibility Layer, which implements the old 3.x workbench mechanisms with the new Eclipse 4 paradigms. For those who want to keep working with the old platform, there is a latest 3.x maintenance release version (3.8) here http://download.eclipse.org/eclipse/downloads/eclipse3x.html

IDE Setup

At page http://www.eclipse.org/downloads you can find several different Eclipse 4 packages. Just download and launch this

At the beginning you’ll notice a few graphical innovation with the splash screen and with the renewed look and feel.
Note: it’s always advisable to use a brand new workspace (since a workspace used with other versions of Eclipse may lead to inconsistent behaviours).

SplashKepler

Let’s now install the Tools that will allow us to create an Eclipse 4 application, using the following update site:

http://download.vogella.com/kepler/e4tools

from which we’ll install the following features:

* CSS spy for Eclipse 4  /  E4 CSS Spy (Incubation)
* Eclipse 4 core tools  /  Eclipse e4 Tools (Incubation)

First Application

Thanks to the Tools just installed we are now able to do File -> New -> Other… -> Eclipse 4 Application Project.

Let’s press Next, input a project name, e.g. it.rcpvision.e4training.application and press again Next, Next, select “Create sample content (parts, menu etc. )” check box, then Finish.
Now, instead of going on with 3.x way (with a click on hyperlink “Launch an Eclipse Application”) we’ll act in a different way: note, in fact, that the new project includes a Product (es. it.rcpvision.e4training.application.product).
Launch this product, right-clicking it and selecting Run As/Debug As -> Eclipse Application. Here we have our first running Eclipse 4 application.

Verify that the wizard created an application with a Part (in 3.x we would have used terms like View or Editor: now this distinction has become obsolete!), some Menu items, linked to Commands, implemented by Handlers (these concepts are instead still valid, although differently and easily made).
If we look at the generated code we’ll see that there disappeared all the 3.x workbench classes. In fact we just have classes

for the generated sample Handlers and the Part.

But what to do if we want to add a new Part where we can put our graphical components? We just have to edit file Application.e4xmi, which represents the EMF model of our application.

Let’s expand Windows node down, till we get the Part Stack object selected

and on the right side, where the details of selected object are shown, press the Add… button after having verified that the nearby combo is showing item “Part”. We are in fact adding a new Part to the selected Part Stack object.

insert a text for Label of this Part, e.g. Orders

and save. Now, launching the application we will see the new created Part (please note that we did not created a correspondent Java class)

In order to put some widget into this Part let’s get back to its detail panel and click the Class URI hyperlink

set a package (e.g. it.rcpvision.e4training.application.parts) and a class name, e.g. Orders, then Finish.

note that the created class does not extend a class, nor implements any interface: it’s a plain Java class with some Annotation.

package it.rcpvision.e4training.application.parts;

import javax.inject.Inject;
import org.eclipse.e4.ui.di.Focus;

public class Orders {

	@Inject
	public Orders() {
	}

	@Focus
	public void onFocus() {
	}

}

Now add the following method

	@PostConstruct
	public void createPartControl(Composite parent) {

	}

Indeed the method name can be different; the important things are the Annotation @PostConstruct and the Composite parameter). Now you can in fact open this class with WindowBuilder

and start populating it with components like you learned in our previous tutorials (see for example WindowBuilder: advanced databinding with CDO).

and in the end you can launch the application and see the first results.

Special credits to Lars Vogel, for his great tutorials, his precious advices and his latest Eclipse 4 book (details below)!

Credits

Lars Vogel
Eclipse 4 Application Development: The complete guide to Eclipse 4 RCP development
Building Eclipse RCP applications based on Eclipse 4

Jonas Helming
Eclipse 4 (e4) Tutorial Part 1 – The e4 Application Model

Tom Schindl
Eclipse / e4

How to contribute to an Eclipse 4 application

This entry was tagged , . Bookmark the permalink.

2 Responses to First steps with Eclipse 4

  1. Sopot Çela says:

    Ciao Vincenzo,

    Infatti seguendo una discussione su https://bugs.eclipse.org/bugs/show_bug.cgi?id=387018 abbiamo deciso di introdurre anche una MPart nel progetto generato dal Wizard (come nello screenshot). Il fix e gia in master quindi sara anche nel seguente stable build.

    Grazie per il tutorial,
    Sopot

    • Vincenzo says:

      Hi Sopot,
      the tutorial has been updated.
      Now it makes use of Lars Vogel’s Update site, so that the fix about MPart is already there!
      Thank you
      Vincenzo

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>