RSS

Search Engine

Monday, June 14, 2010

Perspectives

Perspectives group together and organize UI element that relate to a specific task. Eclipse RCP allows you to add perspectives to your application. The following presents an example.

14.1. Adding a perspective to your application

Create a new RCP project called "de.vogella.rcp.intro.perspective". Use the "RCP application with a view" as a template.

In plugin.xml add a new perspective extension point.

Give the perspective the id "de.vogella.rcp.intro.perspective.perspective" and the name "Perspective". Change the class name to "de.vogella.rcp.intro.perspective.Perspective".

Click on the "class*" link to create the class.

The method createInitialLayout() in your new class is responsible for creating the new perspective. We re-use the existing view in the coding.

    package de.vogella.rcp.intro.perspective;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
layout.setEditorAreaVisible(false);
layout.setFixed(true);

layout.addStandaloneView(View.ID, false, IPageLayout.LEFT, 1.0f, editorArea);
}

}

The perspective is defined but not yet reachable via the application.

14.2. Select the perspective

14.2.1. Select perspective via the toolbar / coolbar

You can activate the switch between perspectives the ApplicationWorkbenchWindowAdvisor in method preWindowOpen() with configurer.setShowPerspectiveBar(true);

     
package perspectivetest;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

public ApplicationWorkbenchWindowAdvisor(
IWorkbenchWindowConfigurer configurer) {
super(configurer);
}

public ActionBarAdvisor createActionBarAdvisor(
IActionBarConfigurer configurer) {
return new ApplicationActionBarAdvisor(configurer);
}

public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("RCP Application");
configurer.setShowPerspectiveBar(true);
// Set the preference toolbar to the left place
// If other menus exists then this will be on the left of them
IPreferenceStore apiStore = PlatformUI.getPreferenceStore();
apiStore.setValue(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR,
"TOP_LEFT");
}
}

You should now be able to select your perspective interactively.

14.2.2. Select perspective via the menu

You can re-use the Eclipse perspective switch in a menu via the following standard command "org.eclipse.ui.perspectives.showPerspective".

0 comments:

Post a Comment