| Free tutorials for Java, Eclipse and Web programming |
Perspectives group together and organize UI element that relate to a specific task.
Eclipse RCP allows you to add easily perspectives to your application. The following presents an example
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". The name is the name under which the perspective will be visible. 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 perspectivetest;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class PerspectiveFactoryNew implements IPerspectiveFactory {
@Override
public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
layout.setEditorAreaVisible(true);
layout.setFixed(false);
layout.addView(View.ID, IPageLayout.LEFT, 0.33f, editorArea);
}
}
Now the perspective is define but not yet reachable view the application.
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.

You can re-use the Eclipse perspective switch in a menu via the following standard command "org.eclipse.ui.perspectives.showPerspective".
See Using Eclipse Commands for details on using Eclipse standard commands.