How to fix your perspective in Eclipse RCP (and potentially a bug…)

A common requirement for Eclipse RCP applications is that the perspective should be fixed so that the user cannot change the layout, e.g. layout parts cannot be moved or zoomed, and the initial set of views cannot be closed.

According to the Javadoc this behavior should happen if the perspective is set to fixed. There seems to be bug in the implementation or in the Javadoc as the position in Perspective.java is important. The following works:



public void createInitialLayout(IPageLayout layout) {
	layout.setEditorAreaVisible(true);
        layout.setFixed(true);
	layout.addView("de.vogella.rcp.fixedperspective.view",
				IPageLayout.LEFT, 0.5f, layout.getEditorArea());
	layout.addView("de.vogella.rcp.fixedperspective.view2",
				IPageLayout.RIGHT, 0.5f, layout.getEditorArea());

}
	

The following does not fix the perspective:

public void createInitialLayout(IPageLayout layout) {
        layout.setEditorAreaVisible(false);
        // does not work
	layout.addView("de.vogella.rcp.fixedperspective.view",
				IPageLayout.LEFT, 0.5f, layout.getEditorArea());
	layout.addView("de.vogella.rcp.fixedperspective.view2",
				IPageLayout.RIGHT, 0.5f, layout.getEditorArea());
	layout.setFixed(true);
}

Does anyone know if that is a bug or a feature?

Another question which sometimes comes up is how to fix a specific view which is added via the Perspective.java. This is possible by getting IViewLayout from the layout.

public void createInitialLayout(IPageLayout layout) {
		layout.addView("com.example.view.view", IPageLayout.LEFT, 0.95f, layout.getEditorArea());
		IViewLayout viewLayout = layout.getViewLayout("com.example.view.view");
		viewLayout.setCloseable(false);
		viewLayout.setMoveable(false);
		layout.setEditorAreaVisible(true);
	}

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse. Bookmark the permalink.

5 Responses to How to fix your perspective in Eclipse RCP (and potentially a bug…)

  1. Gerd says:

    Why do you use the parameter false in
    layout.setFixed(false);
    ?

    Gerd

  2. Uwe Peuker says:

    layout.setFixed(false): “does not fix” the perspective. That’s the expected behaviour? I don’t understand your request?

  3. Lars says:

    You use two different calls of setFixed: the working with “true” and the second with “false”.
    Could it be that simple?

  4. Lars Vogel says:

    setFixed(true) was a typo. Sorry for this. Corrected.

  5. Lars Vogel says:

    Ups, looks like I opened myself a bug for this a while ago. ;-) https://bugs.eclipse.org/bugs/show_bug.cgi?id=331402

    Thanks to Remy Suen to letting me know.

Comments are closed.