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