tmf: Move icon and label text into ITmfProjectModelElement
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / project / model / TmfProjectModelIcons.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson, EfficiOS Inc. and others
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.tmf.ui.project.model;
11
12 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
14 import java.net.URL;
15
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;
25
26 /**
27 * Facilities to load icons used in the Project View.
28 *
29 * @author Alexandre Montplaisir
30 * @since 2.0
31 */
32 final class TmfProjectModelIcons {
33
34 private TmfProjectModelIcons() {}
35
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;
40 public static final @NonNull Image FOLDER_ICON;
41
42 public static final WorkbenchLabelProvider WORKSPACE_LABEL_PROVIDER = new WorkbenchLabelProvider();
43
44 private static final String TRACE_ICON_FILE = "icons/elcl16/trace.gif"; //$NON-NLS-1$
45 private static final String EXPERIMENT_ICON_FILE = "icons/elcl16/experiment.gif"; //$NON-NLS-1$
46 private static final String ANALYSIS_ICON_FILE = "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$
47 private static final String VIEW_ICON_FILE = "icons/obj16/node_obj.gif"; //$NON-NLS-1$
48
49 // ------------------------------------------------------------------------
50 // Initialization
51 // ------------------------------------------------------------------------
52
53 static {
54 FOLDER_ICON = checkNotNull(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
55
56 Bundle bundle = Activator.getDefault().getBundle();
57 DEFAULT_TRACE_ICON = checkNotNull(loadIcon(bundle, TRACE_ICON_FILE));
58 DEFAULT_EXPERIMENT_ICON = checkNotNull(loadIcon(bundle, EXPERIMENT_ICON_FILE));
59 DEFAULT_ANALYSIS_ICON = checkNotNull(loadIcon(bundle, ANALYSIS_ICON_FILE));
60 DEFAULT_VIEW_ICON = checkNotNull(loadIcon(bundle, VIEW_ICON_FILE));
61 }
62
63 public static @Nullable Image loadIcon(Bundle bundle, String url) {
64 Activator plugin = Activator.getDefault();
65 String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$
66 Image icon = plugin.getImageRegistry().get(key);
67 if (icon == null) {
68 URL imageURL = bundle.getResource(url);
69 ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
70 if (descriptor != null) {
71 icon = descriptor.createImage();
72 plugin.getImageRegistry().put(key, icon);
73 }
74 }
75 return icon;
76 }
77 }
This page took 0.034204 seconds and 5 git commands to generate.