tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / Activator.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.core.runtime.preferences.InstanceScope;
19 import org.eclipse.jface.preference.IPreferenceStore;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.jface.resource.ImageRegistry;
22 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
23 import org.eclipse.linuxtools.tmf.ui.TmfUiRefreshHandler;
24 import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
25 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
26 import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventAdapterFactory;
27 import org.eclipse.swt.graphics.Image;
28 import org.eclipse.ui.plugin.AbstractUIPlugin;
29 import org.eclipse.ui.preferences.ScopedPreferenceStore;
30 import org.osgi.framework.BundleContext;
31
32 /**
33 * The activator class controls the plug-in life cycle.
34 */
35 public class Activator extends AbstractUIPlugin {
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40
41 /**
42 * The plug-in ID
43 */
44 public static final String PLUGIN_ID = "org.eclipse.tracecompass.tmf.ui"; //$NON-NLS-1$
45 /**
46 * The core plug-in ID
47 */
48 public static final String PLUGIN_CORE_ID = "org.eclipse.tracecompass.tmf.core"; //$NON-NLS-1$
49
50 /**
51 * The shared instance
52 */
53 private static Activator plugin;
54
55 private TmfEventAdapterFactory fTmfEventAdapterFactory;
56 private IPreferenceStore fCorePreferenceStore;
57
58 // ------------------------------------------------------------------------
59 // Constructors
60 // ------------------------------------------------------------------------
61
62 /**
63 * Constructor
64 */
65 public Activator() {
66 }
67
68 // ------------------------------------------------------------------------
69 // Accessors
70 // ------------------------------------------------------------------------
71
72 /**
73 * Returns the TMF UI plug-in instance.
74 *
75 * @return the TMF UI plug-in instance.
76 */
77 public static Activator getDefault() {
78 return plugin;
79 }
80
81 // ------------------------------------------------------------------------
82 // AbstractUIPlugin
83 // ------------------------------------------------------------------------
84
85 @Override
86 public void start(BundleContext context) throws Exception {
87 super.start(context);
88 plugin = this;
89 TmfUiRefreshHandler.getInstance(); // to classload/initialize it
90 TmfUiTracer.init();
91 TmfTraceElement.init();
92 TmfExperimentElement.init();
93
94 fTmfEventAdapterFactory = new TmfEventAdapterFactory();
95 Platform.getAdapterManager().registerAdapters(fTmfEventAdapterFactory, ITmfEvent.class);
96 }
97
98 @Override
99 public void stop(BundleContext context) throws Exception {
100 TmfUiTracer.stop();
101 TmfUiRefreshHandler.getInstance().dispose();
102 plugin = null;
103
104 Platform.getAdapterManager().unregisterAdapters(fTmfEventAdapterFactory);
105 super.stop(context);
106 }
107
108 /**
109 * Returns a preference store for org.eclipse.linux.tmf.core preferences
110 * @return the preference store
111 */
112 public IPreferenceStore getCorePreferenceStore() {
113 if (fCorePreferenceStore == null) {
114 fCorePreferenceStore= new ScopedPreferenceStore(InstanceScope.INSTANCE, PLUGIN_CORE_ID);
115 }
116 return fCorePreferenceStore;
117 }
118
119 // ------------------------------------------------------------------------
120 // Operations
121 // ------------------------------------------------------------------------
122
123 /**
124 * Gets an image object using given path within plug-in.
125 *
126 * @param path
127 * path to image file
128 *
129 * @return image object
130 */
131 public Image getImageFromPath(String path) {
132 return getImageDescripterFromPath(path).createImage();
133 }
134
135 /**
136 * Gets an image descriptor using given path within plug-in.
137 *
138 * @param path
139 * path to image file
140 *
141 * @return image descriptor object
142 */
143 public ImageDescriptor getImageDescripterFromPath(String path) {
144 return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
145 }
146
147 /**
148 * Gets a image object from the image registry based on the given path. If
149 * the image is not in the registry it will be registered.
150 *
151 * @param path
152 * to the image file
153 * @return image object
154 */
155 public Image getImageFromImageRegistry(String path) {
156 Image icon = getImageRegistry().get(path);
157 if (icon == null) {
158 icon = getImageDescripterFromPath(path).createImage();
159 plugin.getImageRegistry().put(path, icon);
160 }
161 return icon;
162 }
163
164 @Override
165 protected void initializeImageRegistry(ImageRegistry reg) {
166 reg.put(ITmfImageConstants.IMG_UI_ZOOM, getImageFromPath(ITmfImageConstants.IMG_UI_ZOOM));
167 reg.put(ITmfImageConstants.IMG_UI_ZOOM_IN, getImageFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN));
168 reg.put(ITmfImageConstants.IMG_UI_ZOOM_OUT, getImageFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT));
169 reg.put(ITmfImageConstants.IMG_UI_SEQ_DIAGRAM_OBJ, getImageFromPath(ITmfImageConstants.IMG_UI_SEQ_DIAGRAM_OBJ));
170 reg.put(ITmfImageConstants.IMG_UI_ARROW_COLLAPSE_OBJ, getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_COLLAPSE_OBJ));
171 reg.put(ITmfImageConstants.IMG_UI_ARROW_UP_OBJ, getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_UP_OBJ));
172 reg.put(ITmfImageConstants.IMG_UI_CONFLICT, getImageFromPath(ITmfImageConstants.IMG_UI_CONFLICT));
173 }
174
175 /**
176 * Logs a message with severity INFO in the runtime log of the plug-in.
177 *
178 * @param message
179 * A message to log
180 */
181 public void logInfo(String message) {
182 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
183 }
184
185 /**
186 * Logs a message and exception with severity INFO in the runtime log of the
187 * plug-in.
188 *
189 * @param message
190 * A message to log
191 * @param exception
192 * A exception to log
193 */
194 public void logInfo(String message, Throwable exception) {
195 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception));
196 }
197
198 /**
199 * Logs a message and exception with severity WARNING in the runtime log of
200 * the plug-in.
201 *
202 * @param message
203 * A message to log
204 */
205 public void logWarning(String message) {
206 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message));
207 }
208
209 /**
210 * Logs a message and exception with severity WARNING in the runtime log of
211 * the plug-in.
212 *
213 * @param message
214 * A message to log
215 * @param exception
216 * A exception to log
217 */
218 public void logWarning(String message, Throwable exception) {
219 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception));
220 }
221
222 /**
223 * Logs a message and exception with severity ERROR in the runtime log of
224 * the plug-in.
225 *
226 * @param message
227 * A message to log
228 */
229 public void logError(String message) {
230 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message));
231 }
232
233 /**
234 * Logs a message and exception with severity ERROR in the runtime log of
235 * the plug-in.
236 *
237 * @param message
238 * A message to log
239 * @param exception
240 * A exception to log
241 */
242 public void logError(String message, Throwable exception) {
243 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception));
244 }
245 }
This page took 0.052972 seconds and 5 git commands to generate.