org.eclipse.ui.perspectives

We've already seen some ways the workbench allows the user to control the appearance of plug-in functionality. Views can be hidden or shown using the Window->Show View menu. Action sets can be hidden or shown using the Window->Customize Perspective... menu. These features help the user organize the workbench.

Perspectives

Perspectives provide an additional layer of organization inside a workbench window. Users can switch between perspectives as they move across tasks. A perspective defines a collection of views, a layout for the views, and the visible action sets that should be used when the user first opens the perspective.

The platform itself defines one perspective, the Resource perspective. Other platform plug-ins, such as the help system and the Java tooling, define additional perspectives. Your plug-in can define its own perspective by contributing to the org.eclipse.ui.perspectives extension point.

The specification of the perspective in the plugin.xml is straightforward. The following markup is used by the workbench in defining its own resource perspective.

<extension
         point="org.eclipse.ui.perspectives">
      <perspective
            name="%Perspective.resourcePerspective"
            icon="icons/full/cview16/resource_persp.gif"
            class="org.eclipse.ui.internal.ResourcePerspective"
            id="org.eclipse.ui.resourcePerspective">
      </perspective>
   </extension>

A plug-in must supply an id and name for the perspective, along with the name of the class that implements the perspective. An icon can also be specified. The perspective class should implement IPerspectiveFactory.

We can see from the markup that the real work must be happening in the code. The interface for the perspective factory is straightforward. Implementors of IPerspectiveFactory are expected to configure an IPageLayout with information that describes the perspective and its perspective page layout.

Workbench part layout

One of the main jobs of an IPageLayout is to describe the placement of the editor and the views in the workbench window. Note that these layouts are different than the Layout class in SWT. Although IPageLayout and Layout solve a similar problem (sizing and positioning widgets within a larger area), you do not have to understand SWT layouts in order to supply a perspective page layout.

A perspective page layout is initialized with one area for displaying an editor. The perspective factory is responsible for adding additional views relative to the editor. Views are added to the layout relative to (top, bottom, left, right) another part. Placeholders (empty space) can also be added for items that are not initially shown.

To organize related views and reduce clutter, you can use IFolderLayout to group views into tabbed folders. For example, the Resource perspective places the resource navigator inside a folder at the top left corner of the workbench.  Placeholders are commonly used with folder layouts. The Resource perspective defines a placeholder for the bookmarks view in the same folder as the resource navigator. If the user shows the bookmarks view, it will appear in the same folder with the navigator, with a tab for each view.

IPageLayout also allows you to define the available actions and shortcuts inside a perspective.  

Copyright IBM Corp. and others 2000,2002.