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);
}

No comments: