Skip to main content
summaryrefslogtreecommitdiffstats
blob: ce934298392e5277cc32c1261cdea24173d7c71c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * Copyright (c) 2011 Mia-Software.
 * 
 * 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:
 * 	Nicolas Guyomar (Mia-Software) - Bug 349546 - EMF Facet facetSet editor
 *  Vincent Lorenzo (CEA-LIST) - Bug 357621 - Improve the label displayed for Customization and Facets
 */
package org.eclipse.papyrus.emf.facet.efacet.ui.internal.utils;

import java.net.URL;

import org.eclipse.papyrus.emf.facet.efacet.ui.internal.Activator;
import org.eclipse.papyrus.emf.facet.util.core.Logger;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;

public class ImageProvider {

	private static ImageProvider instance;

	public static ImageProvider getInstance() {
		if (ImageProvider.instance == null) {
			ImageProvider.instance = new ImageProvider();
		}
		return ImageProvider.instance;
	}

	private static final String QUERY_SET_ICON_PATH = "/icons/querySet.gif"; //$NON-NLS-1$
	private static final String FACET_ICON_PATH = "/icons/facet.gif"; //$NON-NLS-1$
	private static final String FLAT_VIEW_ICON_PATH = "/icons/flatView.gif"; //$NON-NLS-1$
	private static final String TREE_VIEW_ICON_PATH = "/icons/treeView.gif"; //$NON-NLS-1$

	private Image facetIcon;
	private Image queryIcon;
	private Image flatViewIcon;
	private Image treeViewIcon;

	/**
	 * Create an image descriptor from a resource
	 * 
	 * @param resourcePath
	 *            the path of the resource (in the bundle)
	 * @return the image descriptor
	 */
	private static ImageDescriptor createImageDescriptor(final String resourcePath) {
		final URL url = Activator.getDefault().getBundle().getResource(resourcePath);
		if (url == null) {
			Logger.logError(NLS.bind("Resource not found: {0}", //$NON-NLS-1$
					resourcePath), Activator.getDefault());
			return ImageDescriptor.getMissingImageDescriptor();
		}
		return ImageDescriptor.createFromURL(url);
	}

	/** Return the icon representing a query */
	public Image getFacetIcon() {
		if (this.facetIcon == null) {
			this.facetIcon = createImageDescriptor(ImageProvider.FACET_ICON_PATH).createImage();
		}
		return this.facetIcon;
	}

	/** Return the descriptor representing a query */
	public static ImageDescriptor getFacetIconDescriptor() {
		return createImageDescriptor(ImageProvider.FACET_ICON_PATH);
	}

	/** Return the icon representing a querySet */
	public Image getQuerySetIcon() {
		if (this.queryIcon == null) {
			this.queryIcon = createImageDescriptor(ImageProvider.QUERY_SET_ICON_PATH).createImage();
		}
		return this.queryIcon;
	}
	
	public Image getFlatViewIcon(){
		if (this.flatViewIcon == null) {
			this.flatViewIcon = createImageDescriptor(ImageProvider.FLAT_VIEW_ICON_PATH).createImage();
		}
		return this.flatViewIcon;
	}
	public Image getTreeViewIcon(){
		if (this.treeViewIcon == null) {
			this.treeViewIcon = createImageDescriptor(ImageProvider.TREE_VIEW_ICON_PATH).createImage();
		}
		return this.treeViewIcon;
	}

}

Back to the top