Commit | Line | Data |
---|---|---|
b0d3496e | 1 | /******************************************************************************* |
9fa32496 | 2 | * Copyright (c) 2009, 2012 Ericsson |
b0d3496e ASL |
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 | ||
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui; |
b0d3496e | 14 | |
9fa32496 BH |
15 | import org.eclipse.core.runtime.IStatus; |
16 | import org.eclipse.core.runtime.Status; | |
73005152 BH |
17 | import org.eclipse.jface.resource.ImageDescriptor; |
18 | import org.eclipse.jface.resource.ImageRegistry; | |
12c155f5 | 19 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; |
abfad0aa | 20 | import org.eclipse.swt.graphics.Image; |
b0d3496e ASL |
21 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
22 | import org.osgi.framework.BundleContext; | |
23 | ||
24 | /** | |
12c155f5 | 25 | * The activator class controls the plug-in life cycle. |
b0d3496e | 26 | */ |
8fd82db5 | 27 | public class Activator extends AbstractUIPlugin { |
b0d3496e | 28 | |
12c155f5 | 29 | // ------------------------------------------------------------------------ |
b0d3496e | 30 | // Attributes |
12c155f5 | 31 | // ------------------------------------------------------------------------ |
b0d3496e | 32 | |
9fa32496 BH |
33 | /** |
34 | * The plug-in ID | |
35 | */ | |
3b38ea61 | 36 | public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.ui"; //$NON-NLS-1$ |
b0d3496e | 37 | |
9fa32496 BH |
38 | /** |
39 | * The shared instance | |
40 | */ | |
8fd82db5 | 41 | private static Activator plugin; |
9fa32496 | 42 | |
12c155f5 | 43 | // ------------------------------------------------------------------------ |
b0d3496e | 44 | // Constructors |
12c155f5 | 45 | // ------------------------------------------------------------------------ |
b0d3496e | 46 | |
9fa32496 BH |
47 | /** |
48 | * Constructor | |
49 | */ | |
8fd82db5 | 50 | public Activator() { |
b0d3496e ASL |
51 | } |
52 | ||
12c155f5 | 53 | // ------------------------------------------------------------------------ |
b0d3496e | 54 | // Accessors |
12c155f5 | 55 | // ------------------------------------------------------------------------ |
b0d3496e | 56 | |
9fa32496 BH |
57 | /** |
58 | * Returns the TMF UI plug-in instance. | |
59 | * | |
60 | * @return the TMF UI plug-in instance. | |
61 | */ | |
8fd82db5 | 62 | public static Activator getDefault() { |
b0d3496e ASL |
63 | return plugin; |
64 | } | |
65 | ||
12c155f5 FC |
66 | // ------------------------------------------------------------------------ |
67 | // AbstractUIPlugin | |
68 | // ------------------------------------------------------------------------ | |
b0d3496e | 69 | |
9fa32496 BH |
70 | /* |
71 | * (non-Javadoc) | |
72 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) | |
73 | */ | |
62d1696a | 74 | @Override |
b0d3496e ASL |
75 | public void start(BundleContext context) throws Exception { |
76 | super.start(context); | |
77 | plugin = this; | |
73005152 | 78 | TmfUiTracer.init(); |
12c155f5 | 79 | TmfTraceElement.init(); |
b0d3496e ASL |
80 | } |
81 | ||
9fa32496 BH |
82 | /* |
83 | * (non-Javadoc) | |
84 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) | |
85 | */ | |
62d1696a | 86 | @Override |
b0d3496e | 87 | public void stop(BundleContext context) throws Exception { |
73005152 | 88 | TmfUiTracer.stop(); |
b0d3496e ASL |
89 | plugin = null; |
90 | super.stop(context); | |
91 | } | |
92 | ||
12c155f5 FC |
93 | // ------------------------------------------------------------------------ |
94 | // Operations | |
95 | // ------------------------------------------------------------------------ | |
96 | ||
9fa32496 BH |
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 | */ | |
73005152 BH |
104 | public Image getImageFromPath(String path){ |
105 | return getImageDescripterFromPath(path).createImage(); | |
106 | } | |
107 | ||
9fa32496 BH |
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 | */ | |
73005152 BH |
115 | public ImageDescriptor getImageDescripterFromPath(String path){ |
116 | return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); | |
117 | } | |
118 | ||
9fa32496 BH |
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 | */ | |
73005152 BH |
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; | |
abfad0aa FC |
133 | } |
134 | ||
73005152 BH |
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 | } | |
9fa32496 BH |
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 | } | |
73005152 | 157 | |
9fa32496 BH |
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 | } | |
73005152 | 176 | |
9fa32496 BH |
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 | } | |
b0d3496e | 205 | } |