Commit | Line | Data |
---|---|---|
a7780cc8 | 1 | /******************************************************************************* |
11252342 AM |
2 | * Copyright (c) 2012, 2013 Ericsson |
3 | * | |
a7780cc8 FC |
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 | |
11252342 | 8 | * |
a7780cc8 FC |
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 | ||
9fa32496 BH |
17 | import org.eclipse.core.runtime.IStatus; |
18 | import org.eclipse.core.runtime.Status; | |
a7780cc8 FC |
19 | import org.eclipse.jface.resource.ImageDescriptor; |
20 | import org.eclipse.jface.resource.ImageRegistry; | |
afe13e7a | 21 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences; |
a7780cc8 FC |
22 | import org.eclipse.swt.graphics.Image; |
23 | import org.eclipse.ui.plugin.AbstractUIPlugin; | |
24 | import org.osgi.framework.BundleContext; | |
25 | ||
26 | /** | |
27 | * The activator class controls the plug-in life cycle | |
28 | */ | |
29 | public class Activator extends AbstractUIPlugin { | |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Attributes | |
33 | // ------------------------------------------------------------------------ | |
34 | ||
35 | /** | |
36 | * The plug-in ID | |
37 | */ | |
38 | public static final String PLUGIN_ID = "org.eclipse.linuxtools.lttng2.ui"; //$NON-NLS-1$ | |
39 | ||
40 | /** | |
41 | * The shared instance | |
42 | */ | |
43 | private static Activator plugin; | |
44 | ||
45 | // ------------------------------------------------------------------------ | |
46 | // Constructors | |
47 | // ------------------------------------------------------------------------ | |
48 | ||
49 | /** | |
50 | * The constructor | |
51 | */ | |
52 | public Activator() { | |
53 | } | |
54 | ||
55 | // ------------------------------------------------------------------------ | |
56 | // Accessors | |
57 | // ------------------------------------------------------------------------ | |
58 | ||
59 | /** | |
60 | * Returns the shared instance | |
61 | * | |
62 | * @return the shared instance | |
63 | */ | |
64 | public static Activator getDefault() { | |
65 | return plugin; | |
66 | } | |
67 | ||
68 | // ------------------------------------------------------------------------ | |
69 | // AbstractUIPlugin | |
70 | // ------------------------------------------------------------------------ | |
71 | ||
a7780cc8 FC |
72 | @Override |
73 | public void start(BundleContext context) throws Exception { | |
74 | super.start(context); | |
75 | plugin = this; | |
9315aeee | 76 | ControlPreferences.getInstance().init(getPreferenceStore()); |
a7780cc8 FC |
77 | } |
78 | ||
a7780cc8 FC |
79 | @Override |
80 | public void stop(BundleContext context) throws Exception { | |
afe13e7a | 81 | ControlPreferences.getInstance().dispose(); |
a7780cc8 FC |
82 | plugin = null; |
83 | super.stop(context); | |
84 | } | |
85 | ||
a7780cc8 FC |
86 | @Override |
87 | protected void initializeImageRegistry(ImageRegistry reg) { | |
88 | } | |
89 | ||
90 | // ------------------------------------------------------------------------ | |
91 | // Operations | |
92 | // ------------------------------------------------------------------------ | |
93 | ||
9fa32496 BH |
94 | /** |
95 | * Gets an image object using given path within plug-in. | |
11252342 | 96 | * |
9fa32496 | 97 | * @param path path to image file |
11252342 | 98 | * |
9fa32496 BH |
99 | * @return image object |
100 | */ | |
a7780cc8 FC |
101 | public Image getImageFromPath(String path) { |
102 | return getImageDescripterFromPath(path).createImage(); | |
103 | } | |
104 | ||
9fa32496 BH |
105 | /** |
106 | * Gets an image descriptor using given path within plug-in. | |
11252342 AM |
107 | * |
108 | * @param path path to image file | |
109 | * | |
9fa32496 BH |
110 | * @return image descriptor object |
111 | */ | |
a7780cc8 FC |
112 | public ImageDescriptor getImageDescripterFromPath(String path) { |
113 | return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); | |
114 | } | |
115 | ||
9fa32496 BH |
116 | /** |
117 | * Gets a image object from the image registry based on the given path. | |
11252342 AM |
118 | * If the image is not in the registry it will be registered. |
119 | * | |
120 | * @param path to the image file | |
9fa32496 BH |
121 | * @return image object |
122 | */ | |
a7780cc8 FC |
123 | public Image getImageFromImageRegistry(String path) { |
124 | Image icon = getImageRegistry().get(path); | |
125 | if (icon == null) { | |
126 | icon = getImageDescripterFromPath(path).createImage(); | |
127 | plugin.getImageRegistry().put(path, icon); | |
128 | } | |
129 | return icon; | |
130 | } | |
11252342 | 131 | |
115b4a01 BH |
132 | /** |
133 | * Loads the image in the plug-ins image registry (if necessary) and returns the image | |
134 | * @param url - URL relative to the Bundle | |
135 | * @return the image | |
136 | */ | |
137 | public Image loadIcon(String url) { | |
138 | String key = plugin.getBundle().getSymbolicName() + "/" + url; //$NON-NLS-1$ | |
139 | Image icon = plugin.getImageRegistry().get(key); | |
140 | if (icon == null) { | |
141 | URL imageURL = plugin.getBundle().getResource(url); | |
142 | ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); | |
143 | icon = descriptor.createImage(); | |
144 | plugin.getImageRegistry().put(key, icon); | |
145 | } | |
146 | return icon; | |
147 | } | |
11252342 | 148 | |
9fa32496 BH |
149 | /** |
150 | * Logs a message with severity INFO in the runtime log of the plug-in. | |
11252342 | 151 | * |
9fa32496 BH |
152 | * @param message A message to log |
153 | */ | |
154 | public void logInfo(String message) { | |
155 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); | |
156 | } | |
11252342 | 157 | |
9fa32496 BH |
158 | /** |
159 | * Logs a message and exception with severity INFO in the runtime log of the plug-in. | |
11252342 | 160 | * |
9fa32496 BH |
161 | * @param message A message to log |
162 | * @param exception A exception to log | |
163 | */ | |
164 | public void logInfo(String message, Throwable exception) { | |
165 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception)); | |
166 | } | |
167 | ||
168 | /** | |
169 | * Logs a message and exception with severity WARNING in the runtime log of the plug-in. | |
11252342 | 170 | * |
9fa32496 BH |
171 | * @param message A message to log |
172 | */ | |
173 | public void logWarning(String message) { | |
174 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
175 | } | |
11252342 | 176 | |
9fa32496 BH |
177 | /** |
178 | * Logs a message and exception with severity WARNING in the runtime log of the plug-in. | |
11252342 | 179 | * |
9fa32496 BH |
180 | * @param message A message to log |
181 | * @param exception A exception to log | |
182 | */ | |
183 | public void logWarning(String message, Throwable exception) { | |
184 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception)); | |
185 | } | |
186 | ||
187 | /** | |
188 | * Logs a message and exception with severity ERROR in the runtime log of the plug-in. | |
11252342 | 189 | * |
9fa32496 BH |
190 | * @param message A message to log |
191 | */ | |
192 | public void logError(String message) { | |
193 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
194 | } | |
11252342 | 195 | |
9fa32496 BH |
196 | /** |
197 | * Logs a message and exception with severity ERROR in the runtime log of the plug-in. | |
11252342 | 198 | * |
9fa32496 BH |
199 | * @param message A message to log |
200 | * @param exception A exception to log | |
201 | */ | |
202 | public void logError(String message, Throwable exception) { | |
203 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); | |
204 | } | |
a7780cc8 FC |
205 | |
206 | } |