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