lttng: Rename lttng2 feature/plugins to lttng2.control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / Activator.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
13 package org.eclipse.linuxtools.internal.lttng2.control.ui;
14
15 import java.net.URL;
16
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.preferences.ControlPreferences;
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.control.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
72 @Override
73 public void start(BundleContext context) throws Exception {
74 super.start(context);
75 plugin = this;
76 ControlPreferences.getInstance().init(getPreferenceStore());
77 }
78
79 @Override
80 public void stop(BundleContext context) throws Exception {
81 ControlPreferences.getInstance().dispose();
82 plugin = null;
83 super.stop(context);
84 }
85
86 @Override
87 protected void initializeImageRegistry(ImageRegistry reg) {
88 }
89
90 // ------------------------------------------------------------------------
91 // Operations
92 // ------------------------------------------------------------------------
93
94 /**
95 * Gets an image object using given path within plug-in.
96 *
97 * @param path path to image file
98 *
99 * @return image object
100 */
101 public Image getImageFromPath(String path) {
102 return getImageDescripterFromPath(path).createImage();
103 }
104
105 /**
106 * Gets an image descriptor using given path within plug-in.
107 *
108 * @param path path to image file
109 *
110 * @return image descriptor object
111 */
112 public ImageDescriptor getImageDescripterFromPath(String path) {
113 return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
114 }
115
116 /**
117 * Gets a image object from the image registry based on the given path.
118 * If the image is not in the registry it will be registered.
119 *
120 * @param path to the image file
121 * @return image object
122 */
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 }
131
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 }
148
149 /**
150 * Logs a message with severity INFO in the runtime log of the plug-in.
151 *
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 }
157
158 /**
159 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
160 *
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.
170 *
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 }
176
177 /**
178 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
179 *
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.
189 *
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 }
195
196 /**
197 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
198 *
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 }
205
206 }
This page took 0.035072 seconds and 5 git commands to generate.