Showing posts with label OSGi Platform. Show all posts
Showing posts with label OSGi Platform. Show all posts

2008-11-13

Managing the Layout of the Workbench in Eclipse RCP

Setting the layout of the Workbench in any Eclipse RCP application can be a daunting task if your application needs any control over the placement of views and editor area that is not directly exposed through the RCP interface.

But some techniques can be used to provide (relatively) more control over the layout by managing the perspective settings and hinting the view size.

In the perspective

In the class implementing IPerspectiveFactory (the class that implements the Perspective to the org.eclipse.ui.perspective extension point), you can:

Enable or disable the Editor area, if you are to design an Editor, this setting should be kept to true

layout.setEditorAreaVisible(true);

You can also use the Fixed Layout option, this removes he ability o maximize and minimize views and the editor area (through the min/max buttons and through the double clicking on the view title.

This keeps the ability to resize single views (as if they are included in Resize composites, but without the ability to reorder the views, or stack them or minimize them as fast views)

layout.setFixed(true);

The order of the views to be added decides who gets the full layout to take part of it and what views get the remaining of the layout to take further parts of it

Views

Views can be standard views, stand-alone views or fast views:

A stand-alone view is a special kind of view that cannot stack other views with it, and can optionally enable/disable the title bar
layout.addStandaloneView(MyOwnView.ID, true, IPageLayout.TOP, 1f, editorArea);

Standard view is a simple view in the Workbench that can be docked, stacked, minimized, maximized or detached inside the Workbench window

layout.addView(SampleView.ID, IPageLayout.LEFT, 0.5f, editorArea);

Fast views are shortcuts to the actual views put in the toolbar at the bottom of the Workbench window and shares the status bar if visible

layout.addFastView(SampleView.ID, IPageLayout.DEFAULT_VIEW_RATIO);

Views and hinting its size (in Eclipse 3.4 and upwards)

By implementing the ISizeProvider Interface in the ViewPart class that is creating the view, you can get the view to set its minimum and maximum size, given that the view doesn't get docked into other views (which can be easily made by using stand-alone views), the simplest implementation would be:

@Override public int computePreferredSize(boolean width,
int availableParallel, int availablePerpendicular, int preferredResult) {
return width ? 100 : 110;
}
@Override public int getSizeFlags(boolean width) {
return (SWT.MIN | SWT.MAX);
}

2008-09-04

The Eclipse RCP - 1 - Rich Client Platform

For the full tutorial, see http://www.vogella.de/articles/RichClientPlatform/article.html

The Platform
The Eclipse RCP is a platform, where no functionality is implemented in it; its sole purpose is to manage the plug-ins, where everything in the program is done using the plug-ins.
The plug-ins implement everything, from the menu bar, to the status bar, to the main toolbar, to the views (or panels), to the Editors (which may not be editing anything, but they are the main focus of the program), to auxiliary functionality like software automatic update and help and the management of long-running background operations; these plug-ins are the heart-and-soul of any Eclipse RCP-based program.
The basis for this architecture is the runtime environment of Eclipse which is based on the OSGi Alliance. Eclipse used the OSGi reference implementation Equinox to run upon. The Plug-in concept of Eclipse is the same as the bundle concept of OSGi.

Minimum Requirements
As a minimum, a RCP application requires:
  • Main program or Application (org.eclipse.core.runtime.applications extension point)
  • Workbench Advisor (invoked from the Application handler, it sets the default Perspective, invokes WorkbenchWindowAdvisor which configures the default Main window state and subsequently invokes ActionBarAdvisor, which in turn provides one of the ways to configure the Action Bar or the main menu and Cool Bar or the main toolbar)
  • A Perspective (org.eclipse.ui.perspectives extension point)
  • A View (org.eclipse.ui.views extension point, views are technically not required for a RCP application, but they are the base interface element)
The RCP application depends on 2 main plug-ins:
  • org.eclipse.core.runtime
  • org.eclipse.ui

Plug-ins Architecture
The RCP architecture is based on the concept of extension-points, which a plug-in provides so that any other plug-ins can contribute functionality to it in the form of extensions, e.g. you can easily provide your menu items in the Action Bar (an extension point provided by the org.eclipse.ui plug-in) by implementing extensions that connect to the org.eclipse.ui.menus extension point and provide their own implementation. In general an extension point can be used several times (either by the same plug-in or by other plug-ins).
The plug-in architecture is based on 2 configuration files (or manifests) that describe the behavior of the plug-in, "MANIFEST.MF" and "plugin.xml", by double clicking on any of them, Eclipse provides a graphical editor of the files contents.
The plug-in manifest ties all the code and the resources together, the OSGi bundle manifest is stored in "MANIFEST.MF", while the Eclipse specific parts are stored in "plugin.xml".