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; | |
34 | import org.eclipse.ui.navigator.ICommonContentExtensionSite; | |
35 | import org.eclipse.ui.navigator.ICommonLabelProvider; | |
36 | import org.osgi.framework.Bundle; | |
37 | ||
38 | /** | |
013a5f1c | 39 | * The TMF project label provider for the tree viewer in the project explorer view. |
12c155f5 | 40 | * <p> |
b544077e BH |
41 | * @version 1.0 |
42 | * @author Francois Chouinard | |
12c155f5 | 43 | */ |
d5278aa5 | 44 | public class TmfNavigatorLabelProvider implements ICommonLabelProvider, IStyledLabelProvider { |
12c155f5 FC |
45 | |
46 | // ------------------------------------------------------------------------ | |
47 | // Constants | |
48 | // ------------------------------------------------------------------------ | |
49 | ||
5a5c2fc7 FC |
50 | private static final Image fFolderIcon = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); |
51 | private static final String fTraceIconFile = "icons/elcl16/trace.gif"; //$NON-NLS-1$ | |
ab37ff41 | 52 | private static final String fUnknownIconFile = "icons/elcl16/unknown_parser.gif"; //$NON-NLS-1$ |
5a5c2fc7 | 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; | |
ab37ff41 | 65 | private final Image fUnknownTraceIcon; |
12c155f5 | 66 | private final Image fExperimentIcon; |
c068a752 GB |
67 | private final Image fDefaultAnalysisIcon; |
68 | private final Image fDefaultViewIcon; | |
12c155f5 FC |
69 | |
70 | // ------------------------------------------------------------------------ | |
71 | // Constructors | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
b544077e | 74 | /** |
013a5f1c AM |
75 | * Constructor. |
76 | * | |
b544077e BH |
77 | * Creates the TMF navigator content provider. |
78 | */ | |
12c155f5 | 79 | public TmfNavigatorLabelProvider() { |
8fd82db5 | 80 | Bundle bundle = Activator.getDefault().getBundle(); |
12c155f5 | 81 | fDefaultTraceIcon = loadIcon(bundle, fTraceIconFile); |
ab37ff41 | 82 | fUnknownTraceIcon = loadIcon(bundle, fUnknownIconFile); |
12c155f5 | 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); |
2d64a788 | 114 | if (traceType == null || TmfTraceType.getInstance().getTraceType(traceType) == null) { |
ab37ff41 PT |
115 | return fUnknownTraceIcon; |
116 | } | |
efd33708 | 117 | |
50a41a0d | 118 | IConfigurationElement traceUIAttributes = TmfTraceTypeUIUtils.getTraceUIAttributes(traceType, (element instanceof TmfTraceElement) ? TraceElementType.TRACE : TraceElementType.EXPERIMENT); |
efd33708 MAL |
119 | if (traceUIAttributes != null) { |
120 | String iconAttr = traceUIAttributes.getAttribute(TmfTraceTypeUIUtils.ICON_ATTR); | |
121 | if (iconAttr != null) { | |
2d64a788 AM |
122 | String name = traceUIAttributes.getContributor().getName(); |
123 | if (name != null) { | |
124 | Bundle bundle = Platform.getBundle(name); | |
125 | if (bundle != null) { | |
126 | Image image = loadIcon(bundle, iconAttr); | |
127 | if (image != null) { | |
128 | return image; | |
129 | } | |
130 | } | |
25dc6000 PT |
131 | } |
132 | } | |
2d64a788 | 133 | |
12c155f5 FC |
134 | } |
135 | } catch (CoreException e) { | |
136 | } | |
8f5221c2 GB |
137 | if (element instanceof TmfTraceElement) { |
138 | return fDefaultTraceIcon; | |
139 | } | |
12c155f5 | 140 | return fExperimentIcon; |
013a5f1c | 141 | } |
12c155f5 | 142 | |
013a5f1c | 143 | if (element instanceof TmfExperimentFolder) { |
12c155f5 | 144 | return fExperimentFolderIcon; |
013a5f1c | 145 | } |
12c155f5 | 146 | |
013a5f1c | 147 | if (element instanceof TmfTraceFolder) { |
12c155f5 | 148 | return fTraceFolderIcon; |
013a5f1c | 149 | } |
12c155f5 | 150 | |
c068a752 GB |
151 | if (element instanceof TmfAnalysisOutputElement) { |
152 | TmfAnalysisOutputElement output = (TmfAnalysisOutputElement) element; | |
153 | Image icon = output.getIcon(); | |
154 | if (icon == null) { | |
155 | return fDefaultViewIcon; | |
156 | } | |
157 | return icon; | |
158 | } | |
159 | ||
160 | if (element instanceof TmfAnalysisElement) { | |
161 | TmfAnalysisElement analysis = (TmfAnalysisElement) element; | |
162 | String iconFile = analysis.getIconFile(); | |
163 | if (iconFile != null) { | |
164 | Bundle bundle = analysis.getBundle(); | |
165 | if (bundle != null) { | |
166 | Image icon = loadIcon(bundle, iconFile); | |
167 | return icon; | |
168 | } | |
169 | } | |
170 | return fDefaultAnalysisIcon; | |
171 | } | |
172 | ||
12c155f5 FC |
173 | return null; |
174 | } | |
175 | ||
176 | @Override | |
177 | public String getText(Object element) { | |
178 | ||
339d539c PT |
179 | if (element instanceof TmfTracesFolder) { |
180 | TmfTracesFolder folder = (TmfTracesFolder) element; | |
181 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ | |
182 | } | |
183 | ||
12c155f5 FC |
184 | if (element instanceof TmfTraceFolder) { |
185 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
339d539c PT |
186 | int nbTraces = folder.getTraces().size(); |
187 | if (nbTraces > 0) { | |
188 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ | |
189 | } | |
190 | return folder.getName(); | |
191 | } | |
192 | ||
193 | if (element instanceof TmfTraceElement) { | |
194 | TmfTraceElement trace = (TmfTraceElement) element; | |
195 | if (trace.getParent() instanceof TmfExperimentElement) { | |
196 | return trace.getElementPath(); | |
197 | } | |
198 | return trace.getName(); | |
12c155f5 FC |
199 | } |
200 | ||
201 | if (element instanceof TmfExperimentElement) { | |
202 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
8f5221c2 | 203 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ |
12c155f5 FC |
204 | } |
205 | ||
7d3950f5 FC |
206 | if (element instanceof TmfExperimentFolder) { |
207 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
8f5221c2 | 208 | return folder.getName() + " [" + folder.getChildren().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ |
7d3950f5 FC |
209 | } |
210 | ||
12c155f5 FC |
211 | // Catch all |
212 | if (element instanceof ITmfProjectModelElement) { | |
213 | return ((ITmfProjectModelElement) element).getName(); | |
214 | } | |
215 | ||
216 | return null; | |
217 | } | |
218 | ||
219 | @Override | |
220 | public void addListener(ILabelProviderListener listener) { | |
221 | } | |
222 | ||
223 | @Override | |
224 | public void dispose() { | |
225 | } | |
226 | ||
227 | @Override | |
228 | public boolean isLabelProperty(Object element, String property) { | |
229 | return false; | |
230 | } | |
231 | ||
232 | @Override | |
233 | public void removeListener(ILabelProviderListener listener) { | |
234 | } | |
235 | ||
236 | @Override | |
237 | public void restoreState(IMemento aMemento) { | |
238 | } | |
239 | ||
240 | @Override | |
241 | public void saveState(IMemento aMemento) { | |
242 | } | |
243 | ||
244 | @Override | |
245 | public String getDescription(Object anElement) { | |
246 | return getText(anElement); | |
247 | } | |
248 | ||
249 | @Override | |
250 | public void init(ICommonContentExtensionSite aConfig) { | |
251 | } | |
252 | ||
d5278aa5 GB |
253 | /** |
254 | * @since 3.0 | |
255 | */ | |
256 | @Override | |
257 | public StyledString getStyledText(Object element) { | |
258 | String text = getText(element); | |
259 | if (text != null) { | |
260 | if (element instanceof ITmfStyledProjectModelElement) { | |
261 | Styler styler = ((ITmfStyledProjectModelElement) element).getStyler(); | |
262 | if (styler != null) { | |
263 | return new StyledString(text, styler); | |
264 | } | |
265 | } | |
266 | return new StyledString(text); | |
267 | } | |
268 | return null; | |
269 | } | |
270 | ||
12c155f5 | 271 | } |