tmf: Bug 460842: Introduce tmf remote plug-ins and feature
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / Activator.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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 * Bernd Hufmann - Add Utility to get a OSGI service
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.internal.lttng2.control.ui;
15
16 import java.net.URL;
17
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;
27
28 /**
29 * The activator class controls the plug-in life cycle
30 */
31 public class Activator extends AbstractUIPlugin {
32
33 // ------------------------------------------------------------------------
34 // Attributes
35 // ------------------------------------------------------------------------
36
37 /**
38 * The plug-in ID
39 */
40 public static final String PLUGIN_ID = "org.eclipse.linuxtools.lttng2.control.ui"; //$NON-NLS-1$
41
42 /**
43 * The shared instance
44 */
45 private static Activator plugin;
46
47 // ------------------------------------------------------------------------
48 // Constructors
49 // ------------------------------------------------------------------------
50
51 /**
52 * The constructor
53 */
54 public Activator() {
55 }
56
57 // ------------------------------------------------------------------------
58 // Accessors
59 // ------------------------------------------------------------------------
60
61 /**
62 * Returns the shared instance
63 *
64 * @return the shared instance
65 */
66 public static Activator getDefault() {
67 return plugin;
68 }
69
70 // ------------------------------------------------------------------------
71 // AbstractUIPlugin
72 // ------------------------------------------------------------------------
73
74 @Override
75 public void start(BundleContext context) throws Exception {
76 super.start(context);
77 plugin = this;
78 ControlPreferences.getInstance().init(getPreferenceStore());
79 // This registers the connection manager with the signal manager
80 LttngRelaydConnectionManager.getInstance();
81 }
82
83 @Override
84 public void stop(BundleContext context) throws Exception {
85 ControlPreferences.getInstance().dispose();
86 LttngRelaydConnectionManager.getInstance().dispose();
87 plugin = null;
88 super.stop(context);
89 }
90
91 @Override
92 protected void initializeImageRegistry(ImageRegistry reg) {
93 }
94
95 // ------------------------------------------------------------------------
96 // Operations
97 // ------------------------------------------------------------------------
98
99 /**
100 * Gets an image object using given path within plug-in.
101 *
102 * @param path path to image file
103 *
104 * @return image object
105 */
106 public Image getImageFromPath(String path) {
107 return getImageDescripterFromPath(path).createImage();
108 }
109
110 /**
111 * Gets an image descriptor using given path within plug-in.
112 *
113 * @param path path to image file
114 *
115 * @return image descriptor object
116 */
117 public ImageDescriptor getImageDescripterFromPath(String path) {
118 return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
119 }
120
121 /**
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.
124 *
125 * @param path to the image file
126 * @return image object
127 */
128 public Image getImageFromImageRegistry(String path) {
129 Image icon = getImageRegistry().get(path);
130 if (icon == null) {
131 icon = getImageDescripterFromPath(path).createImage();
132 plugin.getImageRegistry().put(path, icon);
133 }
134 return icon;
135 }
136
137 /**
138 * Loads the image in the plug-ins image registry (if necessary) and returns the image
139 * @param url - URL relative to the Bundle
140 * @return the image
141 */
142 public Image loadIcon(String url) {
143 String key = plugin.getBundle().getSymbolicName() + "/" + url; //$NON-NLS-1$
144 Image icon = plugin.getImageRegistry().get(key);
145 if (icon == null) {
146 URL imageURL = plugin.getBundle().getResource(url);
147 ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
148 icon = descriptor.createImage();
149 plugin.getImageRegistry().put(key, icon);
150 }
151 return icon;
152 }
153
154 /**
155 * Logs a message with severity INFO in the runtime log of the plug-in.
156 *
157 * @param message A message to log
158 */
159 public void logInfo(String message) {
160 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
161 }
162
163 /**
164 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
165 *
166 * @param message A message to log
167 * @param exception A exception to log
168 */
169 public void logInfo(String message, Throwable exception) {
170 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception));
171 }
172
173 /**
174 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
175 *
176 * @param message A message to log
177 */
178 public void logWarning(String message) {
179 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message));
180 }
181
182 /**
183 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
184 *
185 * @param message A message to log
186 * @param exception A exception to log
187 */
188 public void logWarning(String message, Throwable exception) {
189 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception));
190 }
191
192 /**
193 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
194 *
195 * @param message A message to log
196 */
197 public void logError(String message) {
198 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message));
199 }
200
201 /**
202 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
203 *
204 * @param message A message to log
205 * @param exception A exception to log
206 */
207 public void logError(String message, Throwable exception) {
208 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception));
209 }
210 }
This page took 0.034357 seconds and 5 git commands to generate.