Commit | Line | Data |
---|---|---|
a7780cc8 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
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 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
1ee4d327 | 13 | package org.eclipse.linuxtools.internal.lttng2.ui; |
a7780cc8 | 14 | |
115b4a01 BH |
15 | import java.net.URL; |
16 | ||
a7780cc8 FC |
17 | import org.eclipse.jface.resource.ImageDescriptor; |
18 | import org.eclipse.jface.resource.ImageRegistry; | |
afe13e7a | 19 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences; |
a7780cc8 FC |
20 | import org.eclipse.swt.graphics.Image; |
21 | import org.eclipse.ui.plugin.AbstractUIPlugin; | |
22 | import org.osgi.framework.BundleContext; | |
23 | ||
24 | /** | |
25 | * The activator class controls the plug-in life cycle | |
26 | */ | |
27 | public class Activator extends AbstractUIPlugin { | |
28 | ||
29 | // ------------------------------------------------------------------------ | |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
33 | /** | |
34 | * The plug-in ID | |
35 | */ | |
36 | public static final String PLUGIN_ID = "org.eclipse.linuxtools.lttng2.ui"; //$NON-NLS-1$ | |
37 | ||
38 | /** | |
39 | * The shared instance | |
40 | */ | |
41 | private static Activator plugin; | |
42 | ||
43 | // ------------------------------------------------------------------------ | |
44 | // Constructors | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
47 | /** | |
48 | * The constructor | |
49 | */ | |
50 | public Activator() { | |
51 | } | |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Accessors | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
57 | /** | |
58 | * Returns the shared instance | |
59 | * | |
60 | * @return the shared instance | |
61 | */ | |
62 | public static Activator getDefault() { | |
63 | return plugin; | |
64 | } | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // AbstractUIPlugin | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | /* (non-Javadoc) | |
71 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) | |
72 | */ | |
73 | @Override | |
74 | public void start(BundleContext context) throws Exception { | |
75 | super.start(context); | |
76 | plugin = this; | |
9315aeee | 77 | ControlPreferences.getInstance().init(getPreferenceStore()); |
a7780cc8 FC |
78 | } |
79 | ||
80 | /* (non-Javadoc) | |
81 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) | |
82 | */ | |
83 | @Override | |
84 | public void stop(BundleContext context) throws Exception { | |
afe13e7a | 85 | ControlPreferences.getInstance().dispose(); |
a7780cc8 FC |
86 | plugin = null; |
87 | super.stop(context); | |
88 | } | |
89 | ||
90 | /* (non-Javadoc) | |
91 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry) | |
92 | */ | |
93 | @Override | |
94 | protected void initializeImageRegistry(ImageRegistry reg) { | |
95 | } | |
96 | ||
97 | // ------------------------------------------------------------------------ | |
98 | // Operations | |
99 | // ------------------------------------------------------------------------ | |
100 | ||
101 | public Image getImageFromPath(String path) { | |
102 | return getImageDescripterFromPath(path).createImage(); | |
103 | } | |
104 | ||
105 | public ImageDescriptor getImageDescripterFromPath(String path) { | |
106 | return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); | |
107 | } | |
108 | ||
109 | public Image getImageFromImageRegistry(String path) { | |
110 | Image icon = getImageRegistry().get(path); | |
111 | if (icon == null) { | |
112 | icon = getImageDescripterFromPath(path).createImage(); | |
113 | plugin.getImageRegistry().put(path, icon); | |
114 | } | |
115 | return icon; | |
116 | } | |
115b4a01 BH |
117 | |
118 | /** | |
119 | * Loads the image in the plug-ins image registry (if necessary) and returns the image | |
120 | * @param url - URL relative to the Bundle | |
121 | * @return the image | |
122 | */ | |
123 | public Image loadIcon(String url) { | |
124 | String key = plugin.getBundle().getSymbolicName() + "/" + url; //$NON-NLS-1$ | |
125 | Image icon = plugin.getImageRegistry().get(key); | |
126 | if (icon == null) { | |
127 | URL imageURL = plugin.getBundle().getResource(url); | |
128 | ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); | |
129 | icon = descriptor.createImage(); | |
130 | plugin.getImageRegistry().put(key, icon); | |
131 | } | |
132 | return icon; | |
133 | } | |
a7780cc8 FC |
134 | |
135 | } |