1 /*******************************************************************************
2 * Copyright (c) 2011 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
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
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
22 import org
.eclipse
.swt
.graphics
.Image
;
23 import org
.eclipse
.ui
.IMemento
;
24 import org
.eclipse
.ui
.ISharedImages
;
25 import org
.eclipse
.ui
.PlatformUI
;
26 import org
.eclipse
.ui
.navigator
.ICommonContentExtensionSite
;
27 import org
.eclipse
.ui
.navigator
.ICommonLabelProvider
;
28 import org
.osgi
.framework
.Bundle
;
31 * <b><u>TmfNavigatorLabelProvider</u></b>
34 public class TmfNavigatorLabelProvider
implements ICommonLabelProvider
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 private static final Image fFolderIcon
= PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_FOLDER
);
41 private static final String fTraceIconFile
= "icons/elcl16/trace.gif"; //$NON-NLS-1$
42 private static final String fExperimentIconFile
= "icons/elcl16/experiment.gif"; //$NON-NLS-1$
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 private final Image fTraceFolderIcon
= fFolderIcon
;
49 private final Image fExperimentFolderIcon
= fFolderIcon
;
51 private final Image fDefaultTraceIcon
;
52 private final Image fExperimentIcon
;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 public TmfNavigatorLabelProvider() {
59 Bundle bundle
= TmfUiPlugin
.getDefault().getBundle();
60 fDefaultTraceIcon
= loadIcon(bundle
, fTraceIconFile
);
61 fExperimentIcon
= loadIcon(bundle
, fExperimentIconFile
);
64 private Image
loadIcon(Bundle bundle
, String url
) {
65 TmfUiPlugin plugin
= TmfUiPlugin
.getDefault();
66 String key
= bundle
.getSymbolicName() + "/" + url
; //$NON-NLS-1$
67 Image icon
= plugin
.getImageRegistry().get(key
);
69 URL imageURL
= bundle
.getResource(url
);
70 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
71 icon
= descriptor
.createImage();
72 plugin
.getImageRegistry().put(key
, icon
);
77 // ------------------------------------------------------------------------
78 // ICommonLabelProvider
79 // ------------------------------------------------------------------------
82 public Image
getImage(Object element
) {
84 if (element
instanceof TmfTraceElement
) {
85 TmfTraceElement trace
= (TmfTraceElement
) element
;
88 String name
= trace
.getResource().getPersistentProperty(TmfTraceElement
.TRACEBUNDLE
);
89 icon
= trace
.getResource().getPersistentProperty(TmfTraceElement
.TRACEICON
);
90 if (name
!= null && icon
!= null) {
91 Bundle bundle
= Platform
.getBundle(name
);
92 return loadIcon(bundle
, icon
);
94 } catch (CoreException e
) {
96 return fDefaultTraceIcon
;
99 if (element
instanceof TmfExperimentElement
)
100 return fExperimentIcon
;
102 if (element
instanceof TmfExperimentFolder
)
103 return fExperimentFolderIcon
;
105 if (element
instanceof TmfTraceFolder
)
106 return fTraceFolderIcon
;
112 public String
getText(Object element
) {
114 if (element
instanceof TmfTraceFolder
) {
115 TmfTraceFolder folder
= (TmfTraceFolder
) element
;
116 return folder
.getName() + " [" + folder
.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
119 if (element
instanceof TmfExperimentElement
) {
120 TmfExperimentElement folder
= (TmfExperimentElement
) element
;
121 return folder
.getName() + " [" + folder
.getTraces().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
124 if (element
instanceof TmfExperimentFolder
) {
125 TmfExperimentFolder folder
= (TmfExperimentFolder
) element
;
126 return folder
.getName() + " [" + folder
.getChildren().size() + "]"; //$NON-NLS-1$//$NON-NLS-2$
130 if (element
instanceof ITmfProjectModelElement
) {
131 return ((ITmfProjectModelElement
) element
).getName();
138 public void addListener(ILabelProviderListener listener
) {
142 public void dispose() {
146 public boolean isLabelProperty(Object element
, String property
) {
151 public void removeListener(ILabelProviderListener listener
) {
155 public void restoreState(IMemento aMemento
) {
159 public void saveState(IMemento aMemento
) {
163 public String
getDescription(Object anElement
) {
164 return getText(anElement
);
168 public void init(ICommonContentExtensionSite aConfig
) {