EXPLORER: Refine the logic for the cache and resourceChange 43/12443/4
authorchanghyun1.lee <changhyun1.lee@samsung.com>
Fri, 15 Nov 2013 06:37:22 +0000 (15:37 +0900)
committerchanghyun1.lee <changhyun1.lee@samsung.com>
Fri, 15 Nov 2013 08:58:05 +0000 (17:58 +0900)
 Refine for duplicated add image

Change-Id: I11462c71acdfe35f22f2743eb067828a2fb1c91e
Signed-off-by: changhyun1.lee <changhyun1.lee@samsung.com>
org.tizen.common.ui/src/org/tizen/common/ui/decorators/ImageFileDecorator.java

index 0604eef..8dc71eb 100644 (file)
@@ -35,7 +35,6 @@ import org.eclipse.core.resources.IResourceChangeEvent;
 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;
@@ -85,7 +84,7 @@ public class ImageFileDecorator extends BaseLabelProvider implements ILightweigh
     public void decorate(Object element, IDecoration decoration) {
         IFile file = ((IFile) element);
         if ( !file.exists() ) {
-            decoratedImageFiles.remove(file);
+            removeDecoratedImageFile(file);
             return;
         }
 
@@ -95,9 +94,10 @@ public class ImageFileDecorator extends BaseLabelProvider implements ILightweigh
             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 ) {
@@ -114,9 +114,8 @@ public class ImageFileDecorator extends BaseLabelProvider implements ILightweigh
                 decorationImpl.putProperty(IDecoration.ENABLE_REPLACE, Boolean.TRUE);
             }
             decoration.addOverlay(imageDescriptor, IDecoration.REPLACE);
-
-            decoratedImageFiles.put(file, image);
         }
+
     }
 
     /* Implement for IResourceChangeListener */
@@ -128,10 +127,9 @@ public class ImageFileDecorator extends BaseLabelProvider implements ILightweigh
                 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();
                     }
                 }
@@ -148,4 +146,12 @@ public class ImageFileDecorator extends BaseLabelProvider implements ILightweigh
         });
     }
 
+    public void putDecoratedImageFile( IFile imageFile, Image image ) {
+        decoratedImageFiles.put(imageFile, image);
+    }
+
+    public void removeDecoratedImageFile( IFile imageFile ) {
+        SWTUtil.tryDispose(decoratedImageFiles.remove(imageFile));
+    }
+
 }