Hi,
I am telling in my getPaletteCompartmentEntries what image to use also via CreateFeature.
ObjectCreationToolEntry octe = new ObjectCreationToolEntry(cf.getCreateName(), cf.getCreateDescription(),
cf.getCreateImageId(), cf.getCreateLargeImageId(), cf);
However they are defined somewhere else. What I am doing:
1. plugin.xml:
<extension point="org.eclipse.graphiti.ui.diagramTypeProviders">
<diagramTypeProvider
class="com.systemincloud.modeler.gui.diagram.SystemInCloudDiagramTypeProvider"
id="com.systemincloud.modeler.gui.diagram.SystemInCloudDiagramTypeProvider"
description="This is the editor for the System in Cloud Task"
name="System in Cloud Modeler">
<diagramType id="com.systemincloud.modeler.gui.SystemInCloudDiagramType" />
<imageProvider id="com.systemincloud.modeler.gui.SystemInCloudImageProvider" />
</diagramTypeProvider>
</extension>
<extension point="org.eclipse.graphiti.ui.imageProviders">
<imageProvider
class="com.systemincloud.modeler.gui.providers.ImageProvider"
id="com.systemincloud.modeler.gui.SystemInCloudImageProvider">
</imageProvider>
</extension>
2. ImageProvider:
public class ImageProvider extends AbstractImageProvider {
@Override
protected void addAvailableImages() {
// add image path from general features
Map<String, String> imgs = Images.getImageKeyPath();
for (Entry<String, String> img : imgs.entrySet()) {
addImageFilePath(img.getKey(), img.getValue());
}
// add image path from tasks
imgs = TaskProvider.INSTANCE.getImageKeyPath();
for (Entry<String, String> img : imgs.entrySet()) {
addImageFilePath(img.getKey(), img.getValue());
}
// add image path from installed extensions
imgs = ModelerGuiExtensionManager.INSTANCE.getImageKeyPath();
for (Entry<String, String> img : imgs.entrySet()) {
addImageFilePath(img.getKey(), img.getValue());
}
}
}
3. Contributing images
public class Images {
public enum K {
IMG_INSPECT_PALETTE("/icons/palette.inspect.png"),
IMG_INSPECT_DIAGRAM("/icons/diagram.inspect.png")
;
public String path;
K(String path) { this.path = path; }
}
static Map<String, String> images = new HashMap<String, String>() { private static final long serialVersionUID = 1L; {
for (final K v : K.values())
put(v.name(), FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(v.path), null).toString());
}};
public static Map<String, String> getImageKeyPath() { return images; }
}
4. Contribute to Pallete:
public class CreateFeature extends CreateTaskFeature {
public CreateFeature(IFeatureProvider fp, String bundleName, Version version) { super(fp, Inspect.class, bundleName, version); }
@Override public String getPaletteKey() { return SicPlugin.GUI_ID.s(); }
@Override public String getTestPaletteKey() { return SicPlugin.GUI_ID.s(); }
@Override public String getTaskCategory() { return TaskCategory.TEXT.name(); }
@Override public String getTestTaskCategory() { return TaskCategory.TEXT.name(); }
@Override public Object[] create(ICreateContext context) {
Inspect inspect = InspectFactory.eINSTANCE.createInspect();
inspect.setOnlyLocal(true);
return super.create(context, inspect);
}
@Override protected Class<? extends PortsDescr> getPortsDescription() { return Port.class; }
@Override public String getCreateImageId() { return Images.K.IMG_INSPECT_PALETTE.name(); }
}
Summary:
So in my case I can contribute to ImageProvider even from several plugins via for example RegisteredServices.