Saturday, April 9, 2011

Eclipse RCP - Hide minimize / maximize buttons for editors and views

Abstract

Sometimes a user should not be allowed to maximize/minimize a view or editor. This article is about how achieve this.

Defining custom PresentationFactory

The main entry point to change the presentation of RCP editors and views is to define a custom PresentationFactory, which extends the the default presenetation factory. This presenetation factory then needs to be registered in the plugin.xml.

Registering custom presentation factory in plugin.xml


<extension point="org.eclipse.ui.presentationFactories">
  <factory class="org.acme.ExampleWorkbenchPresentationFactory"/>
</extension>

Changing editor presentation

In order to chage the editor presentation - here to hide the minmize / maximize buttons - we need to override the createEditorPresentation method in the presentation factory


@Override
public StackPresentation createEditorPresentation(final Composite parent,
        final IStackPresentationSite site) {
    final TabbedStackPresentation presentation = (TabbedStackPresentation)super.createViewPresentation(parent, site);
        
    presentation.showMinMax(false);
       
    return presentation;
}

The interesting code here is presentation.showMinMax(false).

Changing view presentation

It is the same code as for the editors - we need to override the method createViewPresentation in the presentation factory.

Using fixed layout

The above steps show, how to hide the minimize and maximize buttons of editors and views, but a double click on an editor/view will still cause the editor/view to be maximized. In order to avoid that, an implemenation of the interface IPerspectiveFactory should be provided as follows


public class MyPerspectiveFactory implements IPerspectiveFactory {
    @Override
    public void createInitialLayout(final IPageLayout layout) {
        layout.setFixed(isLayoutFixed());
    }
}

1 comment:

Anonymous said...

Thanks for this blog post - interesting. FYI showMinMax seems to be broken for the editor stack folder in 3.7.1 unfortunately.

You should follow me
on twitter