01/05/2009

Programming the Sidebar using Java

Category   
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 

This blog will show how to programmatically control the Lotus Notes 8 Sidebar using Java.

There is a demo plug-in called com.domiclipse.demo.sidebar which can be found in the CVS. The demo adds a Sidebar Demo menu entry with three actions that will show info about the sidebar, toggle the state of the sidebar and toggle the 'Day-At-A-Glance' panel.

The starting point is the IWorkbenchWindowWithShelfPages which we get by adapting the Eclipse Workbench.

        IAdapterManager adapterMgr = Platform.getAdapterManager();
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow() ;
        IWorkbenchWindowWithShelfPages windowWithShelfPages = (IWorkbenchWindowWithShelfPages)adapterMgr.getAdapter(window, IWorkbenchWindowWithShelfPages.class);

Once we have the workbench we can get a handle on any of the Sidebars or ShelfPages as they are known. The Notes client has left and right sidebars.

        ShelfPage shelfPage = windowWithShelfPages.getShelfPage(IWorkbenchWindowWithShelfPages.RIGHT);

A ShelfPage can be displayed in three ways, thin, expanded or collapsed. This is controlled using the setMode() method.

        if ( shelfPage.getMode() == ShelfPage.COLLAPSED ) {
                shelfPage.setMode( ShelfPage.EXPANDED) ;
        }

Now that we have a handle on the ShelfPage we can see which sidebar panels are currently active.

        IShelfViewReference[] viewReferences = shelfPage.getShelfViewReferences() ;
                               
        System.out.println("There are " + viewReferences.length + " views in the Sidebar.\n\n" );                                
        for ( int x = 0 ; x < viewReferences.length ; x++ ) {
                System.out.println( viewReferences[x].getTitle() + " (" + viewReferences[x].getId() + ")\n" ) ;
        }

If we know the id of a particular sidebar panel it can be opened or closed. The example below toggles the Day-At-A-Glance panel.

        String PANEL_ID = "com.ibm.workplace.ui.sidecalendar.views.SideCalendarViewPart" ;
        IViewReference view = shelfPage.findView( PANEL_ID ) ;

        if ( view != null ) {
                shelfPage.hideView( view ) ;
        }
        else {
                shelfPage.showView( PANEL_ID ) ;
        }

The collection of all the available Sidebar panels can be obtained from the Eclipse extension registry.

        IExtensionRegistry registry = Platform.getExtensionRegistry();
        IExtensionPoint point = registry.getExtensionPoint( "com.ibm.rcp.ui.shelfViews" );
        IConfigurationElement[] elements = point.getConfigurationElements();
               
        System.out.println( "There are " + elements.length + " Sidebar Panels available.\n\n" );
        for( int i = 0; i < elements.length; i++ ) {
                System.out.println( elements[i].getAttribute( "view" ) + "\n" ) ;
        }
               
The registry returns a collection of IConfigurationElement, each one corresponds to a Sidebar panel. Any of the attributes defined by the ShelfView extension point schema can be accessed using the .getAttribute() method.