Loading images [message #1758847] |
Mon, 03 April 2017 18:23 |
Alex Kravets 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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03945 seconds