Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Gabel2016-07-11 03:30:15 -0400
committerBenoit Maggi2016-09-23 05:36:51 -0400
commit20ea5e15ee2cbe80f582580f64a2a5bf97fa157c (patch)
tree3798d7844ef91fee3f9749d4f4f59bb10bf570d6 /plugins/facet
parentad115490043a3867ab70a2bc9485bf8739cf292d (diff)
downloadorg.eclipse.papyrus-20ea5e15ee2cbe80f582580f64a2a5bf97fa157c.tar.gz
org.eclipse.papyrus-20ea5e15ee2cbe80f582580f64a2a5bf97fa157c.tar.xz
org.eclipse.papyrus-20ea5e15ee2cbe80f582580f64a2a5bf97fa157c.zip
Bug 497505: [EMF Facet] Use default ImageDescriptor in ImageManager
class Change-Id: I71e387867028962a3ff209810da36b8b0e25104f Signed-off-by: Sebastien Gabel <sebastien.gabel@esterel-technologies.com> Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Diffstat (limited to 'plugins/facet')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ImageManager.java203
1 files changed, 105 insertions, 98 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ImageManager.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ImageManager.java
index 10708ebd87c..14a7d4c6329 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ImageManager.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ImageManager.java
@@ -1,98 +1,105 @@
-/*******************************************************************************
- * Copyright (c) 2013 Soft-Maint.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * David Couvrand (Soft-Maint) - Bug 418418 - [Customization] Overlay icons not implemented
- * Thomas Cicognani (Soft-Maint) - Bug 424414 - ImageManager doesn't cache images
- *******************************************************************************/
-package org.eclipse.papyrus.emf.facet.custom.ui.internal;
-
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.emf.facet.custom.metamodel.custompt.IImage;
-import org.eclipse.papyrus.emf.facet.custom.ui.internal.custompt.ImageWrapper;
-import org.eclipse.papyrus.emf.facet.custom.ui.internal.custompt.URIImage;
-import org.eclipse.papyrus.emf.facet.util.core.Logger;
-import org.eclipse.papyrus.emf.facet.util.swt.imageprovider.IImageProvider;
-import org.eclipse.papyrus.emf.facet.util.swt.imageprovider.IImageProviderFactory;
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.PlatformUI;
-import org.osgi.framework.Bundle;
-
-public class ImageManager {
-
- private final Map<String, ImageDescriptor> uriImageCache = new HashMap<String, ImageDescriptor>();
-
- private Image getImage(final URIImage uriImage) {
- Image result;
- final String uriStr = uriImage.getUri();
- ImageDescriptor imageDescriptor;
- if (this.uriImageCache.keySet().contains(uriStr)) {
- imageDescriptor = this.uriImageCache.get(uriStr);
- } else {
- imageDescriptor = createImageDescriptor(uriStr);
- this.uriImageCache.put(uriStr, imageDescriptor);
- }
- final IImageProvider imageProvider = IImageProviderFactory.DEFAULT
- .createIImageProvider(Activator.getDefault());
- result = imageProvider.getImage(imageDescriptor);
- return result;
- }
-
-
- private ImageDescriptor createImageDescriptor(final String uriStr) {
- ImageDescriptor imgDecriptor;
- final URI uri = URI.createURI(uriStr);
- final String bundleId = uri.segment(1);
- final Bundle bundle = Platform.getBundle(bundleId);
- final URI baseURI = URI.createPlatformPluginURI(bundleId + '/',
- false);
- final String resourcePath = uri.deresolve(baseURI).toString();
- final URL url = bundle.getResource(resourcePath);
-
- if (url == null) {
- Logger.logError(NLS.bind("Resource not found: {0}", //$NON-NLS-1$
- resourcePath), Activator.getDefault());
- imgDecriptor = ImageDescriptor.getMissingImageDescriptor();
- } else {
- imgDecriptor = ImageDescriptor.createFromURL(url);
- }
- return imgDecriptor;
- }
-
-
- public Image getImage(final IImage image) {
- Image result = null;
- final Device device = PlatformUI.getWorkbench().getDisplay();
- if (image instanceof ImageWrapper) {
- final ImageWrapper wrapper = (ImageWrapper) image;
- result = wrapper.getImage();
- } else if (image instanceof URIImage) {
- final URIImage uriImage = (URIImage) image;
- result = getImage(uriImage);
- } else if (image != null) {
- result = new Image(device, image.getInputStream());
- }
- return result;
- }
-
- public ImageDescriptor getImageDescriptor(final IImage image) {
- ImageDescriptor result = null;
- if (image instanceof URIImage) {
- final URIImage uriImage = (URIImage) image;
- result = createImageDescriptor(uriImage.getUri());
- }
- return result;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2013, 2016 Soft-Maint, Esterel Technologies SAS and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Couvrand (Soft-Maint) - Bug 418418 - [Customization] Overlay icons not implemented
+ * Thomas Cicognani (Soft-Maint) - Bug 424414 - ImageManager doesn't cache images
+ * Nicolas Boulay (Esterel Technologies SAS) - Bug 497505
+ *
+ *******************************************************************************/
+package org.eclipse.papyrus.emf.facet.custom.ui.internal;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.emf.facet.custom.metamodel.custompt.IImage;
+import org.eclipse.papyrus.emf.facet.custom.ui.internal.custompt.ImageWrapper;
+import org.eclipse.papyrus.emf.facet.custom.ui.internal.custompt.URIImage;
+import org.eclipse.papyrus.emf.facet.util.core.Logger;
+import org.eclipse.papyrus.emf.facet.util.swt.imageprovider.IImageProvider;
+import org.eclipse.papyrus.emf.facet.util.swt.imageprovider.IImageProviderFactory;
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PlatformUI;
+import org.osgi.framework.Bundle;
+
+public class ImageManager {
+
+ private final Map<String, ImageDescriptor> uriImageCache = new HashMap<String, ImageDescriptor>();
+
+ private Image getImage(final URIImage uriImage) {
+ Image result;
+ final String uriStr = uriImage.getUri();
+ ImageDescriptor imageDescriptor;
+ if (this.uriImageCache.keySet().contains(uriStr)) {
+ imageDescriptor = this.uriImageCache.get(uriStr);
+ } else {
+ imageDescriptor = createImageDescriptor(uriStr);
+ this.uriImageCache.put(uriStr, imageDescriptor);
+ }
+ final IImageProvider imageProvider = IImageProviderFactory.DEFAULT
+ .createIImageProvider(Activator.getDefault());
+ result = imageProvider.getImage(imageDescriptor);
+ return result;
+ }
+
+
+ private ImageDescriptor createImageDescriptor(final String uriStr) {
+ ImageDescriptor imgDecriptor;
+ if (uriStr == null || "".equals(uriStr) ) {
+ imgDecriptor = ImageDescriptor.getMissingImageDescriptor();
+ } else {
+ final URI uri = URI.createURI(uriStr);
+ final String bundleId = uri.segment(1);
+ final Bundle bundle = Platform.getBundle(bundleId);
+ final URI baseURI = URI.createPlatformPluginURI(bundleId + '/',
+ false);
+ final String resourcePath = uri.deresolve(baseURI).toString();
+ final URL url = bundle.getResource(resourcePath);
+
+ if (url == null) {
+ Logger.logError(NLS.bind("Resource not found: {0}", //$NON-NLS-1$
+ resourcePath), Activator.getDefault());
+ imgDecriptor = ImageDescriptor.getMissingImageDescriptor();
+ } else {
+ imgDecriptor = ImageDescriptor.createFromURL(url);
+ }
+ }
+ return imgDecriptor;
+ }
+
+
+ public Image getImage(final IImage image) {
+ Image result = null;
+ final Device device = PlatformUI.getWorkbench().getDisplay();
+ if (image instanceof ImageWrapper) {
+ final ImageWrapper wrapper = (ImageWrapper) image;
+ result = wrapper.getImage();
+ } else if (image instanceof URIImage) {
+ final URIImage uriImage = (URIImage) image;
+ result = getImage(uriImage);
+ } else if (image != null) {
+ result = new Image(device, image.getInputStream());
+ }
+ return result;
+ }
+
+ public ImageDescriptor getImageDescriptor(final IImage image) {
+ ImageDescriptor result = null;
+ if (image instanceof URIImage) {
+ final URIImage uriImage = (URIImage) image;
+ result = createImageDescriptor(uriImage.getUri());
+ }
+ return result;
+ }
+}

Back to the top