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