Вы находитесь на странице: 1из 43

e4 - Workshop

Tom Schindl - BestSolution Systemhaus GmbH


SBB Bern June 2011
(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

About Me

CEO BestSolution Systemhaus GmbH

Eclipse Committer

e4

Platform UI

EMF

Projectlead: UFaceKit, Nebula

Member of the Architectual Council


(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4
XWT
EAP
EAP-Tooling

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4
XWT
EAP

Eclipse 4
Application
Platform

EAP-Tooling

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4
XWT
EAP
EAP-Tooling

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


Eclipse Project

e4
XWT
EAP
EAP-Tooling

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

XWT

Platform-UI

EAP

JDT

EAP-Tooling

PDE

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

XWT

Platform-UI 3.x

EAP

Platform-UI 4.x

EAP-Tooling

JDT
PDE

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

Eclipse 3.7 SDK

Eclipse 4.1 SDK

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

Platform-UI 3.x

XWT
EAP

Platform-UI 4.x

EAP-Tooling

JDT
PDE

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

Eclipse 3.7 SDK

Eclipse 4.1 SDK

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

Platform-UI 3.x

XWT
EAP

Platform-UI 4.x

EAP-Tooling

JDT

Eclipse 4.1 SDK


PDE

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

Eclipse 3.7 SDK

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

Platform-UI 3.x

XWT
EAP

Platform-UI 4.x

EAP-Tooling

JDT
PDE
Eclipse 4.1 SDK

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

Eclipse 3.7 SDK

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

Eclipse 3.7 SDK


Platform-UI 3.x

XWT

JDT
EAP

PDE

EAP-Tooling

Eclipse 4.1 SDK


Platform-UI 4.x

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

Eclipse 3.7 SDK


Platform-UI 3.x

XWT

JDT
PDE
EAP-Tooling

Eclipse 4.1 SDK


Platform-UI 4.x
EAP

(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

e4 vs Eclipse 4.x SDK


e4

Eclipse Project

Eclipse 3.7 SDK


Platform-UI 3.x

XWT

JDT
PDE
EAP-Tooling

Eclipse 4.1 SDK


Platform-UI 4.x
EAP
JDT & PDE
(c) Tom Schindl - BestSolution Systemhaus GmbH

Donnerstag, 07. Juli 2011

Setting up development env

Copy e4_workshop to C:/e4_workshop

Copy software/eclipse-SDK-4.1-win32 to C:/e4_workshop

Launch Eclipse (Use C:/e4_workshop/ws)

Add the following local update-sites

file:/C:/e4_workshop/software/2.7/

file:/C:/e4_workshop/software/e4-R-0.11-201106201631/

Donnerstag, 07. Juli 2011

Setting up development env

Donnerstag, 07. Juli 2011

Our first e4 application

Select File > New > Project ...

Select e4 > e4 Application Project

Enter ch.sbb.e4.basic.app as project name

Select Next and Finish the dialog

Donnerstag, 07. Juli 2011

Our first e4 application

Donnerstag, 07. Juli 2011

Java-Files need to bootstrap the


framework are gone

Application.java

Various *Advisor.java

A new file has been added


Application.e4xmi

Our first e4 application

The Application Model

Donnerstag, 07. Juli 2011

Holds the main UI structures

Windows

Menus / Toolbars

Stacks and Parts

Our first e4 application

The Application Model

Donnerstag, 07. Juli 2011

None UI structures

Addons

BindingContexts

Commands + Handlers

Our first e4 application

Donnerstag, 07. Juli 2011

The Application Model

EMF

Storage-Format (xmi)

XML

Any element has an UID

Our first e4 application

Adding an UI which displays a Label with Hello World

Create a new package ch.sbb.e4.basic.app.ui

Select File > New > Other

Select e4 > Classes > Part Class

Enter as Package ch.sbb.e4.basic.app.ui

Enter as Name MyPart

Select Finish

Donnerstag, 07. Juli 2011

Our first e4 application


package ch.sbb.e4.basic.app.ui;
import
import
import
import
import
import

javax.inject.Inject;
org.eclipse.e4.ui.di.Focus;
org.eclipse.swt.SWT;
org.eclipse.swt.layout.FillLayout;
org.eclipse.swt.widgets.Composite;
org.eclipse.swt.widgets.Label;

public class MyPart {



@Inject

public MyPart(Composite parent) {


parent.setLayout(new FillLayout());


Label l = new Label(parent, SWT.NONE);


l.setText("Hello World");

}


@Focus

public void onFocus() {


//TODO Your code here

}


}
Donnerstag, 07. Juli 2011

Our first e4 application

Register the Java-Class in the Application.e4xmi

Donnerstag, 07. Juli 2011

App

Eclipse 4 Application Platform


SWT-UI

Core-Business-Logic

EAP - SWT

Framework

Services

Donnerstag, 07. Juli 2011

DI-Container
Workbench Model
Eclipse 4 Application Platform
OSGi (Equinox)
JRE

EMF

Understanding DI

Got popular through Spring-Frame (configured through xml-Files,


since Java 5 through annotations)

Advantages

Makes looser coupeling between code easy (easier)

Easier to test

Components reuseable in other contexts

Donnerstag, 07. Juli 2011

Understanding DI

Advantages (continued)

Removal of glue code

Disadvantages

Harder to debug

What information is available in which context?

Donnerstag, 07. Juli 2011

Understanding DI
public class IconViewPart extends ViewPart {
public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
this.viewer = new GalleryTreeViewer(parent, SWT.MULTI | SWT.V_SCROLL);
this.workspace = ResourcesPlugin.getWorkspace();
this.workspace.addResourceChangeListener(resourceListener);

this.selectionListener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
setFolder(selection);
}
};
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);

}
public void dispose() {
getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(selectionListener);
this.workspace.removeResourceChangeListener(resourceListener);
super.dispose();
}

