Menu

Eclipse Rich Client Platform (RCP)

Gregory M Lyon Dasha

Eclipse get its power from its plug-ins. The Eclipse framework consists of plug-ins like SWT, JFace, and OSGi. By adding a few more specific plug-ins and some original code, one can create a User Interface (UI). Eclipse uses plug-ins or bundles for grouping, delivering, and managing code.

The eclipse mechanism is declarative: plug-ins are connected without loading any of their code/data greatly reducing code bulk and startup time. RCP has the ability to do more than UI, such as providing server capabilities. Rich client replaced simple clients with powerful features for ease of use such as:

  • Extensibilty
  • Varied execution environments
  • Intelligent installation and updates
  • 3rd party libraries and plug-ins
  • Native user experience
  • Portability
  • Disconnected operation
  • Drag and drop
  • System clipboard
  • Customization

Table of Contents

Components of the RCP

User Interface (UI): Action sets, editors, perspectives, views, and the workbench are parts of the Graphical User Interface (GUI), while anything else such as sound is part of the more broad UI.

UI workbench: Contains windows, perspectives, actions, views and editors; adds presentation and coordination to JFace.

Perspective: visual container for a set of views and content editors. Views and editors cannot be mixed into the same stack.

Editor: Primary focus of attention, such as a text IO. Shared between perspectives. Must have title. Need an IEditorInput before they can be opened. Contributes to main toolbar & menu.

View: Supporting information for a given task; output needed for user decision. A title is not needed. Can be detached from a workbench window. Contributes to local toolbar & menu.

Stand-alone view: Hides the title area and prevent the view from being altered.

TreeViewer: Display tree structures using providers.

Content provider: Supply the tree nodes.

Label Provider: Produces human readable names and images for the nodes.

JFace: Provides Actions, Viewers, Wizards, and Databinding; essentially connecting the graphical components to the real underlying actions.

Standard Widget Toolkit (SWT): Contains widgets; stand alone low level graphics library that can be used outside RCP, allows portable and native experience.

Equinox: Contains extensions, applications, products; is an implementation of the OSGi framework specification, allowing applications to implement bundles

OSGi: Provides Bundles (normal jar files), and Services (connecting bundles dynamically); knits together the installed plug-ins to allow them to collaborate.

Manifest.mf : This is the OSGi bundle manifest - The execution specification; plug-in configuration (OSGi).

plugin.xml : This is the Eclipse extension manifest – The extension specification; plug-in configuration (Eclipse Equinox).

.product: The build.

Product: Application with branding, splash, preferences and configuration files, something the user can understand and run.

Manipulating the GUI

Form: A collection of widgets, their form styles, etc.

Composite: Instances of this class control all other controls such as the layout and text of buttons.

IApplication: Interface that represents the executable entry points into an application.

Application: Class that controls all aspects of application's execution, acting as the main routine. (All it does is create a Workbench and attach another class called a Workbench Advisor to it)

Activator: controls the plug-in life cycle

Actions: Given a reference to the container in which they are placed allowing them to query for or access information. Actions can be placed in views, editors, or toolbars and can be controlled by mouse clicks, keyboard strokes or other user input.

Action bar: Any menu, toolbar, status bar, etc.

ApplicationActionBar: Class responsible for creating, adding, and disposing of the actions added to a workbench window.

ApplicationWorkbenchAdvisor: Class creates the window advisor and specifies the perspective id for the initial window.

ApplicationWorkbenchWindowAdvisor: Class determines properties of the window such as its initial size, position, toolbars, or name on the header.

(SomeAction): Any class created to give a mechanism (or mechanisms) an action (or actions).

ViewPart: Class to be subclassed to define new views.

View: Creates the GUI; create layouts, buttons, banners, scroll bars, etc.

Perspective: a mechanism for arranging views and editors, supporting scalable UI's.

There is only one Workbench but there can be many WorkBenchWindows

The Advisor Classes: These

WorkbenchAdvisor: creates the WorkbenchWindowAdvisor, and specifies the perspective id for the initial window.

WorkbenchWindowAdvisor: defines initial settings (position, size) , creation, destruction of windows

ActionBarAdvisor: instantiated by WorkbenchWindowAdvisor createActionBarAdvisor(); creates actions in a window. Controls what appears in the toolbar (Coolbar), menu bar, & status line. (Focal point of customization in RCP) ActionBarAdvisor is responsible for creating, adding, and disposing of the actions added to a workbench window. Each window will be populated with new actions.

ApplicationWorkbenchWindowAdvisor sets window features , size, and position.

ICommandIds is the interface defining the application's command Ids. Key bindings can be defined for specific commands. To associate an action with a command, use Iaction.setActionDefinitionId(commandId).

Layout

This example will show the use of GridLayout to organize components, other layouts such as TableWrapLayout can be used for org.eclipse.ui.forms components.

GridLayout is a blue print which describes the layout of controls on a composite. This works with any SWT components, the example below chooses to to use buttons for convenience.

GridData is the attribute of the control, describing its span, indentation, margin etc for each gird(cell).

This example code breakdown the usage of each piece:

//Creates an instance of Display which is the

Display display = new Display();

//Creates a instance of Shell, in display, which is the

Shell shell = new Shell(display);

//Creates an instance of GridLayout which controls the layout of the controls on 
//the composite

GridLayout gridLayout = new GridLayout();

//Determines the number of columns in a table configuration for the ___ added, 
//where once the given number is reached the next ___ will go start at the next row

gridLayout.numColumns = 3;

//Sets the instance gridLayout on the instance shell

shell.setLayout(gridLayout);

//Create one button, the default button size is to allow just enough room for the 
//given text, but this can be changed withHintsshown later.

