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