public void setFocus() {
viewer.getControl().setFocus();
}
}
Donnerstag, 07. Juli 2011

Understanding DI
public class IconViewPart extends ViewPart {
public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
this.viewer = new GalleryTreeViewer(parent, SWT.MULTI | SWT.V_SCROLL);
this.workspace = ResourcesPlugin.getWorkspace();
this.workspace.addResourceChangeListener(resourceListener);

this.selectionListener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
setFolder(selection);
}
};
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);

}
public void dispose() {
getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(selectionListener);
this.workspace.removeResourceChangeListener(resourceListener);
super.dispose();
}

public void setFocus() {
viewer.getControl().setFocus();
}
}
Donnerstag, 07. Juli 2011

Understanding DI

DI - Standards

JSR 330 (javax.inject): Core DI


@Inject, @Named

JSR 250 (javax.annotation): Lifecycle Support


@PostConstruct, @PreDestroy

Eclipse Extensions

org.eclipse.e4.core.di: @Optional

Donnerstag, 07. Juli 2011

Understanding DI
public class MyAppInstance {

// Field injection

@Inject

private IGreetingService service;


// Constructor injection

@Inject

public MyAppInstance(IGreetingService service) {



}


// PostConstruct Method injection

@PostConstruct

public void init(IGreetingService service) {



}


// Method injection

@Inject

public void setService(IGreetingService service) {



}
}
Donnerstag, 07. Juli 2011

Understanding DI

Injection order Construction:

Constructor Injection

Field Injection

Method Injection

@PostConstruct

Donnerstag, 07. Juli 2011

Injection order Deconstruction:

@PreDestroy

Understanding DI

IEclipseContext

Can be seen as an hierarchical Map

IEclipseContext#set/get

Key is name of the value to be injected

If @Named: value specified in there

If no @Named: fully qualified name of the values class

Donnerstag, 07. Juli 2011

Understanding DI - an example

DI Example Application

Donnerstag, 07. Juli 2011

Annotation Bundles

javax.inject

@Inject: marks value to be subject to injection

@Named: Use the value instead of the fully qualified classname

@Qualifier: Annotation to annotate custom DI-Annotation like


(@Preferences)

Donnerstag, 07. Juli 2011

Annotation Bundles

javax.annotation

@PostConstruct: Called after all injects are done

@PreDestroy: Called the before the context that created the object
gets disposed

Donnerstag, 07. Juli 2011

Annotation Bundles

org.eclipse.e4.core.di

@Optional: Mark injected value as not required

@Execute: Mark method to be executed e.g. by the Command/


Handler-System

@CanExecute: Mark method to be consulted by Command/


Handler-System to check if it is enabled

Donnerstag, 07. Juli 2011

Annotation Bundles

org.eclipse.e4.core.di.extensions

@EventTopic: Mark an argument/field to get injected through the


event system (injection not necessarily on the UI-Thread)

@Preference: Mark an argument to get injected through from the


preferences

Donnerstag, 07. Juli 2011

Annotation Bundles

org.eclipse.e4.ui.di

@Focus: Called when the Part should is focused

@Persist: Called by the framework when one of the savecommands is executed

@UIEventTopic: Mark an argument/field to get injected through


the event system (injection done on the UI-Thread)

Donnerstag, 07. Juli 2011

Dynamic calculated DI-Values

Done through an IContextFunction

Registered through DS

provided service: org.eclipse.e4.core.contexts.IContextFunction

property:

name: service.context.key

value: key used to look up the value in the IEclipseContext

Donnerstag, 07. Juli 2011

Custom DI-Annotations

Done with ExtendedObjectSupplier

Registered via DS

service: org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier

property:

name: dependency.injection.annotation

value: fqn of the annotation

Donnerstag, 07. Juli 2011

Вам также может понравиться