Commit | Line | Data |
---|---|---|
b0d3496e | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2009, 2014 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; |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
24 | import org.eclipse.tracecompass.tmf.ui.TmfUiRefreshHandler; | |
25 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; | |
26 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; | |
27 | import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventAdapterFactory; | |
b0d3496e | 28 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
c1cd9635 | 29 | import org.eclipse.ui.preferences.ScopedPreferenceStore; |
b0d3496e ASL |
30 | import org.osgi.framework.BundleContext; |
31 | ||
32 | /** | |
12c155f5 | 33 | * The activator class controls the plug-in life cycle. |
b0d3496e | 34 | */ |
8fd82db5 | 35 | public class Activator extends AbstractUIPlugin { |
b0d3496e | 36 | |
12c155f5 | 37 | // ------------------------------------------------------------------------ |
b0d3496e | 38 | // Attributes |
12c155f5 | 39 | // ------------------------------------------------------------------------ |
b0d3496e | 40 | |
11252342 AM |
41 | /** |
42 | * The plug-in ID | |
43 | */ | |
c77a695a | 44 | public static final String PLUGIN_ID = "org.eclipse.tracecompass.tmf.ui"; //$NON-NLS-1$ |
c1cd9635 MAL |
45 | /** |
46 | * The core plug-in ID | |
47 | */ | |
c77a695a | 48 | public static final String PLUGIN_CORE_ID = "org.eclipse.tracecompass.tmf.core"; //$NON-NLS-1$ |
b0d3496e | 49 | |
11252342 AM |
50 | /** |
51 | * The shared instance | |
52 | */ | |
53 | private static Activator plugin; | |
9fa32496 | 54 | |
080600d9 | 55 | private TmfEventAdapterFactory fTmfEventAdapterFactory; |
c1cd9635 | 56 | private IPreferenceStore fCorePreferenceStore; |
080600d9 | 57 | |
12c155f5 | 58 | // ------------------------------------------------------------------------ |
b0d3496e | 59 | // Constructors |
12c155f5 | 60 | // ------------------------------------------------------------------------ |
b0d3496e | 61 | |
11252342 AM |
62 | /** |
63 | * Constructor | |
64 | */ | |
65 | public Activator() { | |
66 | } | |
b0d3496e | 67 | |
12c155f5 | 68 | // ------------------------------------------------------------------------ |
b0d3496e | 69 | // Accessors |
12c155f5 | 70 | // ------------------------------------------------------------------------ |
b0d3496e | 71 | |
11252342 AM |
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 | } | |
b0d3496e | 80 | |
12c155f5 FC |
81 | // ------------------------------------------------------------------------ |
82 | // AbstractUIPlugin | |
83 | // ------------------------------------------------------------------------ | |
b0d3496e | 84 | |
11252342 AM |
85 | @Override |
86 | public void start(BundleContext context) throws Exception { | |
87 | super.start(context); | |
88 | plugin = this; | |
9c91c317 | 89 | TmfUiRefreshHandler.getInstance(); // to classload/initialize it |
11252342 AM |
90 | TmfUiTracer.init(); |
91 | TmfTraceElement.init(); | |
8f5221c2 | 92 | TmfExperimentElement.init(); |
080600d9 MAL |
93 | |
94 | fTmfEventAdapterFactory = new TmfEventAdapterFactory(); | |
95 | Platform.getAdapterManager().registerAdapters(fTmfEventAdapterFactory, ITmfEvent.class); | |
11252342 AM |
96 | } |
97 | ||
98 | @Override | |
99 | public void stop(BundleContext context) throws Exception { | |
100 | TmfUiTracer.stop(); | |
9c91c317 | 101 | TmfUiRefreshHandler.getInstance().dispose(); |
11252342 | 102 | plugin = null; |
080600d9 MAL |
103 | |
104 | Platform.getAdapterManager().unregisterAdapters(fTmfEventAdapterFactory); | |
11252342 AM |
105 | super.stop(context); |
106 | } | |
b0d3496e | 107 | |
c1cd9635 MAL |
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 | ||
12c155f5 FC |
119 | // ------------------------------------------------------------------------ |
120 | // Operations | |
121 | // ------------------------------------------------------------------------ | |
122 | ||
11252342 AM |
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) { | |
73005152 BH |
132 | return getImageDescripterFromPath(path).createImage(); |
133 | } | |
f8177ba2 | 134 | |
9fa32496 BH |
135 | /** |
136 | * Gets an image descriptor using given path within plug-in. | |
f8177ba2 | 137 | * |
11252342 AM |
138 | * @param path |
139 | * path to image file | |
f8177ba2 | 140 | * |
9fa32496 BH |
141 | * @return image descriptor object |
142 | */ | |
11252342 | 143 | public ImageDescriptor getImageDescripterFromPath(String path) { |
73005152 BH |
144 | return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); |
145 | } | |
f8177ba2 | 146 | |
9fa32496 | 147 | /** |
11252342 AM |
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. | |
f8177ba2 | 150 | * |
11252342 AM |
151 | * @param path |
152 | * to the image file | |
9fa32496 BH |
153 | * @return image object |
154 | */ | |
73005152 BH |
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; | |
abfad0aa FC |
162 | } |
163 | ||
73005152 BH |
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)); | |
d04ec5a7 | 172 | reg.put(ITmfImageConstants.IMG_UI_CONFLICT, getImageFromPath(ITmfImageConstants.IMG_UI_CONFLICT)); |
73005152 | 173 | } |
9fa32496 BH |
174 | |
175 | /** | |
176 | * Logs a message with severity INFO in the runtime log of the plug-in. | |
f8177ba2 | 177 | * |
11252342 AM |
178 | * @param message |
179 | * A message to log | |
9fa32496 BH |
180 | */ |
181 | public void logInfo(String message) { | |
182 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); | |
183 | } | |
f8177ba2 | 184 | |
9fa32496 | 185 | /** |
11252342 AM |
186 | * Logs a message and exception with severity INFO in the runtime log of the |
187 | * plug-in. | |
f8177ba2 | 188 | * |
11252342 AM |
189 | * @param message |
190 | * A message to log | |
191 | * @param exception | |
192 | * A exception to log | |
9fa32496 BH |
193 | */ |
194 | public void logInfo(String message, Throwable exception) { | |
195 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception)); | |
196 | } | |
197 | ||
198 | /** | |
11252342 AM |
199 | * Logs a message and exception with severity WARNING in the runtime log of |
200 | * the plug-in. | |
f8177ba2 | 201 | * |
11252342 AM |
202 | * @param message |
203 | * A message to log | |
9fa32496 BH |
204 | */ |
205 | public void logWarning(String message) { | |
206 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
207 | } | |
f8177ba2 | 208 | |
9fa32496 | 209 | /** |
11252342 AM |
210 | * Logs a message and exception with severity WARNING in the runtime log of |
211 | * the plug-in. | |
f8177ba2 | 212 | * |
11252342 AM |
213 | * @param message |
214 | * A message to log | |
215 | * @param exception | |
216 | * A exception to log | |
9fa32496 BH |
217 | */ |
218 | public void logWarning(String message, Throwable exception) { | |
219 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception)); | |
220 | } | |
221 | ||
222 | /** | |
11252342 AM |
223 | * Logs a message and exception with severity ERROR in the runtime log of |
224 | * the plug-in. | |
f8177ba2 | 225 | * |
11252342 AM |
226 | * @param message |
227 | * A message to log | |
9fa32496 BH |
228 | */ |
229 | public void logError(String message) { | |
230 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
231 | } | |
f8177ba2 | 232 | |
9fa32496 | 233 | /** |
11252342 AM |
234 | * Logs a message and exception with severity ERROR in the runtime log of |
235 | * the plug-in. | |
f8177ba2 | 236 | * |
11252342 AM |
237 | * @param message |
238 | * A message to log | |
239 | * @param exception | |
240 | * A exception to log | |
9fa32496 BH |
241 | */ |
242 | public void logError(String message, Throwable exception) { | |
243 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); | |
244 | } | |
b0d3496e | 245 | } |