Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Displaying Images
Displaying Images [message #1310568] Wed, 23 April 2014 05:03 Go to next message
John Cole is currently offline John Cole
Messages: 26
Registered: June 2013
Junior Member
Hello everyone,

I am trying to display a simple image and unfortunately it doesn't appear.
The affected part of my AddFeature looks like this:

public PictogramElement add(IAddContext context) {
    // CODE
    ContainerShape container = peCreateService.createContainerShape(context.getTargetContainer(), true);
    // CODE
    createImage(context, container);
    // CODE
}

private void createImage(IAddContext context, ContainerShape container) {
    Image image = gaService.createImage(container, DiagramImageProvider.IMG_EREFERENCE);
    gaService.setLocationAndSize(image, context.getX(), context.getY(), 500, 500);
}


My ImageProvider looks like this:

public class DiagramImageProvider extends AbstractImageProvider {

    // The prefix for all identifiers of this image provider
    protected static final String PREFIX = "my.example.diagram.";

    // The image identifier for an EReference.
    public static final String IMG_EREFERENCE = PREFIX + "exampleimage";

    @Override
    protected void addAvailableImages() {
        String path = (FileSystems.getDefault().getPath("icons", "exampleimage.png")).toString();
        // register the path for each image identifier
        addImageFilePath(IMG_EREFERENCE, path);
    }
}


I think I misunderstand something but the method addAvailableImages() in my ImageProvider is never called and due to this the image is not displayed. It simply looks like this:
index.php/fa/17974/0/

What do I have to do, to display the image in my editor?

I appreciate any advice!
  • Attachment: Screen.png
    (Size: 9.89KB, Downloaded 83 times)
Re: Displaying Images [message #1310820 is a reply to message #1310568] Wed, 23 April 2014 08:19 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1571
Registered: July 2009
Location: Walldorf, Germany
Senior Member
John,

this sounds as if you either have not registered your image provider or did
not assign it to your diagram type provider in plugin.xml. This is an
example for the Sketch test tool:

<extension
point="org.eclipse.graphiti.ui.diagramTypeProviders">
<diagramTypeProvider
class="org.eclipse.graphiti.testtool.sketch.SketchDiagramTypeProvider"
description="A sample sketch editor"
id="org.eclipse.graphiti.testtool.sketch.SketchDiagramTypeProvider"
context="org.eclipse.graphiti.testtool.sketch.context"
name="Sketch">
<diagramType
id="org.eclipse.graphiti.testtool.sketch.SketchDiagramType">
</diagramType>
<imageProvider
id="org.eclipse.graphiti.examples.common.ExampleImageProvider">
</imageProvider>
<imageProvider
id="org.eclipse.graphiti.testtool.sketch.SketchImageProvider">
<-----
</imageProvider>
</diagramTypeProvider>
</extension>

<extension
point="org.eclipse.graphiti.ui.imageProviders">
<imageProvider
class="org.eclipse.graphiti.testtool.sketch.SketchImageProvider"
<-----
id="org.eclipse.graphiti.testtool.sketch.SketchImageProvider">
</imageProvider>
</extension>

Michael
Re: Displaying Images [message #1312437 is a reply to message #1310820] Thu, 24 April 2014 05:40 Go to previous messageGo to next message
John Cole is currently offline John Cole
Messages: 26
Registered: June 2013
Junior Member
Thank you very much once again, Michael! I did not assign it to the diagram type provider. Now it works.

But I've got another question concerning a similar problem.
I want to load images on the fly. Means, that I know which image in my icons folder has to be loaded and I know the path. Currently my ImageProvider looks like this:

public class ImageProvider extends AbstractImageProvider {

	// The prefix for all identifiers of this image provider
	protected static final String PREFIX = "my.example.diagram.";

	public static String image = PREFIX + "circle";

	@Override
	protected void addAvailableImages() {
		String path = (FileSystems.getDefault().getPath("icons", "circle.png")).toString();
		// register the path for each image identifier
		addImageFilePath(image, path);
	}
}


So only the circle.png is supported at the moment. In my AddFeature I've got the following code:

Image image = gaService.createImage(container, ImageProvider.image);
gaService.setLocationAndSize(image, context.getX(), context.getY(), context.getWidth(), context.getHeight());


Now I want to load different images on the fly, when the add() method in my AddFeature is called. How is that possible?

Thank you very much in advance!
Re: Displaying Images [message #1314493 is a reply to message #1312437] Fri, 25 April 2014 08:01 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1571
Registered: July 2009
Location: Walldorf, Germany
Senior Member
That should be possible by introducing a public method to your image
provider that handler the dynamical add (and delegates to addImageFilePath).
In your feature you need to get hold of the image provider and add the
image. It will be usable after addImageFilePath has been called.

Michael
Re: Displaying Images [message #1327399 is a reply to message #1314493] Fri, 02 May 2014 02:15 Go to previous message
John Cole is currently offline John Cole
Messages: 26
Registered: June 2013
Junior Member
Hello Michael,

perfect! It works now. Thank you very much!
Previous Topic:Remove resize handlers
Next Topic:"Copy" bendpoints into another FreeFormConnection
Goto Forum:
  


Current Time: Tue Jul 22 07:41:00 EDT 2014

Powered by FUDForum. Page generated in 0.02587 seconds