Commit | Line | Data |
---|---|---|
dff70ccd AM |
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; | |
6fd57ff7 | 40 | public static final @NonNull Image DEFAULT_REPORT_ICON; |
5c727157 | 41 | |
dff70ccd | 42 | public static final @NonNull Image FOLDER_ICON; |
5c727157 | 43 | public static final @NonNull Image VIEWS_ICON; |
ddfa2689 AM |
44 | public static final @NonNull Image ONDEMAND_ANALYSES_ICON; |
45 | public static final @NonNull Image REPORTS_ICON; | |
dff70ccd AM |
46 | |
47 | public static final WorkbenchLabelProvider WORKSPACE_LABEL_PROVIDER = new WorkbenchLabelProvider(); | |
48 | ||
49 | private static final String TRACE_ICON_FILE = "icons/elcl16/trace.gif"; //$NON-NLS-1$ | |
50 | private static final String EXPERIMENT_ICON_FILE = "icons/elcl16/experiment.gif"; //$NON-NLS-1$ | |
51 | private static final String ANALYSIS_ICON_FILE = "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$ | |
52 | private static final String VIEW_ICON_FILE = "icons/obj16/node_obj.gif"; //$NON-NLS-1$ | |
ddfa2689 AM |
53 | private static final String ONDEMAND_ANALYSES_ICON_FILE = "icons/obj16/debugt_obj.gif"; //$NON-NLS-1$ |
54 | private static final String REPORTS_ICON_FILE = "icons/obj16/arraypartition_obj.gif"; //$NON-NLS-1$ | |
6fd57ff7 | 55 | private static final String DEFAULT_REPORT_ICON_FILE = "icons/etool16/copy_edit.gif"; //$NON-NLS-1$ |
e55bb5d9 | 56 | private static final String VIEWS_ICON_FILE = "icons/obj16/analysisprovider_obj.gif"; //$NON-NLS-1$ |
dff70ccd AM |
57 | |
58 | // ------------------------------------------------------------------------ | |
59 | // Initialization | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
62 | static { | |
5c727157 | 63 | ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); |
ddfa2689 AM |
64 | Bundle bundle = Activator.getDefault().getBundle(); |
65 | ||
5c727157 | 66 | FOLDER_ICON = checkNotNull(sharedImages.getImage(ISharedImages.IMG_OBJ_FOLDER)); |
ddfa2689 AM |
67 | ONDEMAND_ANALYSES_ICON = checkNotNull(loadIcon(bundle, ONDEMAND_ANALYSES_ICON_FILE)); |
68 | REPORTS_ICON = checkNotNull(loadIcon(bundle, REPORTS_ICON_FILE)); | |
dff70ccd | 69 | |
dff70ccd AM |
70 | DEFAULT_TRACE_ICON = checkNotNull(loadIcon(bundle, TRACE_ICON_FILE)); |
71 | DEFAULT_EXPERIMENT_ICON = checkNotNull(loadIcon(bundle, EXPERIMENT_ICON_FILE)); | |
72 | DEFAULT_ANALYSIS_ICON = checkNotNull(loadIcon(bundle, ANALYSIS_ICON_FILE)); | |
73 | DEFAULT_VIEW_ICON = checkNotNull(loadIcon(bundle, VIEW_ICON_FILE)); | |
6fd57ff7 | 74 | DEFAULT_REPORT_ICON = checkNotNull(loadIcon(bundle, DEFAULT_REPORT_ICON_FILE)); |
e55bb5d9 | 75 | VIEWS_ICON = checkNotNull(loadIcon(bundle, VIEWS_ICON_FILE)); |
dff70ccd AM |
76 | } |
77 | ||
78 | public static @Nullable Image loadIcon(Bundle bundle, String url) { | |
79 | Activator plugin = Activator.getDefault(); | |
80 | String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$ | |
81 | Image icon = plugin.getImageRegistry().get(key); | |
82 | if (icon == null) { | |
83 | URL imageURL = bundle.getResource(url); | |
84 | ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); | |
85 | if (descriptor != null) { | |
86 | icon = descriptor.createImage(); | |
87 | plugin.getImageRegistry().put(key, icon); | |
88 | } | |
89 | } | |
90 | return icon; | |
91 | } | |
92 | } |