Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Plug-in Developer Guide
Previous Page Home Next Page

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 .

  • initialize - called first; before any windows; use to register things
  • preStartup - called second; after initialize but before first window is opened; use to temporarily disable things during startup or restore
  • postStartup - called third; after first window is opened; use to reenable things temporarily disabled in previous step
  • postRestore - called after the workbench and its windows have been recreated from a previously saved state; use to adjust the restored workbench
  • preWindowOpen - called as each window is being opened; use to configure aspects of the window other than action bars
  • fillActionBars - called after preWindowOpen to configure a window's action bars
  • postWindowRestore - called after a window has been recreated from a previously saved state; use to adjust the restored window
  • postWindowCreate - called after a window has been created, either from an initial state or from a restored state; used to adjust the window
  • openIntro - called immediately before a window is opened in order to create the introduction component, if any.
  • postWindowOpen - called after a window has been opened; use to hook window listeners, etc.
  • preWindowShellClose - called when a window's shell is closed by the user; use to pre-screen window closings
  • eventLoopException - called to handle the case where the event loop has crashed; use to inform the user that things are not well
  • eventLoopIdle - called when there are currently no more events to be processed; use to perform other work or to yield until new events enter the queue
  • preShutdown - called just after event loop has terminated but before any windows have been closed; allows the application to veto the shutdown
  • postShutdown - called last; after event loop has terminated and all windows have been closed; use to deregister things registered during initialize

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.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire