III. JDT standard icons

The JDT plug-in from Eclipse offers a set of shared standard icons, which you may want to use in your own plug-in.

 

The screen shot below displays all these high-use images:

 

 

The getSharedImages() method implemented by the JDT UI class org.eclipse.jdt.ui.JavaUI allows you to access these shared image resources easily. To get a specific image from the JDT share pool, you must only call the getImage()method subsequently.

Because these images are managed by the JDT Image Registry, you don’t need to dispose of the underlying resources.

 

Procedure

 

1. Identify appropriate icons

To identify standard JDT icons you need to know the registry constant name specified in org.eclipse.jdt.ui.ISharedImages.

 

2. Create image instances

To create a JDT image object, simply call the getSharedImages() method from the org.eclipse.jdt.ui.JavaUI class and apply the getImage()method. To identify the resource, specify the appropriate registry constant as a parameter.

 

import org.eclipse.jdt.ui.ISharedImages;

import org.eclipse.jdt.ui.JavaUI;

 

...

 

Image myImage = JavaUI.getSharedImages().getImage(

                              ISharedImages.<JDT_IMAGE_REGISTRY_CONSTANT>);

 

 

Example

 

The following lines of code display three JDT standard icons as elements in a toolbar:

 

 

 

myToolbar.addToolBarButton(JavaUI.getSharedImages().getImage(

                                 ISharedImages.IMG_OBJS_JAR));

 

myToolbar.addToolBarButton(JavaUI.getSharedImages().getImage(

                                 ISharedImages. IMG_OBJS_PACKAGE));

 

myToolbar.addToolBarButton(JavaUI.getSharedImages().getImage(

                                 ISharedImages. IMG_OBJS_PACKDECL));