Eclipse Spot

StatusBar Development

StatusBar fragment plugin can be employed in an E4 RCP application by following a small number of steps which will be described here along with code snippets:

  1. Add a Window Trim - Bottom to the main window
  2. Add StatusBar category to the project target from the online repository
  3. Add StatusBar plugin to the application manifest
  4. Add StatusBar objects to the application code
  5. Hook StatusItems to events

Window Trim - Bottom

Using the Eclipse 4 model editor, add a "Window Trim - Bottom" to the main window:

E4 model editor

On the right is the "Window Trim" ID field, which must be set to au.com.cybersearch2.statusline.trimbar.

Add StatusBar to Target

The Target Platform refers to the plug-ins which your workspace will be built and run against. A Tycho build may use a project-specific Target Platform separate from the one employed by the plugin development environment. For each applicable target, add a new Software Site with address https://dl.bintray.com/cybersearch2/generic/Statusbar/V1.1.0. Two categories will appear for selection. Tick the StatusBar category to select plugins and, optionally, tick StatusBar (Sources).

Add StatusBar to manifest

Add to the project MANIFEST.MF dependencies statusbar v1.1.0 and control_factory v1.1.0:


 au.com.cybersearch2.statusbar;bundle-version="1.1.0",
 au.com.cybersearch2.control_factory;bundle-version="1.1.0"
              

Add StatusBar objects

Create StatusBar objects in the E4 Lifecycle postContextCreate method in the following order:

Code snippet for postContextCreate()


import au.com.cybersearch2.controls.ControlFactory;
import au.com.cybersearch2.statusbar.StatusBar;
import au.com.cybersearch2.statusbar.StatusItem;
import au.com.cybersearch2.statusbar.controls.ItemConfiguration;
...
    static ItemConfiguration ITEM_CONFIG = 
        new ItemConfiguration(null, "Starting...", 0);

    @PostContextCreate
    void postContextCreate(IEclipseContext workbenchContext) 
    {
        ControlFactory controlFactory =  new ControlFactory();
        workbenchContext.set(ControlFactory.class, controlFactory);
        StatusBar statusBar = new StatusBar();
        workbenchContext.set(StatusBar.class, statusBar);
        StatusItem statusItem = new StatusItem(ITEM_CONFIG, 0);
        statusBar.addStatusItem(statusItem);
          

This code places instances of ControlFactory and StatusBar in the Eclipse context. Then a StatusItem object is created and added to the StatusBar. The StatusItem constructor parameters:

  • Configuration - provides CLabel attributes, including text or image or both.
  • Index - determines position of item in status line, ordered from left to right and with a range starting at 0

The item in this code will be aligned on the left of the main window client area and display text "Starting...". The configuration width hint, (3rd parameter of ITEM_CONFIG constructor), is set to zero which causes the item width to be calculated according to the text being displayed.