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; | |
22 | import org.eclipse.jface.viewers.ILabelProviderListener; | |
8fd82db5 | 23 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
e12ecd30 | 24 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
2d64a788 | 25 | import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; |
12c155f5 FC |
26 | import org.eclipse.swt.graphics.Image; |
27 | import org.eclipse.ui.IMemento; | |
28 | import org.eclipse.ui.ISharedImages; | |
29 | import org.eclipse.ui.PlatformUI; | |
30 | import org.eclipse.ui.navigator.ICommonContentExtensionSite; | |
31 | import org.eclipse.ui.navigator.ICommonLabelProvider; | |
32 | import org.osgi.framework.Bundle; | |
33 | ||
34 | /** | |
013a5f1c | 35 | * The TMF project label provider for the tree viewer in the project explorer view. |
12c155f5 | 36 | * <p> |
b544077e BH |
37 | * @version 1.0 |
38 | * @author Francois Chouinard | |
12c155f5 FC |
39 | */ |
40 | public class TmfNavigatorLabelProvider implements ICommonLabelProvider { | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Constants | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
5a5c2fc7 FC |
46 | private static final Image fFolderIcon = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); |
47 | private static final String fTraceIconFile = "icons/elcl16/trace.gif"; //$NON-NLS-1$ | |
ab37ff41 | 48 | private static final String fUnknownIconFile = "icons/elcl16/unknown_parser.gif"; //$NON-NLS-1$ |
5a5c2fc7 | 49 | private static final String fExperimentIconFile = "icons/elcl16/experiment.gif"; //$NON-NLS-1$ |
c068a752 GB |
50 | private static final String fAnalysisIconFile = "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$ |
51 | private static final String fViewIconFile = "icons/obj16/node_obj.gif"; //$NON-NLS-1$ | |
12c155f5 FC |
52 | |
53 | // ------------------------------------------------------------------------ | |
54 | // Attributes | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
57 | private final Image fTraceFolderIcon = fFolderIcon; | |
58 | private final Image fExperimentFolderIcon = fFolderIcon; | |
59 | ||
60 | private final Image fDefaultTraceIcon; | |
ab37ff41 | 61 | private final Image fUnknownTraceIcon; |
12c155f5 | 62 | private final Image fExperimentIcon; |
c068a752 GB |
63 | private final Image fDefaultAnalysisIcon; |
64 | private final Image fDefaultViewIcon; | |
12c155f5 FC |
65 | |
66 | // ------------------------------------------------------------------------ | |
67 | // Constructors | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
b544077e | 70 | /** |
013a5f1c AM |
71 | * Constructor. |
72 | * | |
b544077e BH |
73 | * Creates the TMF navigator content provider. |
74 | */ | |
12c155f5 | 75 | public TmfNavigatorLabelProvider() { |
8fd82db5 | 76 | Bundle bundle = Activator.getDefault().getBundle(); |
12c155f5 | 77 | fDefaultTraceIcon = loadIcon(bundle, fTraceIconFile); |
ab37ff41 | 78 | fUnknownTraceIcon = loadIcon(bundle, fUnknownIconFile); |
12c155f5 | 79 | fExperimentIcon = loadIcon(bundle, fExperimentIconFile); |
c068a752 GB |
80 | fDefaultAnalysisIcon = loadIcon(bundle, fAnalysisIconFile); |
81 | fDefaultViewIcon = loadIcon(bundle, fViewIconFile); | |
12c155f5 FC |
82 | } |
83 | ||
abbdd66a | 84 | private static Image loadIcon(Bundle bundle, String url) { |
8fd82db5 | 85 | Activator plugin = Activator.getDefault(); |
12c155f5 FC |
86 | String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$ |
87 | Image icon = plugin.getImageRegistry().get(key); | |
88 | if (icon == null) { | |
89 | URL imageURL = bundle.getResource(url); | |
90 | ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); | |
25dc6000 PT |
91 | if (descriptor != null) { |
92 | icon = descriptor.createImage(); | |
93 | plugin.getImageRegistry().put(key, icon); | |
94 | } | |
12c155f5 FC |
95 | } |
96 | return icon; | |
97 | } | |
98 | ||
99 | // ------------------------------------------------------------------------ | |
100 | // ICommonLabelProvider | |
101 | // ------------------------------------------------------------------------ | |
11252342 | 102 | |
12c155f5 FC |
103 | @Override |
104 | public Image getImage(Object element) { | |
105 | ||
8f5221c2 GB |
106 | if (element instanceof TmfCommonProjectElement) { |
107 | TmfCommonProjectElement trace = (TmfCommonProjectElement) element; | |
12c155f5 | 108 | try { |
efd33708 | 109 | String traceType = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); |
2d64a788 | 110 | if (traceType == null || TmfTraceType.getInstance().getTraceType(traceType) == null) { |
ab37ff41 PT |
111 | return fUnknownTraceIcon; |
112 | } | |
efd33708 MAL |
113 | |
114 | IConfigurationElement traceUIAttributes = TmfTraceTypeUIUtils.getTraceUIAttributes(traceType); | |
efd33708 MAL |
115 | if (traceUIAttributes != null) { |
116 | String iconAttr = traceUIAttributes.getAttribute(TmfTraceTypeUIUtils.ICON_ATTR); | |
117 | if (iconAttr != null) { | |
2d64a788 AM |
118 | String name = traceUIAttributes.getContributor().getName(); |
119 | if (name != null) { | |
120 | Bundle bundle = Platform.getBundle(name); | |
121 | if (bundle != null) { | |
122 | Image image = loadIcon(bundle, iconAttr); | |
123 | if (image != null) { | |
124 | return image; | |
125 | } | |
126 | } | |
25dc6000 PT |
127 | } |
128 | } | |
2d64a788 | 129 | |
12c155f5 FC |
130 | } |
131 | } catch (CoreException e) { | |
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 | ||
175 | if (element instanceof TmfTraceFolder) { | |
176 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
8f5221c2 | 177 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ |
12c155f5 FC |
178 | } |
179 | ||
180 | if (element instanceof TmfExperimentElement) { | |
181 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
8f5221c2 | 182 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ |
12c155f5 FC |
183 | } |
184 | ||
7d3950f5 FC |
185 | if (element instanceof TmfExperimentFolder) { |
186 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
8f5221c2 | 187 | return folder.getName() + " [" + folder.getChildren().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ |
7d3950f5 FC |
188 | } |
189 | ||
12c155f5 FC |
190 | // Catch all |
191 | if (element instanceof ITmfProjectModelElement) { | |
192 | return ((ITmfProjectModelElement) element).getName(); | |
193 | } | |
194 | ||
195 | return null; | |
196 | } | |
197 | ||
198 | @Override | |
199 | public void addListener(ILabelProviderListener listener) { | |
200 | } | |
201 | ||
202 | @Override | |
203 | public void dispose() { | |
204 | } | |
205 | ||
206 | @Override | |
207 | public boolean isLabelProperty(Object element, String property) { | |
208 | return false; | |
209 | } | |
210 | ||
211 | @Override | |
212 | public void removeListener(ILabelProviderListener listener) { | |
213 | } | |
214 | ||
215 | @Override | |
216 | public void restoreState(IMemento aMemento) { | |
217 | } | |
218 | ||
219 | @Override | |
220 | public void saveState(IMemento aMemento) { | |
221 | } | |
222 | ||
223 | @Override | |
224 | public String getDescription(Object anElement) { | |
225 | return getText(anElement); | |
226 | } | |
227 | ||
228 | @Override | |
229 | public void init(ICommonContentExtensionSite aConfig) { | |
230 | } | |
231 | ||
232 | } |