Customizing the workbench

The "entry point" for supplying custom workbench behavior is the designation of a WorkbenchAdvisor for configuring the workbench. Your rich client plug-in should extend this abstract class to provide the application-specific configuration for the workbench. The browser example does this using the BrowserAdvisor class.

	int code = PlatformUI.createAndRunWorkbench(display,
			new BrowserAdvisor());

A workbench advisor is responsible for overriding methods to configure the workbench with its desired layout and features, such as the action bar items or intro page.

The workbench life-cycle

Life-cycle methods provided by the workbench advisor allow your application to hook into the creation of the workbench at any point in time and influence the behavior. The following list of advisor life-cycle methods that can be overridden comes from the javadoc for WorkbenchAdvisor.

As you can see, a rich client application has a lot of control over how the workbench is configured and implemented. In the browser example, the primary function of the BrowserAdvisor is to configure the action bars with menu items appropriate for a browser. This is done in the fillActionBars method:

	public void fillActionBars(IWorkbenchWindow window, IActionBarConfigurer configurer, int flags) {
		BrowserActionBuilder builder = new BrowserActionBuilder(window);
		getWorkbenchConfigurer().getWindowConfigurer(window).setData(BUILDER_KEY, builder); 
		builder.fillActionBars(configurer, flags);

In this method, the workbench is configured with a specialized action builder. This action builder is used to fill the action bars of the workbench. We'll look at the details for how the actions are specified in Defining the actions. For now, we are focusing on how we configure the workbench.

Note the use of the getWorkbenchConfigurer() method above. The IWorkbenchConfigurer and IWorkbenchWindowConfigurer are used in conjunction with the WorkbenchAdvisor to customize the window. These classes allow you to override many aspects of workbench creation at different levels. For example, the IWorkbenchWindowConfigurer defines protocol that assumes a particular configuration of controls in the workbench window, such an action bar, status line, perspective bar, cool bar, etc. Its protocol allows you customize and populate these items. The IWorkbenchConfigurer operates at a higher level, allowing you to store application-specific data with the workbench. The WorkbenchAdvisor provides access to these configurers in the life-cycle methods noted above. Lower level methods inside WorkbenchAdvisor may be overridden to completely replace default behavior. For example, your workbench advisor could override the method that creates the SWT controls in the window in order to provide a completely different implementation for the main window.

In other words, there are many ways to customize the workbench and several different levels at which these techniques can be used. The javadoc for WorkbenchAdvisor, IWorkbenchConfigurer, and IWorkbenchWindowConfigurer includes a complete description of the available protocol. See also the complete implementation of BrowserAdvisor for comments on alternate implementations.