Wayne Beaton is not impressed with how tightly coupled his image viewer is with the resources API. His solution to the problem involves reworking the plug-in to make it ‘exploit’ the Eclipse adapter mechanism. The powerful adapter mechanism makes it possible to build plug-ins that ‘work really well together but know nothing about each other’.
“The basic idea is that I want my image viewer to display an image for the selected thing, whatever it is. So it registers a selection listener with the workbench selection service; the selection listener is notified whenever a selection occurs in a table, tree, editor, whatever. The image viewer looks at the selection and tries to determine how to display an image for it. To do this, it attempts to adapt the selected thing into an instance of the ImageProvider type and then asks the ImageProvider for the image. If the selected thing cannot be adapted to the appropriate type, the whole process is aborted, so the image viewer displays the last thing that was selected that could provide an image,” Wayne says.
To insulate the image viewer from having any knowledge of the resources API, Wayne created a separate plug-in that knows about both the image viewer and the resource plug-in, but these plug-ins are isolated from each other. To add support to display images for other types of objects, Wayne adds the org.eclipse.core.runtime.adapters extension. He also provides links to the project set and the image viewer plug-ins.