1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
;
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
;
27 * The activator class controls the plug-in life cycle
29 public class Activator
extends AbstractUIPlugin
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
38 public static final String PLUGIN_ID
= "org.eclipse.linuxtools.lttng2.control.ui"; //$NON-NLS-1$
43 private static Activator plugin
;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * Returns the shared instance
62 * @return the shared instance
64 public static Activator
getDefault() {
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 public void start(BundleContext context
) throws Exception
{
76 ControlPreferences
.getInstance().init(getPreferenceStore());
80 public void stop(BundleContext context
) throws Exception
{
81 ControlPreferences
.getInstance().dispose();
87 protected void initializeImageRegistry(ImageRegistry reg
) {
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 * Gets an image object using given path within plug-in.
97 * @param path path to image file
99 * @return image object
101 public Image
getImageFromPath(String path
) {
102 return getImageDescripterFromPath(path
).createImage();
106 * Gets an image descriptor using given path within plug-in.
108 * @param path path to image file
110 * @return image descriptor object
112 public ImageDescriptor
getImageDescripterFromPath(String path
) {
113 return AbstractUIPlugin
.imageDescriptorFromPlugin(PLUGIN_ID
, path
);
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.
120 * @param path to the image file
121 * @return image object
123 public Image
getImageFromImageRegistry(String path
) {
124 Image icon
= getImageRegistry().get(path
);
126 icon
= getImageDescripterFromPath(path
).createImage();
127 plugin
.getImageRegistry().put(path
, icon
);
133 * Loads the image in the plug-ins image registry (if necessary) and returns the image
134 * @param url - URL relative to the Bundle
137 public Image
loadIcon(String url
) {
138 String key
= plugin
.getBundle().getSymbolicName() + "/" + url
; //$NON-NLS-1$
139 Image icon
= plugin
.getImageRegistry().get(key
);
141 URL imageURL
= plugin
.getBundle().getResource(url
);
142 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
143 icon
= descriptor
.createImage();
144 plugin
.getImageRegistry().put(key
, icon
);
150 * Logs a message with severity INFO in the runtime log of the plug-in.
152 * @param message A message to log
154 public void logInfo(String message
) {
155 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
));
159 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
161 * @param message A message to log
162 * @param exception A exception to log
164 public void logInfo(String message
, Throwable exception
) {
165 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
, exception
));
169 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
171 * @param message A message to log
173 public void logWarning(String message
) {
174 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
));
178 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
180 * @param message A message to log
181 * @param exception A exception to log
183 public void logWarning(String message
, Throwable exception
) {
184 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
, exception
));
188 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
190 * @param message A message to log
192 public void logError(String message
) {
193 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
));
197 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
199 * @param message A message to log
200 * @param exception A exception to log
202 public void logError(String message
, Throwable exception
) {
203 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
, exception
));