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; |
dff70ccd AM |
43 | |
44 | public static final WorkbenchLabelProvider WORKSPACE_LABEL_PROVIDER = new WorkbenchLabelProvider(); | |
45 | ||
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$ | |
50 | ||
51 | // ------------------------------------------------------------------------ | |
52 | // Initialization | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
55 | static { | |
5c727157 AM |
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)); | |
dff70ccd AM |
59 | |
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)); | |
65 | } | |
66 | ||
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); | |
71 | if (icon == null) { | |
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); | |
77 | } | |
78 | } | |
79 | return icon; | |
80 | } | |
81 | } |