EXPLORER: Added image file thumbnail in Project Explorer and Package Explorer 95/12395/6
authorchanghyun1.lee <changhyun1.lee@samsung.com>
Thu, 14 Nov 2013 11:28:14 +0000 (20:28 +0900)
committerchanghyun1.lee <changhyun1.lee@samsung.com>
Fri, 15 Nov 2013 05:06:48 +0000 (14:06 +0900)
 image file thumbnail in Project Explorer

Change-Id: I731591d94b514859513dfc66c10c468115e30cd1
Signed-off-by: changhyun1.lee <changhyun1.lee@samsung.com>
org.tizen.common.ui/OSGI-INF/l10n/bundle.properties
org.tizen.common.ui/plugin.xml
org.tizen.common.ui/src/org/tizen/common/ui/decorators/ImageFileDecorator.java [new file with mode: 0644]
org.tizen.common.ui/src/org/tizen/common/ui/decorators/ReferencedProjectDecorator.java [moved from org.tizen.common/src/org/tizen/common/ui/LightweightProjectDecorator.java with 89% similarity]
org.tizen.common/OSGI-INF/l10n/bundle.properties
org.tizen.common/plugin.xml

index bc53f16..f24342d 100644 (file)
@@ -2,4 +2,6 @@ Bundle-Vendor = The Linux Foundation
 Bundle-Name = Tizen Common UI
 wizard.preferences.name = Wizard
 extension-point.commandbar = Command Bar Extension
-extension-point.tipoftheday = Tip of the day Extension
\ No newline at end of file
+extension-point.tipoftheday = Tip of the day Extension
+decorator.imagefile.label = Image File Decorator
+decorator.referencedproject.label = Referenced Project Decorator
\ No newline at end of file
index fb9f50e..b2910cc 100644 (file)
              file="resources/tips/csseditor.html">\r
        </tip>\r
     </extension>\r
+    <extension\r
+          point="org.eclipse.ui.decorators">\r
+       <decorator\r
+             class="org.tizen.common.ui.decorators.ReferencedProjectDecorator"\r
+             id="org.tizen.common.ui.decorator.projectdecorator"\r
+             label="%decorator.referencedproject.label"\r
+             lightweight="true"\r
+             state="true">\r
+          <description>\r
+             Indicates whether a project is referenced\r
+          </description>\r
+          <enablement>\r
+             <objectClass\r
+                   name="org.eclipse.core.resources.IProject">\r
+             </objectClass>\r
+          </enablement>\r
+       </decorator>\r
+       <decorator\r
+             class="org.tizen.common.ui.decorators.ImageFileDecorator"\r
+             id="org.tizen.common.ui.decorators.ImageFileDecorator"\r
+             label="%decorator.imagefile.label"\r
+             lightweight="true"\r
+             location="REPLACE"\r
+             state="true">\r
+          <enablement>\r
+             <and>\r
+                <objectClass\r
+                      name="org.eclipse.core.resources.IFile">\r
+                </objectClass>\r
+                <or>\r
+                   <objectState\r
+                         name="name"\r
+                         value="*.png">\r
+                   </objectState>\r
+                   <objectState\r
+                         name="name"\r
+                         value="*.jpg">\r
+                   </objectState>\r
+                   <objectState\r
+                         name="name"\r
+                         value="*.jpeg">\r
+                   </objectState>\r
+                   <objectState\r
+                         name="name"\r
+                         value="*.gif">\r
+                   </objectState>\r
+                   <objectState\r
+                         name="name"\r
+                         value="*.bmp">\r
+                   </objectState>\r
+                </or>\r
+             </and>\r
+          </enablement>\r
+       </decorator>\r
+    </extension>\r
 </plugin>\r
