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