btf: Initial Best Trace Format commit
[deliverable/tracecompass.git] / org.eclipse.linuxtools.btf.ui / src / org / eclipse / linuxtools / btf / ui / Activator.java
1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Matthew Khouzam - Initial implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.btf.ui;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.core.runtime.Plugin;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.linuxtools.btf.core.event.BtfEvent;
20 import org.osgi.framework.BundleContext;
21
22 /**
23 * The activator class controls the plug-in life cycle. No more than one such
24 * plug-in can exist at any time.
25 * <p>
26 * It also provides the plug-in's general logging facility and manages the
27 * internal tracer.
28 */
29 public class Activator extends Plugin {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 /**
36 * The plug-in ID
37 */
38 public static final String PLUGIN_ID = "org.eclipse.linuxtools.btf.ui"; //$NON-NLS-1$
39
40 /**
41 * The shared instance
42 */
43 private static Activator fPlugin;
44
45 private BtfEventAdapterFactory fBtfEventAdapterFactory;
46
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51
52 /**
53 * Constructor
54 */
55 public Activator() {
56 setDefault(this);
57 }
58
59 // ------------------------------------------------------------------------
60 // Accessors
61 // ------------------------------------------------------------------------
62
63 /**
64 * Returns the BTF plug-in instance.
65 *
66 * @return the BTF plug-in instance.
67 */
68 public static Activator getDefault() {
69 return fPlugin;
70 }
71
72 // Sets plug-in instance
73 private static void setDefault(Activator plugin) {
74 fPlugin = plugin;
75 }
76
77 // ------------------------------------------------------------------------
78 // Plugin
79 // ------------------------------------------------------------------------
80
81 @Override
82 public void start(BundleContext context) throws Exception {
83 super.start(context);
84 setDefault(this);
85 fBtfEventAdapterFactory = new BtfEventAdapterFactory();
86 Platform.getAdapterManager().registerAdapters(fBtfEventAdapterFactory, BtfEvent.class);
87 }
88
89 @Override
90 public void stop(BundleContext context) throws Exception {
91 setDefault(null);
92 super.stop(context);
93 }
94
95
96 // ------------------------------------------------------------------------
97 // Log an IStatus
98 // ------------------------------------------------------------------------
99
100 /**
101 * Log an IStatus object directly
102 *
103 * @param status
104 * The status to log
105 */
106 public static void log(IStatus status) {
107 fPlugin.getLog().log(status);
108 }
109
110 // ------------------------------------------------------------------------
111 // Log INFO
112 // ------------------------------------------------------------------------
113
114 /**
115 * Logs a message with severity INFO in the runtime log of the plug-in.
116 *
117 * @param message
118 * A message to log
119 */
120 public static void logInfo(String message) {
121 fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
122 }
123
124 /**
125 * Logs a message and exception with severity INFO in the runtime log of the
126 * plug-in.
127 *
128 * @param message
129 * A message to log
130 * @param exception
131 * The corresponding exception
132 */
133 public static void logInfo(String message, Throwable exception) {
134 fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception));
135 }
136
137 // ------------------------------------------------------------------------
138 // Log WARNING
139 // ------------------------------------------------------------------------
140
141 /**
142 * Logs a message and exception with severity WARNING in the runtime log of
143 * the plug-in.
144 *
145 * @param message
146 * A message to log
147 */
148 public static void logWarning(String message) {
149 fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message));
150 }
151
152 /**
153 * Logs a message and exception with severity WARNING in the runtime log of
154 * the plug-in.
155 *
156 * @param message
157 * A message to log
158 * @param exception
159 * The corresponding exception
160 */
161 public static void logWarning(String message, Throwable exception) {
162 fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception));
163 }
164
165 // ------------------------------------------------------------------------
166 // Log ERROR
167 // ------------------------------------------------------------------------
168
169 /**
170 * Logs a message and exception with severity ERROR in the runtime log of
171 * the plug-in.
172 *
173 * @param message
174 * A message to log
175 */
176 public static void logError(String message) {
177 fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message));
178 }
179
180 /**
181 * Logs a message and exception with severity ERROR in the runtime log of
182 * the plug-in.
183 *
184 * @param message
185 * A message to log
186 * @param exception
187 * The corresponding exception
188 */
189 public static void logError(String message, Throwable exception) {
190 fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception));
191 }
192 }
This page took 0.03527 seconds and 5 git commands to generate.