TWiki> Public Web>DpHipe>DpHipePerspectives (revision 8)EditAttach

Creating a Perspective

If you think that a set of (new) views should be presented in standard layout, you can do so by creating a new perspective. Such a perspective defines how these views are layed out in tabs and split panes. This section briefly explains how to contribute a new perspective.

See also the overview page.

Basic Steps

HIPE Perspective menu
The aim is that your contribution is automatically picked up by the infrastructure, such that your perspective is added to the perspective menu, as shown in the picture on the right.

To make this happen, you will have to:

  • Implement the Perspective interface.
  • Register your implementation to the Extension Registry in the init.py.

For you convenience an abstract implementation exists (AbstractPerspective); it allows you to concentrate on implementing one method only:

    public abstract class AbstractPerspective implements Perspective {
    
	public abstract SitePart doLayout(SitePartBuilder builder);
    
    }


Construction items

SiteParts are the building blocks of a perspective. We distinct the following flavors:
  • ViewPart - normal views
  • EditorArea - the editor area
  • SplitPart - two windows with a movable split
  • TabPart - n windows organized into tabs

Access to the views, editor area or creation of the tab and split layout containers are all through the SitePartBuilder:

public interface SitePartBuilder {
    ViewPartManager getViewManager();    
    TabbedPart buildTabs(SitePart... parts);
    SplitPart buildSplit(float split, boolean horizontal, SitePart lhs, SitePart rhs);    
}

Example

The above is explained by an example in which we are going to create a perspective with a familiar layout and register it to HIPE.

Implementation

The implementation below reflects a classic JIDE layout. My JIDE implementation

public final class MyJidePerspective extends AbstractPerspective {

    @Override
    public SitePart doLayout(SitePartBuilder builder) {
        // get pointers to the views and editor area
	ViewPartManager vm = builder.getViewManager();

	SitePart editors = vm.getEditorArea();
	SitePart console = vm.getViewByTitle("Console");
	SitePart history = vm.getViewByTitle("History");

	// actual layout:
	boolean vert = false;
	boolean hori = true;

        SitePart bottom = builder.buildSplit(0.7f, hori, console, history);
	SitePart window = builder.buildSplit(0.7f, vert, editors, bottom);

	return window;
    }

}

The above code is divided into three stages:

  • Getting hold of the views you are interested in. This is done by asking the builder for the view manager. Then you grab existing views either by title or by a view's unique identifier.
  • Creation of split panes that hold the views. First we create the bottom part (console and history), and then split the window into a top part (being the editor area) and the bottom part we just created.
  • The last part is returning the created site part.


Registry

The following snippet, could then go into your __init__.py:

REGISTRY.register(PERSPECTIVE, Extension(
         "site.perspective.myjide",                   # a unique ID
         "resides.in.java.package.MyJidePerspective", # the above implementation
         "My JIDE",                                   # how it should be called in the menu
         None                                         # possible icon (none here)
         ))
See also the Extension Registry documentation for more details.

Edit | Attach | Watch | Print version | History: r21 | r10 < r9 < r8 < r7 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r8 - 2008-08-19 - JaimeSaiz
 
This site is powered by the TWiki collaboration platform Powered by Perl