Table of Contents
mbManagerCart Design
This section describes how to access and retrive data from the MBAT cart, the mechanism that allows the sharing of objects among the workspace plugins. The basic interaction between a workspace, derived from
mbWorkspaceBase, and the GUI for the cart,
JManagerCart, is shown in the figure below. The MBAT cart is an universal object that is shared among all the workspace plugins. The central idea is that any workspace can add an object to the cart and then any another workspace can retrieve this object from the cart.
JManagerCart and mbCartListeners
The
JManagerCart communicates with the workspace plugins using the listener methodology that is widely used in Java Swing. The
mbCartListener interface defines a single method
onEvent( mbCartEvent ):
public interface mbCartListener extends EventListener {
public void onEvent( mbCartEvent event );
}
The
mbCartEvent defines
ADD,REMOVE,OPEN events that need to be handled by the implementing listener for the given
mbObject:
public class mbCartEvent extends AWTEvent {
private mbObject m_mbObject;
public final static int ADD = 0;
public final static int REMOVE = 1;
public final static int OPEN = 2;
}
Examples of how to handle different events are given below.
Add/Remove objects to/from the JManagerCart
To add or remove objects, the workspace plugin should add an instance of the
JManagerCart to a list of
mbCartListeners (the derived workspace must handle storing and managing the cart listeners, ie:
private Vector< mbCartListener > / public void addCartListener( mbCartListener )).
On the specific event, the workspace plugin needs to create an instance of
mbCartEvent and then fire this event to the
mbCartListeners. Upon receiving an
mbCartEvent, the
JManagerCart handles adding or removing the given
mbObject from the
mbManagerCart:
mbCartEvent cartEvent = new mbCartEvent( m_resultTable, mbCartEvent.ADD, annotatedObject );
for( mbCartListener listener: m_vCartListeners )
{
listener.onEvent( cartEvent );
}
Open objects from the JManagerCart
To open an object from the
JManagerCart, the workspace plugin must implement the
mbCartListener interface and define a
onEvent( mbCartEvent ) method to handle the OPEN and REMOVE events that are triggered by the
JManagerCart when the user clicks the Open or Remove buttons in the
JManagerCart GUI:
public void onEvent ( mbCartEvent event )
{
if( event.getID() == mbCartEvent.OPEN )
{
// do something with mbObject
foo( event.getObject() );
}
else( ... )
}
To register your workspace plugin as a cart listener, you must add your workspace to the
JManagerCart cart listeners. Since the
JManagerCart is shared among the workspaces, you must be careful to add and remove your workspace cart listener apprioriately. For example, if you add the cart listener only once at startup, then if you switch workspaces, the OPEN event will still be triggered for the hidden workspace since it is still on the
mbCartListener list. If you only want the
JManagerCart events triggered when the workspace is visible, then as described in the
Workspace Plugins section, you can remove and add the cart listeners in the
hide() and
show() methods:
public void hide ()
{
...
// remove cart listener
JManagerCart.getInstance().removeCartListener( m_viewer );
...
}
public void show ()
{
...
// add cart listener
JManagerCart.getInstance().addCartListener( m_viewer );
...
}