Skip to content

Instantly share code, notes, and snippets.

@turesheim
Created May 5, 2011 06:44
Show Gist options
  • Save turesheim/956647 to your computer and use it in GitHub Desktop.
Save turesheim/956647 to your computer and use it in GitHub Desktop.
Decorating Eclipse icons with status indicators
private static final Point size = new Point(16, 16);
private Image getDecoratedImage(ImageRegistry registry,
String baseImageId,
IStatus status){
ImageDescriptor overlay = null;
Image baseImage = registry.get(baseImageId);
switch (status.getSeverity()) {
case IStatus.ERROR:
overlay = PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR);
break;
case IStatus.WARNING:
overlay = PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING);
break;
default:
return baseImage;
}
// Construct a new image identifier
String decoratedImageId = baseImageId.concat(String.valueOf(status
.getSeverity()));
// Return the stored image if we have one
if (registry.get(decoratedImageId) == null) {
// Otherwise create a new image and store it
DecorationOverlayIcon decoratedImage = new DecorationOverlayIcon(
baseImage, new ImageDescriptor[] { null, null, null,
overlay, null }, size) {
};
registry.put(decoratedImageId, decoratedImage);
}
return registry.get(decoratedImageId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment