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