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
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
22 import org
.eclipse
.jface
.resource
.ImageRegistry
;
23 import org
.eclipse
.swt
.graphics
.Image
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.relayd
.LttngRelaydConnectionManager
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
26 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
27 import org
.osgi
.framework
.BundleContext
;
28 import org
.osgi
.framework
.ServiceReference
;
31 * The activator class controls the plug-in life cycle
33 public class Activator
extends AbstractUIPlugin
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
42 public static final String PLUGIN_ID
= "org.eclipse.linuxtools.lttng2.control.ui"; //$NON-NLS-1$
47 private static Activator plugin
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Returns the shared instance
66 * @return the shared instance
68 public static Activator
getDefault() {
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 public void start(BundleContext context
) throws Exception
{
80 ControlPreferences
.getInstance().init(getPreferenceStore());
81 // This registers the connection manager with the signal manager
82 LttngRelaydConnectionManager
.getInstance();
86 public void stop(BundleContext context
) throws Exception
{
87 ControlPreferences
.getInstance().dispose();
88 LttngRelaydConnectionManager
.getInstance().dispose();
94 protected void initializeImageRegistry(ImageRegistry reg
) {
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
102 * Gets an image object using given path within plug-in.
104 * @param path path to image file
106 * @return image object
108 public Image
getImageFromPath(String path
) {
109 return getImageDescripterFromPath(path
).createImage();
113 * Gets an image descriptor using given path within plug-in.
115 * @param path path to image file
117 * @return image descriptor object
119 public ImageDescriptor
getImageDescripterFromPath(String path
) {
120 return AbstractUIPlugin
.imageDescriptorFromPlugin(PLUGIN_ID
, path
);
124 * Gets a image object from the image registry based on the given path.
125 * If the image is not in the registry it will be registered.
127 * @param path to the image file
128 * @return image object
130 public Image
getImageFromImageRegistry(String path
) {
131 Image icon
= getImageRegistry().get(path
);
133 icon
= getImageDescripterFromPath(path
).createImage();
134 plugin
.getImageRegistry().put(path
, icon
);
140 * Loads the image in the plug-ins image registry (if necessary) and returns the image
141 * @param url - URL relative to the Bundle
144 public Image
loadIcon(String url
) {
145 String key
= plugin
.getBundle().getSymbolicName() + "/" + url
; //$NON-NLS-1$
146 Image icon
= plugin
.getImageRegistry().get(key
);
148 URL imageURL
= plugin
.getBundle().getResource(url
);
149 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
150 icon
= descriptor
.createImage();
151 plugin
.getImageRegistry().put(key
, icon
);
157 * Logs a message with severity INFO in the runtime log of the plug-in.
159 * @param message A message to log
161 public void logInfo(String message
) {
162 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
));
166 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
168 * @param message A message to log
169 * @param exception A exception to log
171 public void logInfo(String message
, Throwable exception
) {
172 getLog().log(new Status(IStatus
.INFO
, PLUGIN_ID
, message
, exception
));
176 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
178 * @param message A message to log
180 public void logWarning(String message
) {
181 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
));
185 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
187 * @param message A message to log
188 * @param exception A exception to log
190 public void logWarning(String message
, Throwable exception
) {
191 getLog().log(new Status(IStatus
.WARNING
, PLUGIN_ID
, message
, exception
));
195 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
197 * @param message A message to log
199 public void logError(String message
) {
200 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
));
204 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
206 * @param message A message to log
207 * @param exception A exception to log
209 public void logError(String message
, Throwable exception
) {
210 getLog().log(new Status(IStatus
.ERROR
, PLUGIN_ID
, message
, exception
));
214 * Return the OSGi service with the given service interface.
218 * @return the specified service or null if it's not registered
220 public static @Nullable <T
> T
getService(Class
<T
> service
) {
221 BundleContext context
= plugin
.getBundle().getBundleContext();
222 ServiceReference
<T
> ref
= context
.getServiceReference(service
);
223 return ((ref
!= null) ? context
.getService(ref
) : null);