I’ve been trying to decide how to work with Equinox services in the user interface.
I’ve started modifying the Organizer application that will soon be part of the Eclipse Examples Project (once it’s provisioned) to use Equinox services. I’ve got a view that updates its appearance based on available services. The implementation is straightforward enough. The view has a ServiceTracker that watches as services of a particular type are added (or removed). As these services come online, the tracker notifies me of the change and I add a button corresponding to the new service to the view. The button is configured (text and image) with information from the service; when clicked, the button invokes behaviour on the service. When the tracker notifies me of that the service has been removed, I dispose() the button (thereby removing it).
It’s pretty cool to see the user interface change in response to commands typed in the Equinox console. Stop the service and the button disappears, start the service and the button reappears. Lather, rinse, repeat. Hours of fun for the whole family.
One advantage of this technique is that I can control aspects of my user interface by selectively enabling services. I can imagine a scenario where, using declarative services, a collection of services depend on the existence of a “role” service. For example, administrative behaviour might be defined in a collection of services that depend on the existence of an “Administrator” service that is only created if the user’s permissions include administrative operations. With declarative services, it’s easy to specify a cardinality on your dependencies; a service can specify, for example, that exactly one service of a particular type must be started before it will start. This isn’t exactly what I have in mind with the example I’m working on, but might be an interesting proof of concept.
The example code is still a little rough. I’m smoothing it out in anticipation of the Examples project being provisioned. In the meantime, I may try to develop a simpler example and post some of the code.