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

Creating a View

You can develop new views and add them to the work-bench of HIPE. This section briefly explains how to do this.


Basic Steps

HIPE View menu

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

To make this happen, you will have to:

  • Implement the Viewable interface by sub-classing any %JCOMPONENT% implementation.
  • Register your implementation to the Extension Registry in the init.py file of your sub-system.

The Viewable interface is a light-weight interface that provides the contents of a View. Your implementation should take the following into account:

  • The implementation must be an extension of a swing component
  • The implementation requires a default, but light-weight constructor. Actual construction of a popup menu, a view menu, or a tool bar or contributions to the main tool bar or main menu (or combinations of them) should be done in the init(ViewPart part) method.
  • In principle only one instance of a view should exist.
  • The ID returned by your implementation must be unique

Example

Implementation

public class MyView extends SomeSwingComponent implements Viewable {
    private ViewPart _part;

    // Viewable implementation
    public MyView() {}
    public void   dispose()  {}
    public Icon   getIcon()  { return getPart().getIcon(); }
    public String getId()    { return getPart().getId();   }
    public String getTitle() { return getPart().getTitle(); }
    public void   init(ViewPart part) {
	_part = part;
	makeActions();
    }

    public ViewPart getPart() { return _part; }
    
    private void makeActions() {
	// create tool bars, menus and other stuff
    }
}

Registry

The following snippet registers the above view within your package's init.py:

REGISTRY.register(VIEWABLE, Extension(
                 "site.view.myview",
                 "resides.in.java.package.MyView",
                 "My View",
                 "resides/in/java/package/myview.gif"))

See also the Extension Registry documentation for more details.

Adding features

Trigger events

Your viewable may want to trigger site events which might be interesting to other views. The ViewPart interface that is passed on through the init method gives you the means of triggering site events:
    private void someMethod() {
        :
        getPart().getEventHandler().trigger(aSiteEvent)
        :
    }

Receiving events

Your viewable may want to listen to site events produced by other views. For that you have to implement the SiteEventListener interface and inform the event handler that you are interested in one or more event types, e.g.:
public class MyView extends SomeSwingComponent implements Viewable, SiteEventListener {
   
    public void init(ViewPart part) {
	:
        part.getEventHandler().addEventListener(SelectionEvent.class, this);
	:
    }


   public void selectionChanged(SiteEvent event) {
       // we *know* that we only receive a SelectionEvent, so:
       SelectionEvent selection = (SelectionEvent)event;
       :
   }

}

Menus, toolbars and other features

You can learn about adding actions to your view, and more, following this link.

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