Download - ITU - MDD - Eclipse Plug-ins
L0079 - 2009-08-27
Redistribution and other use of this material requires written permission from The RCP Company.
ITU - MDD - Eclipse Plug-ins
This presentation shows how Eclipse plug-ins are developed. It has two purposes:Introduce you to the architecture and techniques of a major component based applicationIntroduce you to basic Eclipse plug-in development – this will hopefully ease the needed programming in the rest of the course
This presentation is developed for MDD 2010 course at ITU, Denmark.
L0079 - 2009-08-27
2
Equipment and Groups
Today's lecture will include a bit of Java development!
So…
You need your laptop
You need the following installed and tested – please – on your laptop Eclipse 3.6 Modelling Edition Java SDK 6
You need to be in a group of people (3-4) with some knowledge of Eclipse IDE as a development platform Java development User interface development – if possible
L0079 - 2009-08-27
3
Agenda
Eclipse Architecture The basic plug-in What is a plug-in? Standard Widget Toolkit – SWT
L0079 - 2009-08-27
4
Agenda
Eclipse Architecture What are the drivers for the Eclipse architecture What are the requirements for the architecture
L0079 - 2009-08-27
5
Some Numbers on Eclipse
The Eclipse Modeling Tools 1099 plug-ins 229 features
All Eclipse Projects >45 projects in the Galileo release train 29 MLoC >500 active committers >25 countries >140 locations
L0079 - 2009-08-27
6
Project Activity
L0079 - 2009-08-27
7
So…
We need an architecture that supports distributed development over a large number of autonomous development groups
We need a component concept where components are loosely coupled and can be started (and stopped) independently
We need a way to describe external interfaces of components and dependencies between components
We need a way to only start the components as they are needed – also known as late activation
We need all this to work over multiple generations of components
L0001 - 2008-11-27
8
Eclipse Architecture
Goals for the Eclipse architecture Be able to host any number of 3rd party applications Scalability in terms of size and complexity of hosted applications Alignment with native UI look-n-feel
Flexible architecture, structured around Plug-ins – the basic unit of functionality Extension points – the defined interfaces between plug-ins
This architecture allows for Implementation of 3rd party applications on top of the basic platform
(Eclipse RCP) Additional tools to be integrated in the platform Integrated tools to be further extended
L0001 - 2008-11-27
9
EclipsePlatform
Res
ourc
es
Wor
ksp
ace
Hel
p
Upd
ate
Tea
m
Web
Ser
ver
File
syst
ems
Apa
che
Sea
rch
Nav
igat
or
Intr
o
Tex
t E
dito
rs
Eclipse Architectural Components
JDT
CV
S
WT
P
Da
tato
ols
VE
BIR
T
Myl
yn
PD
E
Eclipse RCP
Run-time/OSGi
SWT
JFace
WorkbenchP
refe
renc
es
Jobs
ICU
Com
man
ds
Reg
istr
y
CD
T
L0001 - 2008-11-27
10
The Basic RCP Components
In the Eclipse, everything is a plug-in including the run-time platform itself It is a small kernel that represents the base of the platform Built on top of OSGi
All subsystems built on the run-time platform follows the rules of plug-ins: They are plug-ins themselves
RCP includes: Component Management Resources Management Preferences Workbench (include SWT and JFace)
RCP does not include functionality that are not commonly needed: Update Help This can be included from the Eclipse platform
Eclipse RCP
Run-time/OSGi
SWT
JFace
WorkbenchP
refe
renc
es
Jobs
ICU
Com
man
ds
Reg
istr
y
L0001 - 2008-11-27
11
ApplicationPlatform
Com
m.
Log
ging
Hel
p
Upd
ate
Aut
h.
Aud
itin
g
Apa
che
Intr
o
Your Typical RCP Application
Ba
se
Ad
d-o
n
Ad
d-o
n
Ad
d-o
n
Ad
d-o
n
De
bu
g T
oo
ls
Da
ta M
od
el
Eclipse RCP
Run-time/OSGi
SWT
JFace
WorkbenchP
refe
renc
es
Jobs
ICU
Com
man
ds
Reg
istr
y
Ad
d-o
n
L0001 - 2008-11-27
12
Organizing the Platform
The software of an Eclipse system is based on the following terms: Plug-ins – a plug-in is the basic unit of software Fragments – a fragment is an add-on to an existing plug-in with
additional functionality Features – a feature is a number of plug-ins that is distributed and
updated as a whole Applications – an application is a Java class that implements a specific
interface and is declared as such in the plug-in Products – a product is a set of features or plug-ins along with the
appropriate branding
L0001 - 2008-11-27
13
Extension Points
Describe additional functionality that could be integrated with the platform External tools extend the platform to bring specific functionality Java Development Tooling (JDT) and Plug-in Development Environment (PDE)
are external tools integrated with the platform Extension points are used to
Add an implementation for a generic feature Extend the workbench Extend common object factory
Advantages: Allows for late load and startup of plug-ins Provides a common “registry” for most extensions like views, perspectives,
commands, etc Disadvantages:
Makes it harder to understand flow of control ID Hell!
Extension points may have corresponding API interface Describes what should be provided in the extension
L0001 - 2008-11-27
14
Eclipse RCP
Run-time/OSGi
SWT
JFace
Workbench
Pre
fere
nces
Jobs
ICU
Com
man
ds
Reg
istr
y
The Role of Run-Time/OSGi
Dynamic module system for Java Solves many of the problems of big applications
Late activation of code Multiple versions of the same library
Eclipse is the reference implementation!
L0001 - 2008-11-27
15
Eclipse RCP
Run-time/OSGi
SWT
JFace
Workbench
Pre
fere
nces
Jobs
ICU
Com
man
ds
Reg
istr
y
Workbench
Represents the desktop development environment
It contains set of tools for resource management
It provides common way of navigating through the resources
Multiple workbenches can be opened at the same time in individual windows
PR0005 - 2008-04-10
16
Eclipse Development Model
Yearly releases Always released around 27. June – just before the start of the
Canadian holidays Many diverse and highly independent development teams
More than 25 countries involved in Eclipse 3.5 Galileo Many milestones and release candidates
5 monthly milestones (August to February) 4 release candidates (May and early June)
Still room for integration of other mayor projects Many projects are released with other release schedules
L0079 - 2009-08-27
17
Agenda
The Basic Plug-In How to build a basic Eclipse plug-in and get it included in Eclipse IDE
L0079 - 2009-08-27
18
Show and Tell
You will be shown how to create a new plug-in with A new perspective A new view A new command for the view
The new plug-in will be included in Eclipse
If you need to do this again, have a look at the two tutorials listed in the last slides
L0036 - 2008-11-23
19
Basic Eclipse UI Information Model
Workbench Window
Workbench Page
Editors Views
PerspectiveTop-level menu
Top-level toolbar
Status line
Perspective switcher
Drop-down menuLocal toolbar
Workbench
0..n
1..n
0..n0..n
L0039 - 2009-08-27
20
Lab Exercise
Create 4 views altogether Add the views to the perspective
The way to position views in a perspective have not be discussed in details, but…
Add the Help→About command to one of the views
L0079 - 2009-08-27
21
Agenda
What is a plug-in? What makes up a plug-in? How are they managed and developed?
L0016 - 2008-11-10
22
What is an Eclipse Plug-in
A plug-in is the smallest functionality that is managed in the Eclipse platform
Plug-ins are described via a number of configuration files Plug-ins have different forms under development and runtime Plug-ins are sometimes deployed individually
If you need update support, plug-ins must always be deployed as parts of a feature
A fragment has the same structure as a plug-in with very few changes
L0016 - 2008-11-10
23
Runtime Files of a Plug-in
OSGi files META-INF/MANIFEST.MF – description of OSGi bundle .options – options for this specific plug-in
General plug-in files plugin.xml and fragment.xml – description of extension points and
extensions of a plug-in plugin.properties and fragment.properties – localized strings for
the previous files
L0016 - 2008-11-10
24
Development Time Files of a Plug-in
.project – basic description of Eclipse project .classpath – the Java class path for a Java Eclipse project (and thus also
a PDE project) .settings – preference store for project level preferences – includes all
property settings for the project *.product – product declaration files build.properties – build information for Ant with content of the
resulting jar files for the project *.exsd – extension point declaration files
L0016 - 2008-11-10
25
MANIFEST.MF File
The OSGi manifest file describes the identify of the plug-in and the dependencies on other plug-ins
Manifest files are very seldom edited directly!
Manifest-Version: 1.0Bundle-ManifestVersion: 2Bundle-Name: %pluginNameBundle-SymbolicName: com.rcpcompany.training.cm33.core; singleton:=trueBundle-Version: 2.1.0Bundle-ClassPath: .Bundle-Vendor: %providerNameBundle-Localization: pluginBundle-RequiredExecutionEnvironment: J2SE-1.5Export-Package: com.rcpcompany.training.cm33.core, com.rcpcompany.training.cm33.core.utilRequire-Bundle: org.eclipse.core.runtime, org.eclipse.emf.ecore;visibility:=reexportBundle-ActivationPolicy: lazy
L0016 - 2008-11-10
26
plugin.xml File
plugin.xml describes extension points and extensions<extension point="org.eclipse.ui.commands">
<commandid="com.rcpcompany.demo.menu33.commands.HelloWorld"name=”&Sample Action” />
</extension><extension point="org.eclipse.ui.commandImages">
<imagecommandId="com.rcpcompany.demo.menu33.commands.HelloWorld"icon="icons/sample.gif” />
</extension><extension point="org.eclipse.ui.handlers">
<handlerclass="demo.actions.SampleHandler"commandId="com.rcpcompany.demo.menu33.commands.HelloWorld” />
</extension><extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:org.eclipse.ui.main.menu"><menu
id="sampleMenu"label="Sample Menu"mnemonic="M">
<commandcommandId="com.rcpcompany.demo.menu33.commands.HelloWorld"id="com.rcpcompany.demo.menu33.commands.HelloWorld.mc.sampleMenu” />
</menu></menuContribution>
</extension>
L0016 - 2008-11-10
27
Plug-in Editor
Double-click on the plugin.xml or MANIFEST.MF opens the editor Almost all plug-in details can be changed in the editor Overview page displays basic plug-in information
L0016 - 2008-11-10
28
Dependencies Page
Displays dependant plug-ins Created by tools when the plug-in type is chosen New dependences can be added
L0016 - 2008-11-10
29
Runtime Page
Displays runtime information such as plug-in classpath Populated by the tools based on inputs from wizards Additional libraries can be added to the classpath
L0016 - 2008-11-10
30
Extensions Page
Displays plug-in extensions Created by the tool based on the plug-in type Extensions can be added
L0016 - 2008-11-10
31
Extension Points Page
Displays plug-in extension points This example is taken from the org.eclipse.ui plug-in
L0016 - 2008-11-10
32
Build and build.properties Pages
Interface to the build.properties file specifies which .jar files to generate
Also describes which non-Java files that are part of the generated .jar file
L0079 - 2009-08-27
33
Agenda
The Standard Widget Toolkit - SWT How to develop the UI parts of an Eclipse plug-.in
L0079 - 2009-08-27
34
Eclipse User Interface Layers
4 Layers: The Eclipse Workbench
Overall look-n-feel JFace
Architecture-independent models SWT
Platform independent API yet rather close to the metal Native widgets
Platform dependent: Windows, Linux, Mac, Unix The “Eclipse User Interface Guidelines” governs the look-n-feel of the
workbench and JFace Consequently (nearly) all Eclipse RCP based applications look the
same! Use the SWT Bible “The Definitive Guide to SWT and JFace” by Robert
Harris and Rob Warner
Eclipse RCP
Run-time/OSGi
SWT
JFace
Workbench
Pre
fere
nces
Jobs
ICU
Com
man
ds
Reg
istr
y
L0079 - 2009-08-27
35
SWT and the Native Widgets
SWT is short for ”The Standard Widget Toolkit” SWT is a sub-project of the Eclipse project SWT has a common API on all target platforms – the implementation is
different Base plug-in org.eclipse.swt contains only MANIFEST.MF plus some
configuration files A set of platform specific fragments implements all of SWT – org.eclipse.swt.win32.win32.x86 for 32-bit Windows on x86 (not Vista look-n-feel)
SWT is a thin layer on top of the native widgets Windows Mac Motif GTK
SWT can easily be used stand-alone
L0079 - 2009-08-27
36
SWT on Different Platforms
PR0000 - Using Eclipse RCP in your Organization - 2007-09-04
37
Extended BrandingHere IBM Lotus Notes version 8
L0079 - 2009-08-27
38
Working with SWT
SWT API is not as regular as Swing The SWT site contains a large repository of “SWT Snippets” that
demonstrates most of the abilities of SWT To find leaks with graphical resources use sleak It is possible to integrate SWT and Swing to a very large degree
Though expect problems with shortcuts and focus management
L0079 - 2009-08-27
39
SWT Widgets
Basic Button, Combo, Composite, Group, Label, Link, List, Menu, ProgressBar, Shell, Slider, Scale, Spinner, TabFolder, Table, Text, ToolBar, and Tree
Advanced Browser, Canvas, CBanner, CCombo, CLabel, CoolBar, CTabFolder, DateTime, ExpandBar, GLCanvas, Sash, SashForm, ScrolledComposite, StyledText, SWT_AWT, TableCursor, and Tray
Other Sources – e.g. Nebula, Sourceforge.net FormattedText, Gallery, Grid, and many more
The C... versions of Label, Combo and TabFolder are emulated and should normally be avoided if possible
L0079 - 2009-08-27
40
SWT Widgets
L0079 - 2009-08-27
41
The Basic Widget Hierarchy
Widget
Control Menu Item
Button Label Composite List MenuItem TableItem TabItem
Canvas Combo Form OleSiteClient Table, …
L0079 - 2009-08-27
42
Using SWT Widgets
Common constructor form – e.g. new Text(parent, SWT.PASSWORD) The parent The style argument specifies the basic sub-function of the widget
Use Text controls for data values event when read-only, as this makes it possible to select and copy the value
L0079 - 2009-08-27
43
Using SWT Styles
Second argument of all widget constructions – e.g. new Text(parent, SWT.PASSWORD)
The most use styles are SWT.NONE – no style needed SWT.LEAD, SWT.CENTER, and SWT.TRAIL - the alignment of text in
labels, menus and buttons SWT.ARROW, SWT.CHECK, SWT.PUSH, SWT.RADIO, and SWT.TOGGLE - the
sub-type of a button SWT.PASSWORD - Text is used for password entry SWT.V_SCROLL, SWT.H_SCROLL, and SWT.NO_SCROLL – Table or Tree
has vertical, horizontal or no scroll bar (3.4)
Some special considerations regarding styles Some style arguments cannot be changed once specified in the
constructor (e.g. SWT.CHECK for a Button), whereas others can (e.g. SWT.LEAD for Label)
Some style arguments have different meaning for different widgets –e.g. SWT.MULTI for Table and Text
L0079 - 2009-08-27
44
SWT Layout Managers
The positioning and sizing of controls in a Composite (and subclasses) is performed using layout managers
SWT includes a rather complete set of standard layout managers FillLayout and RowLayout: layout is a single row or column GridLayout: layout in a grid with size constrains FormLayout: layout in canvas with size and edge-to-edge constrains Most GUI designer can handle these
A new layout manager can be created fairly easily created computeSize: computes the “natural” size of the Composite layout: lays out the controls of the Composite
public abstract class Layout {protected abstract Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache);protected abstract void layout(Composite composite, boolean flushCache);
}
L0079 - 2009-08-27
45
Using the Grid Layout (GridLayout)
Grid Layout is the most used layout manager in Eclipse It works by adding the child widgets to the cells in a grid
Widgets are added in sequence When using a Grid Layout, the parent uses the GridLayout and all
children use GridDatafinal Composite composite = new Composite(parent, SWT.NONE);final GridLayout gridLayout = new GridLayout(3, false);composite.setLayout(gridLayout);
label = new Label(composite, SWT.NONE);label.setText("Label");
text = new Text(composite, SWT.BORDER);text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));// …
L0079 - 2009-08-27
46
Using the Grid Data (GridData)
GridData specifies how a child widget is laid out in the parent grid A GridData holds the following primary information
Grab Excess Space (horizontal and vertical) – describes whether the grid column or row should expand to grad any excess space (defaults to no grab)
Span (horizontal and vertical) – describes the number of cells the widget should span (defaults to 1,1)
Alignment (horizontal and vertical) – placement of widget within the cells – one of SWT.BEGINNING, SWT.CENTER, SWT.END or SWT.FILL (defaults to BEGINNING, BEGINNING)
A GridData also contains information about indentation, minimum size and size hints Don’t use the two-argument constructor!
1,1 2,12,2
C,C F,C
E,E
Horizontal grabNo grab
L0079 - 2009-08-27
47
SWT Events
SWT events and listeners exist in two versions: A simple very light-weight version
One event format and listener interface A type-safe version
Multiple event formats and listener interfaces tailored to the specific use
The difference is illustrated in the following example
filter.addListener(SWT.KeyDown, new Listener() {public void handleEvent(Event event) {
if (event.type == SWT.KeyDown) {//...
}}
});
filter.addKeyListener(new KeyAdapter() {@Overridepublic void keyPressed(KeyEvent e) {
//...}
});
L0079 - 2009-08-27
48
SWT Events
Key KeyDown, KeyUp, HardKeyDown, HardKeyUp
Mouse MouseDown, MouseUp, MouseMove, MouseEnter, MouseExit, MouseDoubleClick, MouseHover, MouseWheel
Control Paint, Move, Resize, Dispose
Selection Selection, DefaultSelection
Focus FocusIn, FocusOut
Tree and Table Expand, Collapse, EraseItem, MeasureItem, PaintItem
Shell Iconify, Deiconify, Close, Activate, Deactivate
Menu Show, Hide, Arm, MenuDetect
Basic Controls Modify, Verify, SetData, Settings
Drag-n-Drop DragDetect
Misc Help
L0079 - 2009-08-27
49
Lab Exercise
Create a view with the following look using simple SWT controls GridLayout, GridData Label, Text, Button …addSelectionListener(…)
Another extra lab for the fast ones: add “stuff” to the lab to only allow “a” and “b” in the text field and to only allow more “a” than “b”! Use a Verify listener
public class View extends ViewPart {public void createPartControl(Composite parent) {
Composite top = new Composite(parent, SWT.NONE);// Add something here…
}
public void setFocus() {}
}
GridLayout with 2 columns
Label TextFILL aligned + grab
Buttonspans two columns, RIGHT alignedSelectionListener that prints current text of Text control
L0079 - 2009-08-27
50
More Information (Basic Plug-in)
“Eclipse Plugin Development Tutorial” http://www.eclipsepluginsite.com/
“Eclipse Plugin Development Tutorial” http://www.vogella.de/articles/EclipsePlugIn/article.html
Eclipse Resources http://www.eclipse.org/resources/
L0079 - 2009-08-27
51
More Information (SWT)
“Eclipse User Interface Guidelines: Version 2.1” http://www.eclipse.org/resources/resource.php?id=162
The Look-n-Feel guidelines for Eclipse – heavily influenced by the corresponding Microsoft Windows Look-n-Feel guidelines
SWT home http://www.eclipse.org/swt/
SWT versus Swing http://www.developer.com/java/other/article.php/2179061
“Using SwingRCP (instead of SWT) in RCP” http://www.eclipsezone.com/eclipse/forums/t104467.rhtml
A discussion of different ways to integrate Eclipse RCP and Swing “The Definitive Guide to SWT and JFace” by Robert Harris and Rob Warner
(ISBN: 978-1590593257) As it says – “The Definitive Guide…” – and needed due to the pure
javadoc of SWT “SWT Snippet” Repository
http://www.eclipse.org/swt/snippets/ A large repository of sample code for most uses of SWT!