Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2011, 2014 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; | |
efd33708 | 19 | import org.eclipse.core.runtime.IConfigurationElement; |
12c155f5 FC |
20 | import org.eclipse.core.runtime.Platform; |
21 | import org.eclipse.jface.resource.ImageDescriptor; | |
d5278aa5 | 22 | import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; |
12c155f5 | 23 | import org.eclipse.jface.viewers.ILabelProviderListener; |
d5278aa5 GB |
24 | import org.eclipse.jface.viewers.StyledString; |
25 | import org.eclipse.jface.viewers.StyledString.Styler; | |
8fd82db5 | 26 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
e12ecd30 | 27 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
2d64a788 | 28 | import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; |
50a41a0d | 29 | import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType.TraceElementType; |
12c155f5 FC |
30 | import org.eclipse.swt.graphics.Image; |
31 | import org.eclipse.ui.IMemento; | |
32 | import org.eclipse.ui.ISharedImages; | |
33 | import org.eclipse.ui.PlatformUI; | |
09b9832c | 34 | import org.eclipse.ui.model.WorkbenchLabelProvider; |
12c155f5 FC |
35 | import org.eclipse.ui.navigator.ICommonContentExtensionSite; |
36 | import org.eclipse.ui.navigator.ICommonLabelProvider; | |
37 | import org.osgi.framework.Bundle; | |
38 | ||
39 | /** | |
013a5f1c | 40 | * The TMF project label provider for the tree viewer in the project explorer view. |
12c155f5 | 41 | * <p> |
b544077e BH |
42 | * @version 1.0 |
43 | * @author Francois Chouinard | |
12c155f5 | 44 | */ |
d5278aa5 | 45 | public class TmfNavigatorLabelProvider implements ICommonLabelProvider, IStyledLabelProvider { |
12c155f5 FC |
46 | |
47 | // ------------------------------------------------------------------------ | |
48 | // Constants | |
49 | // ------------------------------------------------------------------------ | |
50 | ||
5a5c2fc7 FC |
51 | private static final Image fFolderIcon = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); |
52 | private static final String fTraceIconFile = "icons/elcl16/trace.gif"; //$NON-NLS-1$ | |
53 | private static final String fExperimentIconFile = "icons/elcl16/experiment.gif"; //$NON-NLS-1$ | |
c068a752 GB |
54 | private static final String fAnalysisIconFile = "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$ |
55 | private static final String fViewIconFile = "icons/obj16/node_obj.gif"; //$NON-NLS-1$ | |
12c155f5 FC |
56 | |
57 | // ------------------------------------------------------------------------ | |
58 | // Attributes | |
59 | // ------------------------------------------------------------------------ | |
60 | ||
61 | private final Image fTraceFolderIcon = fFolderIcon; | |
62 | private final Image fExperimentFolderIcon = fFolderIcon; | |
63 | ||
64 | private final Image fDefaultTraceIcon; | |
65 | private final Image fExperimentIcon; | |
c068a752 GB |
66 | private final Image fDefaultAnalysisIcon; |
67 | private final Image fDefaultViewIcon; | |
12c155f5 | 68 | |
09b9832c BH |
69 | private final WorkbenchLabelProvider fWorkspaceLabelProvider = new WorkbenchLabelProvider(); |
70 | ||
12c155f5 FC |
71 | // ------------------------------------------------------------------------ |
72 | // Constructors | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
b544077e | 75 | /** |
013a5f1c AM |
76 | * Constructor. |
77 | * | |
b544077e BH |
78 | * Creates the TMF navigator content provider. |
79 | */ | |
12c155f5 | 80 | public TmfNavigatorLabelProvider() { |
8fd82db5 | 81 | Bundle bundle = Activator.getDefault().getBundle(); |
12c155f5 FC |
82 | fDefaultTraceIcon = loadIcon(bundle, fTraceIconFile); |
83 | fExperimentIcon = loadIcon(bundle, fExperimentIconFile); | |
c068a752 GB |
84 | fDefaultAnalysisIcon = loadIcon(bundle, fAnalysisIconFile); |
85 | fDefaultViewIcon = loadIcon(bundle, fViewIconFile); | |
12c155f5 FC |
86 | } |
87 | ||
abbdd66a | 88 | private static Image loadIcon(Bundle bundle, String url) { |
8fd82db5 | 89 | Activator plugin = Activator.getDefault(); |
12c155f5 FC |
90 | String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$ |
91 | Image icon = plugin.getImageRegistry().get(key); | |
92 | if (icon == null) { | |
93 | URL imageURL = bundle.getResource(url); | |
94 | ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); | |
25dc6000 PT |
95 | if (descriptor != null) { |
96 | icon = descriptor.createImage(); | |
97 | plugin.getImageRegistry().put(key, icon); | |
98 | } | |
12c155f5 FC |
99 | } |
100 | return icon; | |
101 | } | |
102 | ||
103 | // ------------------------------------------------------------------------ | |
104 | // ICommonLabelProvider | |
105 | // ------------------------------------------------------------------------ | |
11252342 | 106 | |
12c155f5 FC |
107 | @Override |
108 | public Image getImage(Object element) { | |
109 | ||
8f5221c2 GB |
110 | if (element instanceof TmfCommonProjectElement) { |
111 | TmfCommonProjectElement trace = (TmfCommonProjectElement) element; | |
12c155f5 | 112 | try { |
efd33708 | 113 | String traceType = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); |
a4a116c3 | 114 | if (traceType == null || TmfTraceType.getTraceType(traceType) == null) { |
09b9832c BH |
115 | // request the label to the Eclipse platform |
116 | return fWorkspaceLabelProvider.getImage(((TmfCommonProjectElement) element).getResource()); | |
ab37ff41 | 117 | } |
efd33708 | 118 | |
50a41a0d | 119 | IConfigurationElement traceUIAttributes = TmfTraceTypeUIUtils.getTraceUIAttributes(traceType, (element instanceof TmfTraceElement) ? TraceElementType.TRACE : TraceElementType.EXPERIMENT); |
efd33708 MAL |
120 | if (traceUIAttributes != null) { |
121 | String iconAttr = traceUIAttributes.getAttribute(TmfTraceTypeUIUtils.ICON_ATTR); | |
122 | if (iconAttr != null) { | |
2d64a788 AM |
123 | String name = traceUIAttributes.getContributor().getName(); |
124 | if (name != null) { | |
125 | Bundle bundle = Platform.getBundle(name); | |
126 | if (bundle != null) { | |
127 | Image image = loadIcon(bundle, iconAttr); | |
128 | if (image != null) { | |
129 | return image; | |
130 | } | |
131 | } | |
25dc6000 PT |
132 | } |
133 | } | |
2d64a788 | 134 | |
12c155f5 FC |
135 | } |
136 | } catch (CoreException e) { | |
137 | } | |
8f5221c2 GB |
138 | if (element instanceof TmfTraceElement) { |
139 | return fDefaultTraceIcon; | |
140 | } | |
12c155f5 | 141 | return fExperimentIcon; |
013a5f1c | 142 | } |
12c155f5 | 143 | |
013a5f1c | 144 | if (element instanceof TmfExperimentFolder) { |
12c155f5 | 145 | return fExperimentFolderIcon; |
013a5f1c | 146 | } |
12c155f5 | 147 | |
013a5f1c | 148 | if (element instanceof TmfTraceFolder) { |
12c155f5 | 149 | return fTraceFolderIcon; |
013a5f1c | 150 | } |
12c155f5 | 151 | |
c068a752 GB |
152 | if (element instanceof TmfAnalysisOutputElement) { |
153 | TmfAnalysisOutputElement output = (TmfAnalysisOutputElement) element; | |
154 | Image icon = output.getIcon(); | |
155 | if (icon == null) { | |
156 | return fDefaultViewIcon; | |
157 | } | |
158 | return icon; | |
159 | } | |
160 | ||
161 | if (element instanceof TmfAnalysisElement) { | |
162 | TmfAnalysisElement analysis = (TmfAnalysisElement) element; | |
163 | String iconFile = analysis.getIconFile(); | |
164 | if (iconFile != null) { | |
165 | Bundle bundle = analysis.getBundle(); | |
166 | if (bundle != null) { | |
167 | Image icon = loadIcon(bundle, iconFile); | |
168 | return icon; | |
169 | } | |
170 | } | |
171 | return fDefaultAnalysisIcon; | |
172 | } | |
173 | ||
12c155f5 FC |
174 | return null; |
175 | } | |
176 | ||
177 | @Override | |
178 | public String getText(Object element) { | |
179 | ||
339d539c PT |
180 | if (element instanceof TmfTracesFolder) { |
181 | TmfTracesFolder folder = (TmfTracesFolder) element; | |
182 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ | |
183 | } | |
184 | ||
12c155f5 FC |
185 | if (element instanceof TmfTraceFolder) { |
186 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
339d539c PT |
187 | int nbTraces = folder.getTraces().size(); |
188 | if (nbTraces > 0) { | |
189 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ | |
190 | } | |
191 | return folder.getName(); | |
192 | } | |
193 | ||
194 | if (element instanceof TmfTraceElement) { | |
195 | TmfTraceElement trace = (TmfTraceElement) element; | |
196 | if (trace.getParent() instanceof TmfExperimentElement) { | |
197 | return trace.getElementPath(); | |
198 | } | |
199 | return trace.getName(); | |
12c155f5 FC |
200 | } |
201 | ||
202 | if (element instanceof TmfExperimentElement) { | |
203 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
8f5221c2 | 204 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ |
12c155f5 FC |
205 | } |
206 | ||
7d3950f5 FC |
207 | if (element instanceof TmfExperimentFolder) { |
208 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
8f5221c2 | 209 | return folder.getName() + " [" + folder.getChildren().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ |
7d3950f5 FC |
210 | } |
211 | ||
12c155f5 FC |
212 | // Catch all |
213 | if (element instanceof ITmfProjectModelElement) { | |
214 | return ((ITmfProjectModelElement) element).getName(); | |
215 | } | |
216 | ||
217 | return null; | |
218 | } | |
219 | ||
220 | @Override | |
221 | public void addListener(ILabelProviderListener listener) { | |
222 | } | |
223 | ||
224 | @Override | |
225 | public void dispose() { | |
226 | } | |
227 | ||
228 | @Override | |
229 | public boolean isLabelProperty(Object element, String property) { | |
230 | return false; | |
231 | } | |
232 | ||
233 | @Override | |
234 | public void removeListener(ILabelProviderListener listener) { | |
235 | } | |
236 | ||
237 | @Override | |
238 | public void restoreState(IMemento aMemento) { | |
239 | } | |
240 | ||
241 | @Override | |
242 | public void saveState(IMemento aMemento) { | |
243 | } | |
244 | ||
245 | @Override | |
246 | public String getDescription(Object anElement) { | |
247 | return getText(anElement); | |
248 | } | |
249 | ||
250 | @Override | |
251 | public void init(ICommonContentExtensionSite aConfig) { | |
252 | } | |
253 | ||
d5278aa5 GB |
254 | /** |
255 | * @since 3.0 | |
256 | */ | |
257 | @Override | |
258 | public StyledString getStyledText(Object element) { | |
259 | String text = getText(element); | |
260 | if (text != null) { | |
261 | if (element instanceof ITmfStyledProjectModelElement) { | |
262 | Styler styler = ((ITmfStyledProjectModelElement) element).getStyler(); | |
263 | if (styler != null) { | |
264 | return new StyledString(text, styler); | |
265 | } | |
266 | } | |
267 | return new StyledString(text); | |
268 | } | |
269 | return null; | |
270 | } | |
271 | ||
12c155f5 | 272 | } |