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