Perspective Change Selections

Perspective Listener

It is possible to programmatically change a workbench perspective, and it is also possible to listen for perspective change events so that your view can be made aware of when a particular perspective is chosen to be displayed.

The first of these two cases is very simple and is explained in full at http://wiki.eclipse.org/index.php/FAQ_How_do_I_show_a_given_perspective%3F

The second case requires you to implement the IPerspectiveListener interface. The interface is very simple and has the following methods:

IPerspectiveListener
/**
     * Notifies this listener that a perspective in the given page
     * has been activated.
     *
     * @param page the page containing the activated perspective
     * @param perspective the perspective descriptor that was activated
     * @see IWorkbenchPage#setPerspective
     */
    public void perspectiveActivated(IWorkbenchPage page,
            IPerspectiveDescriptor perspective);

    /**
     * 
     * This method is currently not used!!!!
     * 
     * Notifies this listener that a perspective has changed in some way 
     * (for example, editor area hidden, perspective reset,
     * view show/hide, editor open/close, etc).
     *
     * @param page the page containing the affected perspective
     * @param perspective the perspective descriptor
     * @param changeId one of the <code>CHANGE_*</code> constants on IWorkbenchPage
     */
    public void perspectiveChanged(IWorkbenchPage page,
            IPerspectiveDescriptor perspective, String changeId);

Once you've implemented the interface, you will need to register the listener with the WorkbenchWindow. You can access the workbench window via the ViewSite, i.e. ViewSite.getWorkbenchPage().getWorkbenchWindow(), or through the static helper method PlatformUI.getWorkbench().getWorkbenchWindow()

Note: At the time of writing this, the second method is currently not implemented in the workbench.

Labels

 
(None)