Created
May 5, 2011 06:44
-
-
Save turesheim/956647 to your computer and use it in GitHub Desktop.
Decorating Eclipse icons with status indicators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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