Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Loading images
Loading images [message #1758847] Mon, 03 April 2017 18:23 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
The editor I am writing is using declarative approach - non of the UI is hard-coded, it's all driven by XML, for example palette is described the descriptor XML. Part of declaration are the images which are queried from the XML as well. So when adding shape from the palette, I have the following code in order to get correct image for the component from the palette:

public class ImageProvider extends AbstractImageProvider {
	public static final String ID = "com.ui.diagram.graphiti.ImageProvider";
	// The prefix for all identifiers of this image provider
    protected static final String PREFIX = "com.ui.diagram.graphiti.images.";
 
    // The image identifier for an EReference.
    public static final String RELATION_IMG = PREFIX + "relation";
    public static final String LOOP_IMG = PREFIX + "loop";
    
    private List<String> imageIdsList = new ArrayList<String>();
 
    @Override
    protected void addAvailableImages() {
        // register the path for each image identifier
        addImageFilePath(RELATION_IMG, "icons/misc/relation.png");
        addImageFilePath(LOOP_IMG, "icons/misc/loop.png");
    }
    
    public String resolveComponentImage(String id){
    	if(!imageIdsList.contains(id)){
    		addImageFilePath(PREFIX + id, "/icons/palette/components/" + id + "_32.png");
    		imageIdsList.add(id);
    	}
    	return PREFIX + id;
    }
}


During creation of the image resolveComponentImage() is called, image is registered and used in the editor. This works fine as GraphicsAlgorithm is created with id com.ui.diagram.graphiti.images.file for example, and image is displayed. However, when I restart Eclipse, id that I had registered using resolveComponentImage() is not in loaded anymore and thus I just a have a red square, which is expected at this point.

My question is, can I dynamically populate ImageProvider with images when class is initialized and addAvailableImages() is called? Ideally I'd like to have ImageProvider get all graphicsAlgorithms of type Image, get their ID's and load image described by ID into memory. Another words I rather not hard-code images that are available in the plugin in ImageProvider because then I lose the whole declarative approach.

So far the two solutions I see are either to get the bundle and iterate through icons directory in addAvailableImages() method or to get diagram file for the editor, get image ID's from there and in turn use first approach to load them. But before doing this I want to see if Graphiti offers something already or I am missing an obvious solution.
Re: Loading images [message #1759124 is a reply to message #1758847] Thu, 06 April 2017 15:44 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex,

I'm not sure if I completely understood your question, but as an immedeate idea to solve this I propose to add a hook to diagram editor (e.g. in init after the site has been set), parse the diagram there and register all found images.

HTH,
Michael
Re: Loading images [message #1759334 is a reply to message #1759124] Mon, 10 April 2017 16:12 Go to previous message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
Thanks Michael. This will work.
Previous Topic:Graphiti examples
Next Topic:Custom connection
Goto Forum:
  


Current Time: Fri Mar 29 05:25:07 GMT 2024

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

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

Back to the top