Last week I posted about a new plug-in I created for Sametime, the Lotus Connections Notifications Plug-In. The plug-in is basically a feed reader of all the things that your colleagues are working on inside Lotus Connections, but it's a lot easier to use for the big majority of users. And because it brings Lotus Connections to the desktop, it drives adoption.
One of the comments left on my blog asked some technical details on which APIs I used to create the plug-in. I briefly mentioned that I used the Notifications API, but I wanted to expand on that. Thus, warning, the following is very geeky!
When I first started, I looked at the sample plug-ins included with the Sametime SDK, specifically the com.ibm.collaboration.realtime.sample.snippets sample. If you want to learn more about how alerts work, I recommend taking a peek at the sample code provided in that simple plug-in.
I think that the best way to explain this is go through the flow of the plug-in and mention the classes being used:
- First, the plug-in is activated during startup because one of its classes implements org.eclipse.ui.IStartup
- At that point, the plug-in's Activator gets loaded and a job is created. This job is a custom class that extends org.eclipse.core.runtime.jobs.Job and overrides the run(IProgressMonitor monitor) method. This method runs in a separate thread and is scheduled to run every 60 seconds.
- Once the job is triggered, we make a query to Lotus Connections to retrieve this feed: https://connections.acme.com/news/atom/stories/public. This feed returns the same content shown in the Discover tab of the Lotus Connections Homepage.
- For each story retrieved, we check to see if it's from one of the user's colleagues. (you can retrieve the user's colleagues by querying https://connections.acme.com/profiles/atom/connections.do?connectionType=colleague&userid=....
- If a story is from one of our colleagues, we create a notification using the Sametime Notifications API. To do this, we create an instance of com.ibm.collaboration.realtime.messages.AlertUserMessage. Once instantiated, we set some options, and then call the post() method.
- Once the alert has been posted, the framework checks what type of alert it is. In plugin-xml, I've defined that this alert should be 'drawn' by a custom class I created called NewsUpdateWindow.
- NewsUpdateWindow is extends com.ibm.rcp.realtime.alerts.ui.DefaultAlertWndow and overrides the buildContents(Composite parent) method.
- In this method, we follow the basic RCP UI guidelines to build the UI of the alert.
- For my particular alert, I chose to use Sametime's embedded browser: com.ibm.collaboration.realtime.browser.Browser. The reason is that the atom feed returns an HTML version of the news feed. Therefore, the alert looks like what you would see if you were reading the stories directly in Lotus Connections via a regular browser ( and I don't need to do any extra parsing ).
- At this point, the alert is shown to the user, the job ends and we wait until the job is triggered again, 60 seconds later.
I've included the source code as part of the plug-in. Thus, as soon as the plug-in becomes available you'll be able to see the nitty gritty of how this plug-in works.
I hope this information is valuable to you. Please let me know if there's anything else you would like to know.