Contributing a sample handler
We will now contribute a very basic status handler just to illustrate the steps
needed to contribute a status handler implementation to the Workbench. To do this:
- use the org.eclipse.ui.statusHandlers extension point to register
a status handler implementation and bind it to your product
- extend the org.eclipse.ui.statushandlers.AbstractStatusHandler
class and use as the class attribute in the above extension point contribution
- run your Eclipse based product with the correct product id
Here is the org.eclipse.ui.statusHandlers extension point markup:
<extension point="org.eclipse.ui.statusHandlers">
<statusHandler
class="org.eclipse.ui.statushandlers.SampleStatusHandler"
id="sampleStatusHandler"/>
<statusHandlerProductBinding
handlerId="sampleStatusHandler"
productId="productId">
</introProductBinding>
</extension>
A statusHandler is registered with the Workbench. The statusHandlerProductBinding
contribution tells the Workbench that the status handler we just defined is
bound to our product with the id "productId". The status handling facility
uses lazy initialization, so the handler will be instantiated during first access
to the facility in the product.
The class defined by the class attribute extends org.eclipse.ui.statushandlers.AbstractStatusHandler
.
The following is sample code that simply writes to the console the message set in the status adapter.
public void handle(final StatusAdapter statusAdapter, int style) {
System.out.println(statusAdapter.getStatus().getMessage());
}
When you run the product with the id defined in the statusHandlerProductBinding
you will start to use your product handler. For example, if you are self hosting,
create a new runtime-workbench launch configuration, choose the "Run a product"
option, and select productId from the dropdown.