Note that the workbench advisor object is created in advance of creating the workbench. However, by the time the workbench starts calling methods on this class, PlatformUI.getWorkbench
is guaranteed to have been properly initialized.
Example of creating and running a workbench (in an IPlatformRunnable
):
public class MyApplication implements IPlatformRunnable { public Object run(Object args) { WorkbenchAdvisor workbenchAdvisor = new MyWorkbenchAdvisor(); Display display = PlatformUI.createDisplay(); int returnCode = PlatformUI.createAndRunWorkbench(display, workbenchAdvisor); if (returnCode == PlatformUI.RETURN_RESTART) { return IPlatformRunnable.EXIT_RESTART; } else { return IPlatformRunnable.EXIT_OK; } }
An application should declare a subclass of WorkbenchAdvisor
and override methods to configure the workbench to suit the needs of the particular application.
The following advisor methods are called at strategic points in the workbench's lifecycle (all occur within the dynamic scope of the call to {@link PlatformUI#createAndRunWorkbench PlatformUI.createAndRunWorkbench}):
initialize
- called first; before any windows; use to register thingspreStartup
- called second; after initialize but before first window is opened; use to temporarily disable things during startup or restorepostStartup
- called third; after first window is opened; use to reenable things temporarily disabled in previous steppostRestore
- called after the workbench and its windows has been recreated from a previously saved state; use to adjust the restored workbenchpreWindowOpen
- called as each window is being opened; use to configure aspects of the window other than actions bars fillActionBars
- called after preWindowOpen
to configure a window's action barspostWindowRestore
- called after a window has been recreated from a previously saved state; use to adjust the restored windowpostWindowCreate
- called after a window has been created, either from an initial state or from a restored state; used to adjust the windowopenIntro
- 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 closingseventLoopException
- called to handle the case where the event loop has crashed; use to inform the user that things are not welleventLoopIdle
- called when there are currently no more events to be processed; use to perform other work or to yield until new events enter the queuepreShutdown
- called immediately prior to workbench shutdown before any windows have been closed; allows the advisor to veto the shutdownpostShutdown
- called last; after event loop has terminated and all windows have been closed; use to deregister things registered during initialize
|
|
|
|