Replace printStackTrace() with proper logging in TMF and LTTng
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / Activator.java
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
13 package org.eclipse.linuxtools.internal.lttng2.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.ui.views.control.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.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 /* (non-Javadoc)
73 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
74 */
75 @Override
76 public void start(BundleContext context) throws Exception {
77 super.start(context);
78 plugin = this;
79 ControlPreferences.getInstance().init(getPreferenceStore());
80 }
81
82 /* (non-Javadoc)
83 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
84 */
85 @Override
86 public void stop(BundleContext context) throws Exception {
87 ControlPreferences.getInstance().dispose();
88 plugin = null;
89 super.stop(context);
90 }
91
92 /* (non-Javadoc)
93 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
94 */
95 @Override
96 protected void initializeImageRegistry(ImageRegistry reg) {
97 }
98
99 // ------------------------------------------------------------------------
100 // Operations
101 // ------------------------------------------------------------------------
102
103 /**
104 * Gets an image object using given path within plug-in.
105 *
106 * @param path path to image file
107 *
108 * @return image object
109 */
110 public Image getImageFromPath(String path) {
111 return getImageDescripterFromPath(path).createImage();
112 }
113
114 /**
115 * Gets an image descriptor using given path within plug-in.
116 *
117 * @param path path to image file
118 *
119 * @return image descriptor object
120 */
121 public ImageDescriptor getImageDescripterFromPath(String path) {
122 return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
123 }
124
125 /**
126 * Gets a image object from the image registry based on the given path.
127 * If the image is not in the registry it will be registered.
128 *
129 * @param path to the image file
130 * @return image object
131 */
132 public Image getImageFromImageRegistry(String path) {
133 Image icon = getImageRegistry().get(path);
134 if (icon == null) {
135 icon = getImageDescripterFromPath(path).createImage();
136 plugin.getImageRegistry().put(path, icon);
137 }
138 return icon;
139 }
140
141 /**
142 * Loads the image in the plug-ins image registry (if necessary) and returns the image
143 * @param url - URL relative to the Bundle
144 * @return the image
145 */
146 public Image loadIcon(String url) {
147 String key = plugin.getBundle().getSymbolicName() + "/" + url; //$NON-NLS-1$
148 Image icon = plugin.getImageRegistry().get(key);
149 if (icon == null) {
150 URL imageURL = plugin.getBundle().getResource(url);
151 ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
152 icon = descriptor.createImage();
153 plugin.getImageRegistry().put(key, icon);
154 }
155 return icon;
156 }
157
158 /**
159 * Logs a message with severity INFO in the runtime log of the plug-in.
160 *
161 * @param message A message to log
162 */
163 public void logInfo(String message) {
164 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
165 }
166
167 /**
168 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
169 *
170 * @param message A message to log
171 * @param exception A exception to log
172 */
173 public void logInfo(String message, Throwable exception) {
174 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception));
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 */
182 public void logWarning(String message) {
183 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message));
184 }
185
186 /**
187 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
188 *
189 * @param message A message to log
190 * @param exception A exception to log
191 */
192 public void logWarning(String message, Throwable exception) {
193 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception));
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 */
201 public void logError(String message) {
202 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message));
203 }
204
205 /**
206 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
207 *
208 * @param message A message to log
209 * @param exception A exception to log
210 */
211 public void logError(String message, Throwable exception) {
212 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception));
213 }
214
215 }
This page took 0.043285 seconds and 6 git commands to generate.