new Button(shell, SWT.PUSH).setText("Button");

//Forces each column to be same width, the default is false

gridLayout.makeColumnsEqualWidth = true;

//To set a widget's GridData object, you use the setLayoutData

GridData gridData = new GridData(); 
gridData.horizontalAlignment = GridData.FILL;

//This is one instance of GridData, do not reuse any instance of GridData

gridData.grabExcessHorizontalSpace = true;

//The default horizontalAlignment is BEGINNING, while verticalAlignment is CENTER. 
//BEGINNING refers to being leftward or upward in a cell, CENTER is toward the 
//center, END is rightward or downward, and FILL occupies the the entirety of the 
//cell.

//Button is set leftward, downward, and to occupy all the horizontal space in the 
//cell while maintaining a constant height

gridData.horizontalAlignment = SWT.BEGINNING 
gridData.verticalAlignment = SWT.END 
gridData.horizontalAlignment = SWT.FILL

//sets indent 4 pixels

gridData.horizontalIndent = 4;

//Expands across one cell

gridData.horizontalAlignment = GridData.FILL;

//Makes two cells into one

gridData.horizontalSpan = 2;

//Fills window as it resizes. If more than one widget is trying to grab the same 
//space, then the excess space is shared evenly among the grabbing widgets

gridData.grabExcessVerticalSpace = true;

//These hints set the initial size of the button to be 70 pixels wide and 40 tall.

gridData.widthHint = 70; 
gridData.heightHint = 40;

//This sets the window to fit the given parts such that they have enough room for 
//each component to show correctly, giving leftover room to the last component

shell.pack();

//Opens the window

shell.open();

while (!shell.isDisposed()) { 
if (!display.readAndDispatch()) display.sleep(); 
}

NOTE: To write the gridData in a more compact notation you can pass arguments to gridData as you instantiate it:

GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);

SWT

A widget in SWT is created by

  1. Specifying parent (the container that the widget is created inside of)

  2. Specifying style (any constant from the SWT class such as SWT.PUSH, SWT.BORDER, SWT.LEFT, etc)

If more than one style is desired – separate them out with a “|” bitwise operator (e.g. SWT.MULTI | SWT.V_SCROLL creates a multiline text area that has a vertical scrollbar). If no specific style is desired – use SWT.NONE.

Widgets that can be created:

Display: the entire frame of the window including header. The single point of contact for all UI capabilities of SWT; such as running the event loop, inter-thread communication, timers, fonts, and colors.

Shell: the window excluding the header that holds all widgets and displays GUI elements

Composite:

Buttons: A box that can be selected by mouse-click and implements listeners; provides actions new Button(shell, SWT.PUSH | SWT.FLAT).setText("Flat Push Button");

new Button(shell, SWT.CHECK).setText("Check Button"); 
new Button(shell, SWT.TOGGLE).setText("Toggle Button"); 
new Button(shell, SWT.RADIO).setText("Radio Button");

Labels: Plain text for subtitles, and separators

Text: Character fields

new Text(shell, SWT.NONE).setText("ugly text field"); 
new Text(shell, SWT.BORDER); // regular textfield 
new Text(shell, SWT.PASSWORD | SWT.BORDER).setText("password"); 
new Text(shell, SWT.READ_ONLY | SWT.BORDER).setText("Can't type inside"); 
new Text(shell, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP |SWT.BORDER).setText("\n\n\n");

List: Holds an array of strings displayed in rows and columns

Combo: Drop downs, text entry with attached list

Group: Creates a box around objects, acting essentially as a “subshell”

Browser: Set the URL and Display; access the web

Layout: Organizational tool for widgets. It sets the composite’s layout by calling setLayout().

FillLayout: Places all widgets in either a single column or a single row depending on if SWT.VERTICAL or SWT.HORIZONTAL is used

RowLayout: Same as FillLayout, except doesn’t force all widgets to be the same size, can wrap to a new row or column if it runs out of space.

StackLayout: All widgets are stacked on top of each other and you can only see one at a time.

GridLayout: Powerful grid that uses GridData to layout the buttons

FormLayout: Provides maximum flexibility; the basic idea is that you layout the widgets relative to each other or to the enclosing composite

Event: SWT widgets can listen for events to happen. Attach a listener (an interface defining when certain behaviors happen) to the widget. An Adapter is a class that implements the interface and from which you can just extend and override the method you are interested in.

  • FocusListener/FocusAdapter – listens for focus gained and focus lost events
  • KeyListener/KeyAdapter – listens for key releases and key presses
  • ModifyListener(only has 1 method) – listens for text modifications
  • VerifyListener – listens for (and potentially intercepts) text modifications
  • MouseListener/MouseAdapter – listens for mouse button presses
  • SelectionListener/SelectionAdapter – listens for selection events (similar to ActionListener in Swing)

Threading

When a widget is created in your main thread, a separate thread does the labor. Then, the widget is updated with the result of the second thread’s computation.

In the second thread, the new value must be applied, using widget.setValue(newValue), and a mode of synchronization.

syncExec(Runnable) 
asyncExec(Runnable)

General Styles

pack: Pushes widgets together such that they all are given enough room to display their content; giving any extra space to the last widget

Building Wizards

Miscellaneous

Java Runtime Environment: A subset of the Java Development Kit (JDK) for end-users and developers who want to redistribute the runtime environment alone. The Java runtime environment consists of the Java virtual machine, the Java core classes, and supporting files.

Launch Configuration: Manage name, data allocation, which program to run, choose a JRE and command line arguments.

Eclipse provides forms (define these) which allow you to simply input images from your workspace into the RCP as icon pictures, headers, and more (.gif images are required for icons and pictures).


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.