1 /*******************************************************************************
2 * Copyright (c) 2011, 2012, 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$
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 private final Image fTraceFolderIcon
= fFolderIcon
;
54 private final Image fExperimentFolderIcon
= fFolderIcon
;
56 private final Image fDefaultTraceIcon
;
57 private final Image fUnknownTraceIcon
;
58 private final Image fExperimentIcon
;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
67 * Creates the TMF navigator content provider.
69 public TmfNavigatorLabelProvider() {
70 Bundle bundle
= Activator
.getDefault().getBundle();
71 fDefaultTraceIcon
= loadIcon(bundle
, fTraceIconFile
);
72 fUnknownTraceIcon
= loadIcon(bundle
, fUnknownIconFile
);
73 fExperimentIcon
= loadIcon(bundle
, fExperimentIconFile
);
76 private static Image
loadIcon(Bundle bundle
, String url
) {
77 Activator plugin
= Activator
.getDefault();
78 String key
= bundle
.getSymbolicName() + "/" + url
; //$NON-NLS-1$
79 Image icon
= plugin
.getImageRegistry().get(key
);
81 URL imageURL
= bundle
.getResource(url
);
82 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
83 icon
= descriptor
.createImage();
84 plugin
.getImageRegistry().put(key
, icon
);
89 // ------------------------------------------------------------------------
90 // ICommonLabelProvider
91 // ------------------------------------------------------------------------
94 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
97 public Image
getImage(Object element
) {
99 if (element
instanceof TmfTraceElement
) {
100 TmfTraceElement trace
= (TmfTraceElement
) element
;
102 if (trace
.getResource().getPersistentProperty(TmfCommonConstants
.TRACETYPE
) == null) {
103 return fUnknownTraceIcon
;
105 String name
= trace
.getResource().getPersistentProperty(TmfCommonConstants
.TRACEBUNDLE
);
106 String icon
= trace
.getResource().getPersistentProperty(TmfCommonConstants
.TRACEICON
);
107 if (name
!= null && icon
!= null) {
108 Bundle bundle
= Platform
.getBundle(name
);
109 return loadIcon(bundle
, icon
);
111 } catch (CoreException e
) {
113 return fDefaultTraceIcon
;
116 if (element
instanceof TmfExperimentElement
) {
117 return fExperimentIcon
;
120 if (element
instanceof TmfExperimentFolder
) {
121 return fExperimentFolderIcon
;
124 if (element
instanceof TmfTraceFolder
) {
125 return fTraceFolderIcon
;
133 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
136 public String
getText(Object element
) {
138 if (element
instanceof TmfTraceFolder
) {
139 TmfTraceFolder folder
= (TmfTraceFolder
) element
;
140 return folder
.getName() + " [" + folder
.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
143 if (element
instanceof TmfExperimentElement
) {
144 TmfExperimentElement folder
= (TmfExperimentElement
) element
;
145 return folder
.getName() + " [" + folder
.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
148 if (element
instanceof TmfExperimentFolder
) {
149 TmfExperimentFolder folder
= (TmfExperimentFolder
) element
;
150 return folder
.getName() + " [" + folder
.getChildren().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
154 if (element
instanceof ITmfProjectModelElement
) {
155 return ((ITmfProjectModelElement
) element
).getName();
163 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
166 public void addListener(ILabelProviderListener listener
) {
171 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
174 public void dispose() {
179 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
182 public boolean isLabelProperty(Object element
, String property
) {
188 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
191 public void removeListener(ILabelProviderListener listener
) {
196 * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento)
199 public void restoreState(IMemento aMemento
) {
204 * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento)
207 public void saveState(IMemento aMemento
) {
212 * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object)
215 public String
getDescription(Object anElement
) {
216 return getText(anElement
);
221 * @see org.eclipse.ui.navigator.ICommonLabelProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite)
224 public void init(ICommonContentExtensionSite aConfig
) {