Wednesday, 9 December 2015

Creating Image Registry in Eclipse RCP

Advantage of Creating Image Registry in Eclipse RCP

  1. Share same image between different plugin.
  2. Don't dispose the image and keep it for another plugin.

How to crate Image Registry?

Override the initializeImageRegistry method inside the Activator and you are ready to use t

 public class Activator  {
      public static final String MY_PLUGIN_ID = "";
      public static final String MY_IMAGE_ID = "";

      protected void initializeImageRegistry(ImageRegistry registry) {
         Bundle bundle = Platform.getBundle(MY_PLUGIN_ID);
         IPath path = new Path("icons/save_image.gif");
         URL url = FileLocator.find(bundle, path, null);
         ImageDescriptor desc = ImageDescriptor.createFromURL(url);
         registry.put(MY_IMAGE_ID , desc);

How to use in Code :

In same plugin :
            imageRegistry.getDescriptor( Activator.MY_IMAGE_ID) );

In Different plugin :

AbstractUIPlugin.imageDescriptorFromPlugin( "", "" );