import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.DecorationContext;
public void decorate(Object element, IDecoration decoration) {
IFile file = ((IFile) element);
if ( !file.exists() ) {
- decoratedImageFiles.remove(file);
+ removeDecoratedImageFile(file);
return;
}
try {
bImage = ImageUtil.getBufferedImage(file.getContents());
image = ImageUtil.convertImageToSWT(SWTUtil.getDisplay(), ImageUtil.getScaledImage( bImage, IMAGE_FILE_WIDTH, IMAGE_FILE_HEIGHT ));
- } catch (CoreException e) {
- logger.error( e.getMessage(), e );
- } catch (NullPointerException e ) {
+ if ( image != null ) {
+ putDecoratedImageFile(file, image);
+ }
+ } catch (Exception e) {
logger.error( "Invalid image file: " + file.getName(), e );
} finally {
if ( bImage != null ) {
decorationImpl.putProperty(IDecoration.ENABLE_REPLACE, Boolean.TRUE);
}
decoration.addOverlay(imageDescriptor, IDecoration.REPLACE);
-
- decoratedImageFiles.put(file, image);
}
+
}
/* Implement for IResourceChangeListener */
IResourceDelta delta = event.getDelta().findMember(file.getFullPath());
if ( delta != null ) {
if ( delta.getKind() == IResourceDelta.REMOVED ) {
- SWTUtil.tryDispose(decoratedImageFiles.get(file));
- decoratedImageFiles.remove(file);
+ removeDecoratedImageFile(file);
} else {
- decoratedImageFiles.put(file, null);
+ putDecoratedImageFile(file, null);
refresh();
}
}
});
}
+ public void putDecoratedImageFile( IFile imageFile, Image image ) {
+ decoratedImageFiles.put(imageFile, image);
+ }
+
+ public void removeDecoratedImageFile( IFile imageFile ) {
+ SWTUtil.tryDispose(decoratedImageFiles.remove(imageFile));
+ }
+
}