1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson, EfficiOS Inc. and others
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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
16 import org
.eclipse
.jdt
.annotation
.NonNull
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
19 import org
.eclipse
.swt
.graphics
.Image
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
21 import org
.eclipse
.ui
.ISharedImages
;
22 import org
.eclipse
.ui
.PlatformUI
;
23 import org
.eclipse
.ui
.model
.WorkbenchLabelProvider
;
24 import org
.osgi
.framework
.Bundle
;
27 * Facilities to load icons used in the Project View.
29 * @author Alexandre Montplaisir
32 final class TmfProjectModelIcons
{
34 private TmfProjectModelIcons() {}
36 public static final @NonNull Image DEFAULT_TRACE_ICON
;
37 public static final @NonNull Image DEFAULT_EXPERIMENT_ICON
;
38 public static final @NonNull Image DEFAULT_ANALYSIS_ICON
;
39 public static final @NonNull Image DEFAULT_VIEW_ICON
;
41 public static final @NonNull Image FOLDER_ICON
;
42 public static final @NonNull Image VIEWS_ICON
;
44 public static final WorkbenchLabelProvider WORKSPACE_LABEL_PROVIDER
= new WorkbenchLabelProvider();
46 private static final String TRACE_ICON_FILE
= "icons/elcl16/trace.gif"; //$NON-NLS-1$
47 private static final String EXPERIMENT_ICON_FILE
= "icons/elcl16/experiment.gif"; //$NON-NLS-1$
48 private static final String ANALYSIS_ICON_FILE
= "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$
49 private static final String VIEW_ICON_FILE
= "icons/obj16/node_obj.gif"; //$NON-NLS-1$
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 ISharedImages sharedImages
= PlatformUI
.getWorkbench().getSharedImages();
57 FOLDER_ICON
= checkNotNull(sharedImages
.getImage(ISharedImages
.IMG_OBJ_FOLDER
));
58 VIEWS_ICON
= checkNotNull(sharedImages
.getImage(ISharedImages
.IMG_OBJ_ELEMENT
));
60 Bundle bundle
= Activator
.getDefault().getBundle();
61 DEFAULT_TRACE_ICON
= checkNotNull(loadIcon(bundle
, TRACE_ICON_FILE
));
62 DEFAULT_EXPERIMENT_ICON
= checkNotNull(loadIcon(bundle
, EXPERIMENT_ICON_FILE
));
63 DEFAULT_ANALYSIS_ICON
= checkNotNull(loadIcon(bundle
, ANALYSIS_ICON_FILE
));
64 DEFAULT_VIEW_ICON
= checkNotNull(loadIcon(bundle
, VIEW_ICON_FILE
));
67 public static @Nullable Image
loadIcon(Bundle bundle
, String url
) {
68 Activator plugin
= Activator
.getDefault();
69 String key
= bundle
.getSymbolicName() + "/" + url
; //$NON-NLS-1$
70 Image icon
= plugin
.getImageRegistry().get(key
);
72 URL imageURL
= bundle
.getResource(url
);
73 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
74 if (descriptor
!= null) {
75 icon
= descriptor
.createImage();
76 plugin
.getImageRegistry().put(key
, icon
);