Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2011, 2013 Ericsson |
013a5f1c | 3 | * |
12c155f5 FC |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
013a5f1c | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
ab37ff41 | 11 | * Patrick Tasse - Add support for unknown trace type icon |
12c155f5 FC |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
15 | ||
16 | import java.net.URL; | |
17 | ||
18 | import org.eclipse.core.runtime.CoreException; | |
19 | import org.eclipse.core.runtime.Platform; | |
20 | import org.eclipse.jface.resource.ImageDescriptor; | |
21 | import org.eclipse.jface.viewers.ILabelProviderListener; | |
8fd82db5 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
e12ecd30 | 23 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
12c155f5 FC |
24 | import org.eclipse.swt.graphics.Image; |
25 | import org.eclipse.ui.IMemento; | |
26 | import org.eclipse.ui.ISharedImages; | |
27 | import org.eclipse.ui.PlatformUI; | |
28 | import org.eclipse.ui.navigator.ICommonContentExtensionSite; | |
29 | import org.eclipse.ui.navigator.ICommonLabelProvider; | |
30 | import org.osgi.framework.Bundle; | |
31 | ||
32 | /** | |
013a5f1c | 33 | * The TMF project label provider for the tree viewer in the project explorer view. |
12c155f5 | 34 | * <p> |
b544077e BH |
35 | * @version 1.0 |
36 | * @author Francois Chouinard | |
12c155f5 FC |
37 | */ |
38 | public class TmfNavigatorLabelProvider implements ICommonLabelProvider { | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Constants | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
5a5c2fc7 FC |
44 | private static final Image fFolderIcon = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); |
45 | private static final String fTraceIconFile = "icons/elcl16/trace.gif"; //$NON-NLS-1$ | |
ab37ff41 | 46 | private static final String fUnknownIconFile = "icons/elcl16/unknown_parser.gif"; //$NON-NLS-1$ |
5a5c2fc7 | 47 | private static final String fExperimentIconFile = "icons/elcl16/experiment.gif"; //$NON-NLS-1$ |
12c155f5 FC |
48 | |
49 | // ------------------------------------------------------------------------ | |
50 | // Attributes | |
51 | // ------------------------------------------------------------------------ | |
52 | ||
53 | private final Image fTraceFolderIcon = fFolderIcon; | |
54 | private final Image fExperimentFolderIcon = fFolderIcon; | |
55 | ||
56 | private final Image fDefaultTraceIcon; | |
ab37ff41 | 57 | private final Image fUnknownTraceIcon; |
12c155f5 FC |
58 | private final Image fExperimentIcon; |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Constructors | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
b544077e | 64 | /** |
013a5f1c AM |
65 | * Constructor. |
66 | * | |
b544077e BH |
67 | * Creates the TMF navigator content provider. |
68 | */ | |
12c155f5 | 69 | public TmfNavigatorLabelProvider() { |
8fd82db5 | 70 | Bundle bundle = Activator.getDefault().getBundle(); |
12c155f5 | 71 | fDefaultTraceIcon = loadIcon(bundle, fTraceIconFile); |
ab37ff41 | 72 | fUnknownTraceIcon = loadIcon(bundle, fUnknownIconFile); |
12c155f5 FC |
73 | fExperimentIcon = loadIcon(bundle, fExperimentIconFile); |
74 | } | |
75 | ||
abbdd66a | 76 | private static Image loadIcon(Bundle bundle, String url) { |
8fd82db5 | 77 | Activator plugin = Activator.getDefault(); |
12c155f5 FC |
78 | String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$ |
79 | Image icon = plugin.getImageRegistry().get(key); | |
80 | if (icon == null) { | |
81 | URL imageURL = bundle.getResource(url); | |
82 | ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); | |
83 | icon = descriptor.createImage(); | |
84 | plugin.getImageRegistry().put(key, icon); | |
85 | } | |
86 | return icon; | |
87 | } | |
88 | ||
89 | // ------------------------------------------------------------------------ | |
90 | // ICommonLabelProvider | |
91 | // ------------------------------------------------------------------------ | |
b544077e BH |
92 | /* |
93 | * (non-Javadoc) | |
94 | * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) | |
95 | */ | |
12c155f5 FC |
96 | @Override |
97 | public Image getImage(Object element) { | |
98 | ||
99 | if (element instanceof TmfTraceElement) { | |
100 | TmfTraceElement trace = (TmfTraceElement) element; | |
12c155f5 | 101 | try { |
ab37ff41 PT |
102 | if (trace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE) == null) { |
103 | return fUnknownTraceIcon; | |
104 | } | |
e12ecd30 | 105 | String name = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEBUNDLE); |
ab37ff41 | 106 | String icon = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEICON); |
12c155f5 FC |
107 | if (name != null && icon != null) { |
108 | Bundle bundle = Platform.getBundle(name); | |
109 | return loadIcon(bundle, icon); | |
110 | } | |
111 | } catch (CoreException e) { | |
112 | } | |
113 | return fDefaultTraceIcon; | |
114 | } | |
115 | ||
013a5f1c | 116 | if (element instanceof TmfExperimentElement) { |
12c155f5 | 117 | return fExperimentIcon; |
013a5f1c | 118 | } |
12c155f5 | 119 | |
013a5f1c | 120 | if (element instanceof TmfExperimentFolder) { |
12c155f5 | 121 | return fExperimentFolderIcon; |
013a5f1c | 122 | } |
12c155f5 | 123 | |
013a5f1c | 124 | if (element instanceof TmfTraceFolder) { |
12c155f5 | 125 | return fTraceFolderIcon; |
013a5f1c | 126 | } |
12c155f5 FC |
127 | |
128 | return null; | |
129 | } | |
130 | ||
b544077e BH |
131 | /* |
132 | * (non-Javadoc) | |
133 | * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) | |
134 | */ | |
12c155f5 FC |
135 | @Override |
136 | public String getText(Object element) { | |
137 | ||
138 | if (element instanceof TmfTraceFolder) { | |
139 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
140 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$ | |
141 | } | |
142 | ||
143 | if (element instanceof TmfExperimentElement) { | |
144 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
145 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$ | |
146 | } | |
147 | ||
7d3950f5 FC |
148 | if (element instanceof TmfExperimentFolder) { |
149 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
150 | return folder.getName() + " [" + folder.getChildren().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$ | |
151 | } | |
152 | ||
12c155f5 FC |
153 | // Catch all |
154 | if (element instanceof ITmfProjectModelElement) { | |
155 | return ((ITmfProjectModelElement) element).getName(); | |
156 | } | |
157 | ||
158 | return null; | |
159 | } | |
160 | ||
b544077e BH |
161 | /* |
162 | * (non-Javadoc) | |
163 | * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) | |
164 | */ | |
12c155f5 FC |
165 | @Override |
166 | public void addListener(ILabelProviderListener listener) { | |
167 | } | |
168 | ||
b544077e BH |
169 | /* |
170 | * (non-Javadoc) | |
171 | * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() | |
172 | */ | |
12c155f5 FC |
173 | @Override |
174 | public void dispose() { | |
175 | } | |
176 | ||
b544077e BH |
177 | /* |
178 | * (non-Javadoc) | |
179 | * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) | |
180 | */ | |
12c155f5 FC |
181 | @Override |
182 | public boolean isLabelProperty(Object element, String property) { | |
183 | return false; | |
184 | } | |
185 | ||
b544077e BH |
186 | /* |
187 | * (non-Javadoc) | |
188 | * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) | |
189 | */ | |
12c155f5 FC |
190 | @Override |
191 | public void removeListener(ILabelProviderListener listener) { | |
192 | } | |
193 | ||
b544077e BH |
194 | /* |
195 | * (non-Javadoc) | |
196 | * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento) | |
197 | */ | |
12c155f5 FC |
198 | @Override |
199 | public void restoreState(IMemento aMemento) { | |
200 | } | |
201 | ||
b544077e BH |
202 | /* |
203 | * (non-Javadoc) | |
204 | * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento) | |
205 | */ | |
12c155f5 FC |
206 | @Override |
207 | public void saveState(IMemento aMemento) { | |
208 | } | |
209 | ||
b544077e BH |
210 | /* |
211 | * (non-Javadoc) | |
212 | * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object) | |
213 | */ | |
12c155f5 FC |
214 | @Override |
215 | public String getDescription(Object anElement) { | |
216 | return getText(anElement); | |
217 | } | |
218 | ||
b544077e BH |
219 | /* |
220 | * (non-Javadoc) | |
221 | * @see org.eclipse.ui.navigator.ICommonLabelProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) | |
222 | */ | |
12c155f5 FC |
223 | @Override |
224 | public void init(ICommonContentExtensionSite aConfig) { | |
225 | } | |
226 | ||
227 | } |