Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse MenuManager: get ImageDescriptor of Image?

I cannot get this to work so I thought it might be a wise idea posting over here...

I have a context menu in SWT (actually its an Eclipse plugin). It's a cascaded menu, so it expands as soon as you hover over a certain entry...

My problem is, that I want to attach a small icon to the menu but I struggle with that!

Code: ....

            manager.add(new Separator());

            // icon for the "change color" menu
            ImageDescriptor icon = ImageDescriptor.createFromFile(null,
                "icons/palette_brush.png");

            // submenu
            MenuManager colorMenu = new MenuManager("Menu", icon,  null);

            // Actions
            colorMenu.add(someAction);

            // add the action to the submenu
            manager.add(colorMenu);

           ....

My problem is, that the new MenuManager can either be called with 2 Arguments (no attached image) or 3 (with attached image). The image should be passed along as ImageDescriptor.

The question basically is:
"How can I get an Imagedescriptor off an image?"
Maybe it's an stupid mistake - but I cannot get an ImageDescriptor from an image file. I have an *.png icon ready to use, but I struggle incorporating this.

If anyone could help out with a snippet, that would get me an ImageDescriptor from an image file this would be soo awesome!

Best regards!

MenuManager Documentation:
MenuManager Docu

like image 281
Gnark Avatar asked Sep 21 '10 10:09

Gnark


2 Answers

Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, "icons/palette_brush.png");
ImageDescriptor.createFromURL(fullPathString);

pluginId is the id of the plugin where you put your icon.

like image 56
nanda Avatar answered Sep 23 '22 10:09

nanda


Bundle bundle= org.eclipse.core.runtime.Platform.getBundle(pluginId);
URL fullPathString = bundle.getEntry("icons/palette_brush.png");
desc= ImageDescriptor.createFromURL(fullPathString);
desc.createImage();
like image 38
user6669492 Avatar answered Sep 23 '22 10:09

user6669492