| Multiple ImageProviders in separate plug-ins [message #757169] |
Wed, 16 November 2011 16:42  |
Brian Fitzpatrick Messages: 495 Registered: July 2009 |
Senior Member |
|
|
Hi all...
There are multiple threads about registering multiple ImageProviders from different plug-ins for a particular DiagramType. But I haven't seen an example and haven't been able to get it to work yet.
We have a use case where we're trying to add items to the palette. Each item has an icon that is provided by a URL or project-relative path. So we don't know about these items ahead of time and can't register them in an ImageProvider class up front. To work around that, before we open the editor, I process the project looking for these files that have icon references in them and try to add them to an ImageProvider class at that point.
Unfortunately, even if I get the ImageProvider registered in an extension point in one plug-in and reference it in the other with the diagram provider, when the feature tries to get the image all I get is the little red "missing image" box.
I'm open to ideas here. I've debugged into this thing three ways from Sunday but I still haven't figured out where it's actually loading the image for the palette or for the diagram element on the canvas. So I don't know if it's just that you can't register images after the fact with Graphiti or what's going on.
Perhaps there's a way to use an Eclipse UI Image instead of a Graphiti Image that I'm not seeing? But there seem to be too many levels of indirection when doing stuff like this:
IGaService service = Graphiti.getGaService();
Image img = service.createImage(rect, [image ID registered in the ImageProvider] );
service.setLocationAndSize(img, 2, 2, GraphicsUtil.TASK_IMAGE_SIZE,
GraphicsUtil.TASK_IMAGE_SIZE);
And though I can grab the ImageDescriptor and create an Image that way, there doesn't seem to be a way to shoehorn it in even if I do my own image management.
Any and all ideas are welcome - even crazy ones.
Thanks
--Fitz
|
|
|
| Re: Multiple ImageProviders in separate plug-ins [message #757676 is a reply to message #757169] |
Mon, 21 November 2011 03:58   |
Joerg Reichert Messages: 60 Registered: July 2009 Location: Leipzig |
Member |
|
|
Hi Brian,
Graphiti uses GraphitiUi.getImageService().getImageForId(...) internally.
This method fetches internally the image registry from the GraphitiUIPlugin
ImageRegistry imageRegistry = GraphitiUIPlugin.getDefault().getImageRegistry();
Image result = imageRegistry.get(imageId);
So what you can do is to register and deregister images via the call
GraphitiUIPlugin.getDefault().getImageRegistry().put(String key, ImageDescriptor descriptor)
The ImageDescriptor class provides static methods like ImageDescriptor.createFromFile(Class location, String filename)
To fetch images from other plug-ins you can provide an extension point that returns an input stream or a URL, TheClassInTheOtherPlugin.class.getResourceAsStream(name) : InputStream or TheClassInTheOtherPlugin.class.getResource(name) : URL.
Regards,
Joerg
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01869 seconds