diff --git a/org.tizen.common.ui/src/org/tizen/common/ui/decorators/ImageFileDecorator.java b/org.tizen.common.ui/src/org/tizen/common/ui/decorators/ImageFileDecorator.java
new file mode 100644 (file)
index 0000000..0604eef
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Common ui
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.common.ui.decorators;
+
+import java.awt.image.BufferedImage;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.core.resources.IFile;
+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;
+import org.eclipse.jface.viewers.IDecoration;
+import org.eclipse.jface.viewers.IDecorationContext;
+import org.eclipse.jface.viewers.ILightweightLabelDecorator;
+import org.eclipse.swt.graphics.Image;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.CommonPlugin;
+import org.tizen.common.util.ImageUtil;
+import org.tizen.common.util.SWTUtil;
+
+/**
+ * ImageFileDecorator.
+ * 
+ * Icon file preview in Project Explorer and Package Explorer.
+ * 
+ * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core)
+ */
+public class ImageFileDecorator extends BaseLabelProvider implements ILightweightLabelDecorator, IResourceChangeListener {
+
+    protected final Logger logger = LoggerFactory.getLogger( getClass() );
+
+    public static final String IMAGE_FILE_DECORATOR_ID = "org.tizen.common.ui.decorators.ImageFileDecorator";
+
+    public static final int IMAGE_FILE_WIDTH = 16;
+    public static final int IMAGE_FILE_HEIGHT = 16;
+
+    private static HashMap<IFile, Image> decoratedImageFiles = new HashMap<IFile, Image>();
+
+    public ImageFileDecorator() {
+        ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+    }
+
+    @Override
+    public void dispose() {
+        ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+        for ( Image image : decoratedImageFiles.values()) {
+            SWTUtil.tryDispose(image);
+        }
+        super.dispose();
+    }
+
+    /* Implement for ILightweightLabelDecorator */
+    @Override
+    public void decorate(Object element, IDecoration decoration) {
+        IFile file = ((IFile) element);
+        if ( !file.exists() ) {
+            decoratedImageFiles.remove(file);
+            return;
+        }
+
+        Image image = decoratedImageFiles.get(file);
+        if ( image == null ) {
+            BufferedImage bImage = null;
+            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 ) {
+                logger.error( "Invalid image file: " + file.getName(), e );
+            } finally {
+                if ( bImage != null ) {
+                    bImage.flush();
+                }
+            }
+        }
+
+        if ( image != null ) {
+            ImageDescriptor imageDescriptor = ImageDescriptor.createFromImage(image);
+            IDecorationContext decorationCtx = decoration.getDecorationContext();
+            if ( decorationCtx instanceof DecorationContext ) {
+                DecorationContext decorationImpl = (DecorationContext) decorationCtx;
+                decorationImpl.putProperty(IDecoration.ENABLE_REPLACE, Boolean.TRUE);
+            }
+            decoration.addOverlay(imageDescriptor, IDecoration.REPLACE);
+
+            decoratedImageFiles.put(file, image);
+        }
+    }
+
+    /* Implement for IResourceChangeListener */
+    @Override
+    public void resourceChanged(final IResourceChangeEvent event) {
+        if ( event != null && event.getDelta() != null ) {
+            ArrayList<IFile> arrayList = new ArrayList<IFile>(decoratedImageFiles.keySet());
+            for ( IFile file : arrayList ) {
+                IResourceDelta delta = event.getDelta().findMember(file.getFullPath());
+                if ( delta != null ) {
+                    if ( delta.getKind() == IResourceDelta.REMOVED ) {
+                        SWTUtil.tryDispose(decoratedImageFiles.get(file));
+                        decoratedImageFiles.remove(file);
+                    } else {
+                        decoratedImageFiles.put(file, null);
+                        refresh();
+                    }
+                }
+            }
+        }
+    }
+
+    public void refresh() {
+        SWTUtil.asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                CommonPlugin.getDefault().getWorkbench().getDecoratorManager().update(IMAGE_FILE_DECORATOR_ID);
+            }
+        });
+    }
+
+}
@@ -1,5 +1,5 @@
 /*\r
-*  Common\r
+*  Common ui\r
 *\r
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
 *\r
@@ -23,7 +23,7 @@
 *\r
 */\r
 \r
-package org.tizen.common.ui;\r
+package org.tizen.common.ui.decorators;\r
 \r
 import org.eclipse.core.resources.IProject;\r
 import org.eclipse.jface.viewers.IDecoration;\r
@@ -34,12 +34,12 @@ import org.tizen.common.TizenProjectType;
 import org.tizen.common.util.ProjectUtil;\r
 import org.tizen.common.util.StringUtil;\r
 \r
-public class LightweightProjectDecorator implements ILightweightLabelDecorator {\r
-    private static final String SUFFIX_ROOT = " [Root]";\r
+public class ReferencedProjectDecorator implements ILightweightLabelDecorator {\r
+    //private static final String SUFFIX_ROOT = " [Root]";\r
     private static final String SUFFIX_REFERENCED = " [with %s]";\r
     //private final ImageDescriptor OVERLAY = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/lock.gif");\r
 \r
-    public LightweightProjectDecorator() {\r
+    public ReferencedProjectDecorator() {\r
         super();\r
     }\r
 \r
@@ -56,7 +56,7 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator {
             } catch (CoreException e) {\r
             }\r
             */\r
-            \r
+\r
             ITizenProject tizenProject = ProjectUtil.getTizenProject(project);\r
             if ( tizenProject == null ) {\r
                 return;\r
@@ -65,7 +65,7 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator {
             if ( projectType == null || projectType.isReferencedProject() == false ) {\r
                 return;\r
             }\r
-            \r
+\r
             IProject[] refPrjs = project.getReferencingProjects();\r
             if (refPrjs != null && refPrjs.length > 0) {\r
                 String refs = "";\r
@@ -82,8 +82,7 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator {
 \r
                     if ( StringUtil.isEmpty(refs) ) {\r
                         refs += refPrjs[i].getName();\r
-                    }\r
-                    else {\r
+                    } else {\r
                         refs += ", " + refPrjs[i].getName();\r
                     }\r
                 }\r
@@ -110,4 +109,5 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator {
     @Override\r
     public void removeListener(ILabelProviderListener listener) {\r
     }\r
+\r
 }\r
index ba94263..6d314a6 100644 (file)
@@ -26,4 +26,4 @@ preferences.logger.name = Tizen Logger
 
 extension-point.crashreporter = Crash Reporter
 extension-point.prompter = Prompter
-extension-point.project = ITizenProject Adapter
+extension-point.project = ITizenProject Adapter
\ No newline at end of file
index f8fccba..1134736 100644 (file)
           </enabledWhen>\r
       </page>\r
     </extension>\r
-    <extension\r
-         point="org.eclipse.ui.decorators">\r
-        <decorator\r
-            lightweight="true"\r
-            label="Tizen IDE Decorator"\r
-            class="org.tizen.common.ui.LightweightProjectDecorator"\r
-            state="true"\r
-            id="org.tizen.ui.decorator.projectdecorator">\r
-            <description>\r
-                Indicates whether a project is referenced\r
-            </description>\r
-            <enablement>\r
-                <objectClass name="org.eclipse.core.resources.IProject"/>\r
-            </enablement>\r
-        </decorator>\r
-    </extension>\r
     <!-- activities end -->\r
 </plugin>