Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » adding icons to the palette
adding icons to the palette [message #1699423] Wed, 24 June 2015 09:15 Go to next message
Li li is currently offline Li liFriend
Messages: 3
Registered: May 2015
Junior Member


I want to add a ObjectCreationEntry to a paletteCompartmentEntry, we use a "getCreateimageId()" as parameter. I guess it represents the small icon in the palette to show a small picture of what we are going to add. However, i can't find where we define this imageid (in the createFeature ?), i already searched, but i only find a setimageId for a contextButton, not for a CreateFeature.

So, my question is, how can i add this small picture in my palette ?Could you give me a simple sample?

Thank you for your time
Re: adding icons to the palette [message #1699520 is a reply to message #1699423] Wed, 24 June 2015 18:29 Go to previous message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
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.
Previous Topic:how to import/export model instances
Next Topic:Animations in Graphiti
Goto Forum:
  


Current Time: Fri Apr 19 21:37:40 GMT 2024

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

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

Back to the top