From dd780b9d505bb7c2be6e718cd2ff66921bd87367 Mon Sep 17 00:00:00 2001 From: "changhyun1.lee" Date: Thu, 14 Nov 2013 20:28:14 +0900 Subject: [PATCH] EXPLORER: Added image file thumbnail in Project Explorer and Package Explorer image file thumbnail in Project Explorer Change-Id: I731591d94b514859513dfc66c10c468115e30cd1 Signed-off-by: changhyun1.lee --- .../OSGI-INF/l10n/bundle.properties | 4 +- org.tizen.common.ui/plugin.xml | 55 ++++++++ .../common/ui/decorators/ImageFileDecorator.java | 151 +++++++++++++++++++++ .../ui/decorators/ReferencedProjectDecorator.java | 18 +-- org.tizen.common/OSGI-INF/l10n/bundle.properties | 2 +- org.tizen.common/plugin.xml | 16 --- 6 files changed, 219 insertions(+), 27 deletions(-) create mode 100644 org.tizen.common.ui/src/org/tizen/common/ui/decorators/ImageFileDecorator.java rename org.tizen.common/src/org/tizen/common/ui/LightweightProjectDecorator.java => org.tizen.common.ui/src/org/tizen/common/ui/decorators/ReferencedProjectDecorator.java (89%) diff --git a/org.tizen.common.ui/OSGI-INF/l10n/bundle.properties b/org.tizen.common.ui/OSGI-INF/l10n/bundle.properties index bc53f16..f24342d 100644 --- a/org.tizen.common.ui/OSGI-INF/l10n/bundle.properties +++ b/org.tizen.common.ui/OSGI-INF/l10n/bundle.properties @@ -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 diff --git a/org.tizen.common.ui/plugin.xml b/org.tizen.common.ui/plugin.xml index fb9f50e..b2910cc 100644 --- a/org.tizen.common.ui/plugin.xml +++ b/org.tizen.common.ui/plugin.xml @@ -121,4 +121,59 @@ file="resources/tips/csseditor.html"> + + + + Indicates whether a project is referenced + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 index 0000000..0604eef --- /dev/null +++ b/org.tizen.common.ui/src/org/tizen/common/ui/decorators/ImageFileDecorator.java @@ -0,0 +1,151 @@ +/* + * Common ui + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Changhyun Lee + * Kangho Kim + * Hyeongseok Heo + * + * 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 } (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 decoratedImageFiles = new HashMap(); + + 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 arrayList = new ArrayList(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); + } + }); + } + +} diff --git a/org.tizen.common/src/org/tizen/common/ui/LightweightProjectDecorator.java b/org.tizen.common.ui/src/org/tizen/common/ui/decorators/ReferencedProjectDecorator.java similarity index 89% rename from org.tizen.common/src/org/tizen/common/ui/LightweightProjectDecorator.java rename to org.tizen.common.ui/src/org/tizen/common/ui/decorators/ReferencedProjectDecorator.java index 774a368..5f69622 100644 --- a/org.tizen.common/src/org/tizen/common/ui/LightweightProjectDecorator.java +++ b/org.tizen.common.ui/src/org/tizen/common/ui/decorators/ReferencedProjectDecorator.java @@ -1,5 +1,5 @@ /* -* Common +* Common ui * * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * @@ -23,7 +23,7 @@ * */ -package org.tizen.common.ui; +package org.tizen.common.ui.decorators; import org.eclipse.core.resources.IProject; import org.eclipse.jface.viewers.IDecoration; @@ -34,12 +34,12 @@ import org.tizen.common.TizenProjectType; import org.tizen.common.util.ProjectUtil; import org.tizen.common.util.StringUtil; -public class LightweightProjectDecorator implements ILightweightLabelDecorator { - private static final String SUFFIX_ROOT = " [Root]"; +public class ReferencedProjectDecorator implements ILightweightLabelDecorator { + //private static final String SUFFIX_ROOT = " [Root]"; private static final String SUFFIX_REFERENCED = " [with %s]"; //private final ImageDescriptor OVERLAY = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/lock.gif"); - public LightweightProjectDecorator() { + public ReferencedProjectDecorator() { super(); } @@ -56,7 +56,7 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator { } catch (CoreException e) { } */ - + ITizenProject tizenProject = ProjectUtil.getTizenProject(project); if ( tizenProject == null ) { return; @@ -65,7 +65,7 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator { if ( projectType == null || projectType.isReferencedProject() == false ) { return; } - + IProject[] refPrjs = project.getReferencingProjects(); if (refPrjs != null && refPrjs.length > 0) { String refs = ""; @@ -82,8 +82,7 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator { if ( StringUtil.isEmpty(refs) ) { refs += refPrjs[i].getName(); - } - else { + } else { refs += ", " + refPrjs[i].getName(); } } @@ -110,4 +109,5 @@ public class LightweightProjectDecorator implements ILightweightLabelDecorator { @Override public void removeListener(ILabelProviderListener listener) { } + } diff --git a/org.tizen.common/OSGI-INF/l10n/bundle.properties b/org.tizen.common/OSGI-INF/l10n/bundle.properties index ba94263..6d314a6 100644 --- a/org.tizen.common/OSGI-INF/l10n/bundle.properties +++ b/org.tizen.common/OSGI-INF/l10n/bundle.properties @@ -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 diff --git a/org.tizen.common/plugin.xml b/org.tizen.common/plugin.xml index f8fccba..1134736 100644 --- a/org.tizen.common/plugin.xml +++ b/org.tizen.common/plugin.xml @@ -392,21 +392,5 @@ - - - - Indicates whether a project is referenced - - - - - - -- 2.7.4