The handlers are responsible for presenting problems by logging or showing appropriate feedback to the user (generally dialogs).
All status handlers extend org.eclipse.ui.statushandlers.AbstractStatusHandler which requires each handler to implement handle(StatusAdapter status, int style). This method handles statuses based on a handling style. The style indicates how status handler should handle a status. See Acceptable styles.
There are two ways for contributing handlers to the Workbench:
NOTE! if there exists a handler associated with the product, it is used instead of the one defined in the advisor.
A status handler has an id and a set of parameters. The handler can use them during the handling process. If the handler is added as an extension, both the id and parameter set are set during initialization of the handler with the use of elements and attributes of the statusHandler element.In order to log extra information with the use of the default logging mechanism, it is necessary to perform some additional steps. The status manager provides you with an API that allows you to hook into the mechanism.
StatusManager#addLoggedStatus(IStatus status)
And below is the example of addLoggedStatus(IStatus status) proper usage.
public void handle(final StatusAdapter statusAdapter, int style) { ... if ((style & StatusManager.LOG) == StatusManager.LOG) { StatusManager.getManager().addLoggedStatus(statusAdapter.getStatus()); WorkbenchPlugin.getDefault().getLog().log(statusAdapter.getStatus()); } }
The platform supplies its own status handler implementation org.eclipse.ui.statushandlers.WorkbenchErrorHandler. It respects all acceptable styles. It uses the default logging mechanism and a dialog based on the JFace org.eclipse.jface.dialogs.ErrorDialog.
There is a simple way to contribute a support area in the JFace ErrorDialog. It is the ErrorSupportProvider which can be set in the JFace policy. Because the default workbench handler uses a subclass of the ErrorDialog for its dialog, setting the provider on the JFace policy will affect this dialog as well.
When a handler like the one below is created
public class CustomStatusHandler extends WorkbenchErrorHandler { public CompanyStatusHandler() { ErrorSupportProvider provider = createSupportProvider(); Policy.setErrorSupportProvider(provider); } private ErrorSupportProvider createSupportProvider() { ... } }
and is contributed to the Workbench in one of two available ways, all dialogs based on the ErrorDialog including the one shown by the default handler, will have an extra support area.
The status manager is the entry point for all statuses that are to be displayed in the user interface. Handlers are not intended to be used directly. They should be referenced via the StatusManager which selects the appropriate handler to apply. The following methods are the API entry points to the StatusManager
StatusManager#handle(IStatus) StatusManager#handle(IStatus, int) StatusManager#handle(StatusAdapter) StatusManager#handle(StatusAdapter, int)
The StatusManager singleton is accessed using
StatusManager.getManager()
The int parameters are used for supplying styles for handling. See Acceptable styles.
NOTE! the style is only a suggestion and may not be honored by the current handler. For instance a handler may choose not to show the user anything when the SHOW flag is sent. See Status handlers for more details.
If a handler is associated with a product, it is used instead of the one that was defined in advisor. However because product handler is lazy initialized, an error can occur during the first attempt to access it. If any creation error occurs in the product handler, the workbench handler will process this error.
Below is a list of StatusManager styles which can be combined with logical OR:
The StatusAdapter wraps an instance of IStatus subclass and can hold additional information either by using properties or by adding a new adapter. It is used during status handling process.
Each handler should specify what properties or types it accepts, being aware of the fact that developers can pass status adapters with such extra information.