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