Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically access JDT icons with an eclipse plugin?

I'd like to use built-in JDT icons inside my plugin: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-icons.htm

How can I access them from within my code? The following code seems to list some shared images, but only standard UI icons of eclise, not JDT specific (I need icons for private/public/... methods/fields in Java):

IWorkbench workbench = PlatformUI.getWorkbench();
ISharedImages images = workbench.getSharedImages();
Image image = images.getImage(ISharedImages.IMG_OBJ_FOLDER);
like image 424
Cedric Reichenbach Avatar asked Oct 23 '12 12:10

Cedric Reichenbach


1 Answers

Just found it out: On my above code, instead of using org.eclipse.ui.ISharedImages (as returned by workbench.getSharedImages(), just use org.eclipse.jdt.ui.ISharedImages, which returns constants for jdt images.

Update:

The above gave me a NullPointerException. The following is working now:

ISharedImages images = JavaUI.getSharedImages();
Image image = images.getImage(ISharedImages.IMG_WHATEVER);
like image 118
Cedric Reichenbach Avatar answered Oct 09 '22 20:10

Cedric Reichenbach