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