1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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 * Bernd Hufmann - Add Utility to get a OSGI service
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
21 import org
.eclipse
.jface
.resource
.ImageRegistry
;
22 import org
.eclipse
.swt
.graphics
.Image
;
23 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.relayd
.LttngRelaydConnectionManager
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
25 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
26 import org
.osgi
.framework
.BundleContext
;
29 * The activator class controls the plug-in life cycle
31 public class Activator
extends AbstractUIPlugin
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
40 public static final String PLUGIN_ID
= "org.eclipse.tracecompass.lttng2.control.ui"; //$NON-NLS-1$
45 private static Activator plugin
;
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
62 * Returns the shared instance
64 * @return the shared instance
66 public static Activator
getDefault() {
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
75 public void start(BundleContext context
) throws Exception
{
78 ControlPreferences
.getInstance().init(getPreferenceStore());
79 // This registers the connection manager with the signal manager
80 LttngRelaydConnectionManager
.getInstance();
84 public void stop(BundleContext context
) throws Exception
{
85 ControlPreferences
.getInstance().dispose();
86 LttngRelaydConnectionManager
.getInstance().dispose();
92 protected void initializeImageRegistry(ImageRegistry reg
) {
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 * Gets an image object using given path within plug-in.
102 * @param path path to image file
104 * @return image object
106 public Image
getImageFromPath(String path
) {
107 return getImageDescripterFromPath(path
).createImage();
111 * Gets an image descriptor using given path within plug-in.
113 * @param path path to image file
115 * @return image descriptor object
117 public ImageDescriptor
getImageDescripterFromPath(String path
) {
118 return AbstractUIPlugin
.imageDescriptorFromPlugin(PLUGIN_ID
, path
);
122 * Gets a image object from the image registry based on the given path.
123 * If the image is not in the registry it will be registered.
125 * @param path to the image file
126 * @return image object
128 public Image
getImageFromImageRegistry(String path
) {
129 Image icon
= getImageRegistry().get(path
);
131 icon
= getImageDescripterFromPath(path
).createImage();
132 plugin
.getImageRegistry().put(path
, icon
);
138 * Loads the image in the plug-ins image registry (if necessary) and returns the image
139 * @param url - URL relative to the Bundle
142 public Image
loadIcon(String url
) {
143 String key
= plugin
.getBundle().getSymbolicName() + "/" + url
; //$NON-NLS-1$
144 Image icon
= plugin
.getImageRegistry().get(key
);
146 URL imageURL
= plugin
.getBundle().getResource(url
);
147 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
148 icon
= descriptor
.createImage();
149 plugin
.getImageRegistry().put(key
, icon
);
155 * Logs a message with severity INFO in the runtime log of the plug-in.
157 * @param message A message to log
159 public void logInfo(String message
) {
160 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
));
164 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
166 * @param message A message to log
167 * @param exception A exception to log
169 public void logInfo(String message
, Throwable exception
) {
170 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
, exception
));
174 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
176 * @param message A message to log
178 public void logWarning(String message
) {
179 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
));
183 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
185 * @param message A message to log
186 * @param exception A exception to log
188 public void logWarning(String message
, Throwable exception
) {
189 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
, exception
));
193 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
195 * @param message A message to log
197 public void logError(String message
) {
198 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
));
202 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
204 * @param message A message to log
205 * @param exception A exception to log
207 public void logError(String message
, Throwable exception
) {
208 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
, exception
));