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