1 /*******************************************************************************
2 * Copyright (c) 2012 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
.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
.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
;
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.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 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
76 public void start(BundleContext context
) throws Exception
{
79 ControlPreferences
.getInstance().init(getPreferenceStore());
83 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
86 public void stop(BundleContext context
) throws Exception
{
87 ControlPreferences
.getInstance().dispose();
93 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
96 protected void initializeImageRegistry(ImageRegistry reg
) {
99 // ------------------------------------------------------------------------
101 // ------------------------------------------------------------------------
104 * Gets an image object using given path within plug-in.
106 * @param path path to image file
108 * @return image object
110 public Image
getImageFromPath(String path
) {
111 return getImageDescripterFromPath(path
).createImage();
115 * Gets an image descriptor using given path within plug-in.
117 * @param path path to image file
119 * @return image descriptor object
121 public ImageDescriptor
getImageDescripterFromPath(String path
) {
122 return AbstractUIPlugin
.imageDescriptorFromPlugin(PLUGIN_ID
, path
);
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.
129 * @param path to the image file
130 * @return image object
132 public Image
getImageFromImageRegistry(String path
) {
133 Image icon
= getImageRegistry().get(path
);
135 icon
= getImageDescripterFromPath(path
).createImage();
136 plugin
.getImageRegistry().put(path
, icon
);
142 * Loads the image in the plug-ins image registry (if necessary) and returns the image
143 * @param url - URL relative to the Bundle
146 public Image
loadIcon(String url
) {
147 String key
= plugin
.getBundle().getSymbolicName() + "/" + url
; //$NON-NLS-1$
148 Image icon
= plugin
.getImageRegistry().get(key
);
150 URL imageURL
= plugin
.getBundle().getResource(url
);
151 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
152 icon
= descriptor
.createImage();
153 plugin
.getImageRegistry().put(key
, icon
);
159 * Logs a message with severity INFO in the runtime log of the plug-in.
161 * @param message A message to log
163 public void logInfo(String message
) {
164 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
));
168 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
170 * @param message A message to log
171 * @param exception A exception to log
173 public void logInfo(String message
, Throwable exception
) {
174 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
, exception
));
178 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
180 * @param message A message to log
182 public void logWarning(String message
) {
183 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
));
187 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
189 * @param message A message to log
190 * @param exception A exception to log
192 public void logWarning(String message
, Throwable exception
) {
193 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
, exception
));
197 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
199 * @param message A message to log
201 public void logError(String message
) {
202 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
));
206 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
208 * @param message A message to log
209 * @param exception A exception to log
211 public void logError(String message
, Throwable exception
) {
212 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
, exception
));