A couple of years ago I wrote briefly about how to implement desktop notifications using a feature in Mylyn Commons. Since then the notification system in Mylyn has improved. In the 3.5 release there is now a extensible framework for handling and configuring notifications. While this API is still provisional I see no harm in using it as long as you’re aware of the potential consequences. I also think some feedback (and patches) from early adopters would be good. If you’re interested in the background story, take a look at these Eclipse bugs.
The org.eclipse.mylyn.commons.notifications.notifications extension point allows four extension types: category, event, eventMapping and sink. The category is used simply to organize the various events. Event is used to declare the event types and add some GUI attributes. The eventMapping is used for assigning default event type handlers. And lastly a sink is used to declare a mechanism that will handle the event.
If want to use a popup notification sink there is no longer a need to implement it yourself. You start by declaring the event type itself (a existing category is reused). An added benefit is that you get preference settings for configuring notifications.
In order to display the popup you will also have to implement an instance of AbstractNotification and trigger the notification.
AbstractNotification notification = new AbstractNotification ("my.event" ) { ... public String getLabel() { return "My Label"; } public String getDescription(){ return "My Description"; } }; Notifications.getService().notify( Collections.singletonList(notification)) ;
In Mylyn Builds we demonstrate use of this framework where both a popup and a special service message inside a view are used. Check out the source code for details. Also take a look at the extension point documentation.
Hi, thanks for your example.
One question: How do I create the categoryId?
It seems like that must be created somewhere before use.
5 minutes after I wrote this I understood that there was a category on the extension point as well. Simple enough and now it works.