When developing Eclipse plugins that should contribute to the UI, it is reasonable to align with the Eclipse UI design.
For example, within tree representations or in other UI elements, you might want to include the standard icons used in Eclipse.
To do this, Eclipse provides infrastructure that makes it an absolute no-brainer.
Standard Eclipse Icons
To access the standard Eclipse Icons, add a dependency on org.eclipse.ui to your plugin and use this code to access an icon as Image:
import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.swt.graphics.Image; ... Image image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
Note that the interface ISharedImages provides constants for all standard icons you can access.
JDT Eclipse Icons
The JDT provides a similar infrastructure hat could be accessed in an even more compact form:
import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.ISharedImages; import org.eclipse.swt.graphics.Image; ... ISharedImages images = JavaUI.getSharedImages(); Image image = images.getImage(ISharedImages.IMG_WHATEVER);
Again the JDT specific ISharedImages interface provides constants for the standard icons.
Using the same name for the interface makes it intuitive to find and use, but you need to use full qualified names if you want to use the standard and the JDT icons within the same compilation unit.