1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Add support for unknown trace type icon
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
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
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.TmfCommonConstants
;
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
;
33 * The TMF project label provider for the tree viewer in the project explorer view.
36 * @author Francois Chouinard
38 public class TmfNavigatorLabelProvider
implements ICommonLabelProvider
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
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$
46 private static final String fUnknownIconFile
= "icons/elcl16/unknown_parser.gif"; //$NON-NLS-1$
47 private static final String fExperimentIconFile
= "icons/elcl16/experiment.gif"; //$NON-NLS-1$
48 private static final String fAnalysisIconFile
= "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$
49 private static final String fViewIconFile
= "icons/obj16/node_obj.gif"; //$NON-NLS-1$
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 private final Image fTraceFolderIcon
= fFolderIcon
;
56 private final Image fExperimentFolderIcon
= fFolderIcon
;
58 private final Image fDefaultTraceIcon
;
59 private final Image fUnknownTraceIcon
;
60 private final Image fExperimentIcon
;
61 private final Image fDefaultAnalysisIcon
;
62 private final Image fDefaultViewIcon
;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
71 * Creates the TMF navigator content provider.
73 public TmfNavigatorLabelProvider() {
74 Bundle bundle
= Activator
.getDefault().getBundle();
75 fDefaultTraceIcon
= loadIcon(bundle
, fTraceIconFile
);
76 fUnknownTraceIcon
= loadIcon(bundle
, fUnknownIconFile
);
77 fExperimentIcon
= loadIcon(bundle
, fExperimentIconFile
);
78 fDefaultAnalysisIcon
= loadIcon(bundle
, fAnalysisIconFile
);
79 fDefaultViewIcon
= loadIcon(bundle
, fViewIconFile
);
82 private static Image
loadIcon(Bundle bundle
, String url
) {
83 Activator plugin
= Activator
.getDefault();
84 String key
= bundle
.getSymbolicName() + "/" + url
; //$NON-NLS-1$
85 Image icon
= plugin
.getImageRegistry().get(key
);
87 URL imageURL
= bundle
.getResource(url
);
88 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
89 if (descriptor
!= null) {
90 icon
= descriptor
.createImage();
91 plugin
.getImageRegistry().put(key
, icon
);
97 // ------------------------------------------------------------------------
98 // ICommonLabelProvider
99 // ------------------------------------------------------------------------
102 public Image
getImage(Object element
) {
104 if (element
instanceof TmfTraceElement
) {
105 TmfTraceElement trace
= (TmfTraceElement
) element
;
107 if (trace
.getResource().getPersistentProperty(TmfCommonConstants
.TRACETYPE
) == null) {
108 return fUnknownTraceIcon
;
110 String name
= trace
.getResource().getPersistentProperty(TmfCommonConstants
.TRACEBUNDLE
);
111 String icon
= trace
.getResource().getPersistentProperty(TmfCommonConstants
.TRACEICON
);
112 if (name
!= null && icon
!= null) {
113 Bundle bundle
= Platform
.getBundle(name
);
114 if (bundle
!= null) {
115 Image image
= loadIcon(bundle
, icon
);
120 return fUnknownTraceIcon
;
122 } catch (CoreException e
) {
124 return fDefaultTraceIcon
;
127 if (element
instanceof TmfExperimentElement
) {
128 return fExperimentIcon
;
131 if (element
instanceof TmfExperimentFolder
) {
132 return fExperimentFolderIcon
;
135 if (element
instanceof TmfTraceFolder
) {
136 return fTraceFolderIcon
;
139 if (element
instanceof TmfAnalysisOutputElement
) {
140 TmfAnalysisOutputElement output
= (TmfAnalysisOutputElement
) element
;
141 Image icon
= output
.getIcon();
143 return fDefaultViewIcon
;
148 if (element
instanceof TmfAnalysisElement
) {
149 TmfAnalysisElement analysis
= (TmfAnalysisElement
) element
;
150 String iconFile
= analysis
.getIconFile();
151 if (iconFile
!= null) {
152 Bundle bundle
= analysis
.getBundle();
153 if (bundle
!= null) {
154 Image icon
= loadIcon(bundle
, iconFile
);
158 return fDefaultAnalysisIcon
;
165 public String
getText(Object element
) {
167 if (element
instanceof TmfTraceFolder
) {
168 TmfTraceFolder folder
= (TmfTraceFolder
) element
;
169 return folder
.getName() + " [" + folder
.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
172 if (element
instanceof TmfExperimentElement
) {
173 TmfExperimentElement folder
= (TmfExperimentElement
) element
;
174 return folder
.getName() + " [" + folder
.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
177 if (element
instanceof TmfExperimentFolder
) {
178 TmfExperimentFolder folder
= (TmfExperimentFolder
) element
;
179 return folder
.getName() + " [" + folder
.getChildren().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
183 if (element
instanceof ITmfProjectModelElement
) {
184 return ((ITmfProjectModelElement
) element
).getName();
191 public void addListener(ILabelProviderListener listener
) {
195 public void dispose() {
199 public boolean isLabelProperty(Object element
, String property
) {
204 public void removeListener(ILabelProviderListener listener
) {
208 public void restoreState(IMemento aMemento
) {
212 public void saveState(IMemento aMemento
) {
216 public String
getDescription(Object anElement
) {
217 return getText(anElement
);
221 public void init(ICommonContentExtensionSite aConfig
) {