Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2011, 2013 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; | |
19 | import org.eclipse.core.runtime.Platform; | |
20 | import org.eclipse.jface.resource.ImageDescriptor; | |
21 | import org.eclipse.jface.viewers.ILabelProviderListener; | |
8fd82db5 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
e12ecd30 | 23 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
12c155f5 FC |
24 | import org.eclipse.swt.graphics.Image; |
25 | import org.eclipse.ui.IMemento; | |
26 | import org.eclipse.ui.ISharedImages; | |
27 | import org.eclipse.ui.PlatformUI; | |
28 | import org.eclipse.ui.navigator.ICommonContentExtensionSite; | |
29 | import org.eclipse.ui.navigator.ICommonLabelProvider; | |
30 | import org.osgi.framework.Bundle; | |
31 | ||
32 | /** | |
013a5f1c | 33 | * The TMF project label provider for the tree viewer in the project explorer view. |
12c155f5 | 34 | * <p> |
b544077e BH |
35 | * @version 1.0 |
36 | * @author Francois Chouinard | |
12c155f5 FC |
37 | */ |
38 | public class TmfNavigatorLabelProvider implements ICommonLabelProvider { | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Constants | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
5a5c2fc7 FC |
44 | private static final Image fFolderIcon = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); |
45 | private static final String fTraceIconFile = "icons/elcl16/trace.gif"; //$NON-NLS-1$ | |
ab37ff41 | 46 | private static final String fUnknownIconFile = "icons/elcl16/unknown_parser.gif"; //$NON-NLS-1$ |
5a5c2fc7 | 47 | private static final String fExperimentIconFile = "icons/elcl16/experiment.gif"; //$NON-NLS-1$ |
12c155f5 FC |
48 | |
49 | // ------------------------------------------------------------------------ | |
50 | // Attributes | |
51 | // ------------------------------------------------------------------------ | |
52 | ||
53 | private final Image fTraceFolderIcon = fFolderIcon; | |
54 | private final Image fExperimentFolderIcon = fFolderIcon; | |
55 | ||
56 | private final Image fDefaultTraceIcon; | |
ab37ff41 | 57 | private final Image fUnknownTraceIcon; |
12c155f5 FC |
58 | private final Image fExperimentIcon; |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Constructors | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
b544077e | 64 | /** |
013a5f1c AM |
65 | * Constructor. |
66 | * | |
b544077e BH |
67 | * Creates the TMF navigator content provider. |
68 | */ | |
12c155f5 | 69 | public TmfNavigatorLabelProvider() { |
8fd82db5 | 70 | Bundle bundle = Activator.getDefault().getBundle(); |
12c155f5 | 71 | fDefaultTraceIcon = loadIcon(bundle, fTraceIconFile); |
ab37ff41 | 72 | fUnknownTraceIcon = loadIcon(bundle, fUnknownIconFile); |
12c155f5 FC |
73 | fExperimentIcon = loadIcon(bundle, fExperimentIconFile); |
74 | } | |
75 | ||
abbdd66a | 76 | private static Image loadIcon(Bundle bundle, String url) { |
8fd82db5 | 77 | Activator plugin = Activator.getDefault(); |
12c155f5 FC |
78 | String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$ |
79 | Image icon = plugin.getImageRegistry().get(key); | |
80 | if (icon == null) { | |
81 | URL imageURL = bundle.getResource(url); | |
82 | ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); | |
25dc6000 PT |
83 | if (descriptor != null) { |
84 | icon = descriptor.createImage(); | |
85 | plugin.getImageRegistry().put(key, icon); | |
86 | } | |
12c155f5 FC |
87 | } |
88 | return icon; | |
89 | } | |
90 | ||
91 | // ------------------------------------------------------------------------ | |
92 | // ICommonLabelProvider | |
93 | // ------------------------------------------------------------------------ | |
11252342 | 94 | |
12c155f5 FC |
95 | @Override |
96 | public Image getImage(Object element) { | |
97 | ||
98 | if (element instanceof TmfTraceElement) { | |
99 | TmfTraceElement trace = (TmfTraceElement) element; | |
12c155f5 | 100 | try { |
ab37ff41 PT |
101 | if (trace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE) == null) { |
102 | return fUnknownTraceIcon; | |
103 | } | |
e12ecd30 | 104 | String name = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEBUNDLE); |
ab37ff41 | 105 | String icon = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEICON); |
12c155f5 FC |
106 | if (name != null && icon != null) { |
107 | Bundle bundle = Platform.getBundle(name); | |
25dc6000 PT |
108 | if (bundle != null) { |
109 | Image image = loadIcon(bundle, icon); | |
110 | if (image != null) { | |
111 | return image; | |
112 | } | |
113 | } | |
114 | return fUnknownTraceIcon; | |
12c155f5 FC |
115 | } |
116 | } catch (CoreException e) { | |
117 | } | |
118 | return fDefaultTraceIcon; | |
119 | } | |
120 | ||
013a5f1c | 121 | if (element instanceof TmfExperimentElement) { |
12c155f5 | 122 | return fExperimentIcon; |
013a5f1c | 123 | } |
12c155f5 | 124 | |
013a5f1c | 125 | if (element instanceof TmfExperimentFolder) { |
12c155f5 | 126 | return fExperimentFolderIcon; |
013a5f1c | 127 | } |
12c155f5 | 128 | |
013a5f1c | 129 | if (element instanceof TmfTraceFolder) { |
12c155f5 | 130 | return fTraceFolderIcon; |
013a5f1c | 131 | } |
12c155f5 FC |
132 | |
133 | return null; | |
134 | } | |
135 | ||
136 | @Override | |
137 | public String getText(Object element) { | |
138 | ||
139 | if (element instanceof TmfTraceFolder) { | |
140 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
141 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$ | |
142 | } | |
143 | ||
144 | if (element instanceof TmfExperimentElement) { | |
145 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
146 | return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$ | |
147 | } | |
148 | ||
7d3950f5 FC |
149 | if (element instanceof TmfExperimentFolder) { |
150 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
151 | return folder.getName() + " [" + folder.getChildren().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$ | |
152 | } | |
153 | ||
12c155f5 FC |
154 | // Catch all |
155 | if (element instanceof ITmfProjectModelElement) { | |
156 | return ((ITmfProjectModelElement) element).getName(); | |
157 | } | |
158 | ||
159 | return null; | |
160 | } | |
161 | ||
162 | @Override | |
163 | public void addListener(ILabelProviderListener listener) { | |
164 | } | |
165 | ||
166 | @Override | |
167 | public void dispose() { | |
168 | } | |
169 | ||
170 | @Override | |
171 | public boolean isLabelProperty(Object element, String property) { | |
172 | return false; | |
173 | } | |
174 | ||
175 | @Override | |
176 | public void removeListener(ILabelProviderListener listener) { | |
177 | } | |
178 | ||
179 | @Override | |
180 | public void restoreState(IMemento aMemento) { | |
181 | } | |
182 | ||
183 | @Override | |
184 | public void saveState(IMemento aMemento) { | |
185 | } | |
186 | ||
187 | @Override | |
188 | public String getDescription(Object anElement) { | |
189 | return getText(anElement); | |
190 | } | |
191 | ||
192 | @Override | |
193 | public void init(ICommonContentExtensionSite aConfig) { | |
194 | } | |
195 | ||
196 | } |