Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Multiple ImageProviders in separate plug-ins
Multiple ImageProviders in separate plug-ins [message #757169] Wed, 16 November 2011 21:42 Go to next message
Brian Fitzpatrick is currently offline 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 08:58 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg Reichert
Messages: 78
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
Re: Multiple ImageProviders in separate plug-ins [message #896222 is a reply to message #757169] Tue, 17 July 2012 15:53 Go to previous messageGo to next message
Rob Cernich is currently offline Rob Cernich
Messages: 40
Registered: September 2011
Member
It would be nice if there were a way to do this through an extension point. If I wanted to create an extensible editor whereby additional functionality could be contributed by additional plugins, those plugins would need to be able to contribute icons to the diagram type being extended.

I've been able to **HACK** around this by adding an additional diagramTypeProvider extension that only describes an imageProvider. It's definitely a hack, but it works. For example,

   <!-- This could be fragile.  We do this to make sure the SwitchYard images are loaded for use in the BPMN2 Editor. -->
   <!-- Make sure class is null so it doesn't hork up the real diagram provider. -->
   <extension point="org.eclipse.graphiti.ui.diagramTypeProviders">
      <diagramTypeProvider
            description="This is the editor for the BPMN2 diagram"
            id="org.eclipse.bpmn2.modeler.ui.diagram.MainBPMNDiagramType"
            name="BPMN2 Editor">
         <imageProvider id="org.switchyard.tools.ui.editor.ImageProvider"/>
      </diagramTypeProvider>
   </extension>


Best,
Rob
Re: Multiple ImageProviders in separate plug-ins [message #896472 is a reply to message #896222] Wed, 18 July 2012 13:22 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Rob,

interesting approach... :-O

Providing images from other plugins is already requested, see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=366452. "P3" says it is a
candidate currently for our Eclipse Kepler planning.

Michael
Re: Multiple ImageProviders in separate plug-ins [message #1005429 is a reply to message #757169] Fri, 25 January 2013 12:07 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek Jagielski
Messages: 63
Registered: April 2012
Member
Hello,
What is the stage of the topic? Is there already a standard solution to keep images in separate bundles.
In my case (dynamically extended editor by eclipse plugins) I used deprecated

Platform.find(FrameworkUtil.getBundle(VipBezimieModelerExtension.class), new Path(pluginImage.getImagePath())).toString()


in plugins in osgi service functions to provide information to the image provider of the main editor plugin.

Marek
Re: Multiple ImageProviders in separate plug-ins [message #1005454 is a reply to message #1005429] Fri, 25 January 2013 13:59 Go to previous message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Marek,

Bugzilla https://bugs.eclipse.org/bugs/show_bug.cgi?id=366452 was used to
track this and was closed as it seemed that all needed things work. See
especially comment 8 for details on how to reference images located
somewhere else.

If this does not fit in your case feel free to reopen that bug.

Michael
Previous Topic:Adding Root Domain Object on Diagram Creation
Next Topic:Adding a new shape to diagram by double-click
Goto Forum:
  


Current Time: Thu Oct 23 11:14:09 GMT 2014

Powered by FUDForum. Page generated in 0.01807 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software