Workbench Session Management

Just about every non-trivial GUI application requires a way to manage the state of the application. An application's state consists of data like who the current user is, what service is the application connected to, what object is the user currently editing. Also, this kind of data may be differeent for different parts of the same application. For instance, one application window may be displaying data from one company while another window displays data from a different company.

The org.jlense.uiworks.workbench.IWorkbenchSession interface provides a way to manage such data. This interface is used to bind objects to UI parts thus providing a way to manage 'workflow' information in the workbench.

The IWorkbenchSession interface is inpired by the Java Servlet API's HttpSession interface except that the UIWorks IWorkbenchSession interface may actively manages session attributes than the HttpSession interface.

An instance of IWorkbenchSession can be obtained the workbench like so:

IWorkbenchSession session= PlatformUI.getWorkbench().getWorkbenchSession();

When getting attributes from this manager a workbench component reference is passed to the getAttribute method in addition to the attribute name. The passed component reference is used by the session manager to indicate the UI context in which the attribute is being requested.

public class AccountsView extends OutlookPart
     * Method declared on IWorkbenchPart
    public JComponent createPartControl()
        IWorkbenchSession session= 

        /* get the chart of accounts associated with this view */
        IChartOfAccounts chart= (IChartOfAccounts) 

So, for instance, the manager may return one value for a particular attribute when a component belongs to one workbench window and the manager may return a different value for the same attribute when the given component belongs to a different workbench window.

The purpose of the IWorkbenchSession interface is to provide an abstract facility for getting important session information that unburdens components from knowing exactly how they should get the information with regard to the state of the workbench or the workbench context in which the information is being requested.
For instance, a view that is looking for the name of the current project should not have to know how projects are managed within the workbench (are projects unique to workbench windows, to workbench pages, or to views?). The workbench session interface unburdens the view from having to know how projects are managed. The view simply passes a component reference that is used to determine the context in which the view is requesting a project reference, the rest is handled by the session manager implementation.

Attribute Managers

The IWorkbenchSession interface provides a method for plugins to actively manage session attributes by registering instances of ISessionAttributeManager.

The Workbench's IWorkbenchSession is extended by plugins to recognise new attributes by registering attribute managers. A ISessionAttributeManager can customize the way that attribute values are mapped to UI elements or they can dynamically create attribute values when requested.

Plugins may use the IWorkbenchSession.registerAttributes method to register and unregister attribute managers. The org.jlense.uiworks.sessionAttributeManagers extension point may also be used to register attribute factories.