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