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