Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProvider.java64
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProviderFactory.java37
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/Activator.java50
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProvider.java70
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProviderFactory.java34
5 files changed, 255 insertions, 0 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProvider.java
new file mode 100644
index 00000000000..d8c89579655
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProvider.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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:
+ * Thomas Cicognani (Soft-Maint) - Bug 424416 - Plug-in for JFace Utilities
+ ******************************************************************************/
+
+package org.eclipse.emf.facet.util.jface.ui.imageprovider;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.DecorationOverlayIcon;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * JFace Image Provider
+ *
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @since 0.4.0
+ */
+public interface IImageProvider {
+
+ /**
+ * Return an image from an Overlay Icon description.
+ *
+ * @param imgDescriptor
+ * Overlay Icon description
+ * @return A new image
+ */
+ Image getImage(DecorationOverlayIcon imgDescriptor);
+
+ /**
+ * Return an image from its path
+ *
+ * @param path
+ * The path of the image
+ * @return A new image
+ */
+ Image getImage(String path);
+
+ /**
+ * Return an image descriptor from its path
+ *
+ * @param resourcePath
+ * The path from which to create the descriptor
+ * @return The new image descriptor
+ */
+ ImageDescriptor createImageDescriptor(String resourcePath);
+
+ /**
+ * Return an image from an image descriptor
+ *
+ * @param imgDescriptor
+ * An image descriptor to create the image
+ * @return A new image
+ */
+ Image getImage(ImageDescriptor imgDescriptor);
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProviderFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProviderFactory.java
new file mode 100644
index 00000000000..07f9deb1e81
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/imageprovider/IImageProviderFactory.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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:
+ * Thomas Cicognani (Soft-Maint) - Bug 424416 - Plug-in for JFace Utilities
+ ******************************************************************************/
+package org.eclipse.emf.facet.util.jface.ui.imageprovider;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.emf.facet.util.jface.ui.internal.imageprovider.ImageProviderFactory;
+
+/**
+ * JFace Image Provider Factory
+ *
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @since 0.4.0
+ */
+public interface IImageProviderFactory {
+
+ IImageProviderFactory DEFAULT = new ImageProviderFactory();
+
+ /**
+ * Create a new Image Provider Factory. Factories are cached with plugin
+ * instances.
+ *
+ * @param plugin
+ * Current plugin which wants an image provider
+ * @return An image provider factory
+ */
+ IImageProvider createIImageProvider(Plugin plugin);
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/Activator.java
new file mode 100644
index 00000000000..70b206ff1fa
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/Activator.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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:
+ * Thomas Cicognani (Soft-Maint) - Bug 424416 - Plug-in for JFace Utilities
+ ******************************************************************************/
+package org.eclipse.emf.facet.util.jface.ui.internal;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+@SuppressWarnings("PMD.UseSingleton")
+//@SuppressWarnings("PMD.UseSingleton") We cannot conforms to this rule because
+//this class is an Eclipse plug-in activator which will be instantiated by the
+//Eclipse framework.
+public class Activator extends Plugin {
+
+ private static Activator plugin;
+
+ @Override
+ @SuppressWarnings("PMD.SignatureDeclareThrowsException")
+ // @SuppressWarnings("PMD.SignatureDeclareThrowsException") We have to use
+ // this signature because this is an override of an Eclipse framework's
+ // method.
+ public void start(final BundleContext bundleContext) throws Exception {
+ super.start(bundleContext);
+ Activator.plugin = this;
+ }
+
+ @Override
+ @SuppressWarnings("PMD.SignatureDeclareThrowsException")
+ // @SuppressWarnings("PMD.SignatureDeclareThrowsException") We have to use
+ // this signature because this is an override of an Eclipse framework's
+ // method.
+ public void stop(final BundleContext bundleContext) throws Exception {
+ // NOPMD: PMD say "Assigning an Object to null is a code smell."
+ // No choice to right it in another way : this is an Eclipse pattern.
+ Activator.plugin = null; // NOPMD by gdupe on 30/03/12 10:19
+ super.stop(bundleContext);
+ }
+
+ public static Plugin getDefault() {
+ return Activator.plugin;
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProvider.java
new file mode 100644
index 00000000000..b3a70b1c768
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProvider.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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:
+ * Thomas Cicognani (Soft-Maint) - Bug 424416 - Plug-in for JFace Utilities
+ ******************************************************************************/
+
+package org.eclipse.emf.facet.util.jface.ui.internal.imageprovider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.emf.facet.util.core.DebugUtils;
+import org.eclipse.emf.facet.util.jface.ui.imageprovider.IImageProvider;
+import org.eclipse.emf.facet.util.jface.ui.internal.Activator;
+import org.eclipse.emf.facet.util.swt.imageprovider.IImageProviderFactory;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.DecorationOverlayIcon;
+import org.eclipse.swt.graphics.Image;
+import org.osgi.framework.Bundle;
+
+public final class ImageProvider implements IImageProvider {
+
+ private static final boolean DEBUG = DebugUtils.getDebugStatus(Activator
+ .getDefault());
+ private final Map<Object, Image> map = new HashMap<Object, Image>();
+ private final Plugin plugin;
+ private final org.eclipse.emf.facet.util.swt.imageprovider.IImageProvider delegate;
+
+ ImageProvider(final Plugin plugin) {
+ this.plugin = plugin;
+ this.delegate = IImageProviderFactory.DEFAULT
+ .createIImageProvider(plugin);
+ }
+
+ public Image getImage(final DecorationOverlayIcon imgDescriptor) {
+ Image result = this.map.get(imgDescriptor);
+ if (result == null) {
+ result = imgDescriptor.createImage();
+ this.map.put(imgDescriptor, result);
+ if (DEBUG) {
+ final Bundle bundle = this.plugin.getBundle();
+ final String bundleId = bundle.getSymbolicName();
+ final String message = String.format(
+ "New image loaded from an overlay icon (bundle=%s)", //$NON-NLS-1$
+ bundleId);
+ DebugUtils.debug(message);
+ }
+ }
+ return result;
+ }
+
+ public Image getImage(final String path) {
+ return this.delegate.getImage(path);
+ }
+
+ public ImageDescriptor createImageDescriptor(final String resourcePath) {
+ return this.delegate.createImageDescriptor(resourcePath);
+ }
+
+ public Image getImage(final ImageDescriptor imgDescriptor) {
+ return this.delegate.getImage(imgDescriptor);
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProviderFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProviderFactory.java
new file mode 100644
index 00000000000..d5d6f6e6a40
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.util.jface.ui/src/org/eclipse/emf/facet/util/jface/ui/internal/imageprovider/ImageProviderFactory.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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:
+ * Thomas Cicognani (Soft-Maint) - Bug 424416 - Plug-in for JFace Utilities
+ ******************************************************************************/
+package org.eclipse.emf.facet.util.jface.ui.internal.imageprovider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.emf.facet.util.jface.ui.imageprovider.IImageProvider;
+import org.eclipse.emf.facet.util.jface.ui.imageprovider.IImageProviderFactory;
+
+public class ImageProviderFactory implements IImageProviderFactory {
+
+ private final Map<Plugin, IImageProvider> map = new HashMap<Plugin, IImageProvider>();
+
+ public IImageProvider createIImageProvider(final Plugin plugin) {
+ IImageProvider result = this.map.get(plugin);
+ if (result == null) {
+ result = new ImageProvider(plugin);
+ this.map.put(plugin, result);
+ }
+ return result;
+ }
+
+}

Back to the top