Commit | Line | Data |
---|---|---|
a7780cc8 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
27f3a03d | 3 | * |
a7780cc8 FC |
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 | |
27f3a03d | 8 | * |
a7780cc8 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
1ee4d327 | 13 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui; |
a7780cc8 | 14 | |
9fa32496 BH |
15 | import org.eclipse.core.runtime.IStatus; |
16 | import org.eclipse.core.runtime.Status; | |
a7780cc8 FC |
17 | import org.eclipse.jface.resource.ImageDescriptor; |
18 | import org.eclipse.jface.resource.ImageRegistry; | |
19 | import org.eclipse.swt.graphics.Image; | |
20 | import org.eclipse.ui.plugin.AbstractUIPlugin; | |
21 | import org.osgi.framework.BundleContext; | |
22 | ||
23 | /** | |
24 | * The activator class controls the plug-in life cycle | |
25 | */ | |
26 | public class Activator extends AbstractUIPlugin { | |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Attributes | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
32 | /** | |
33 | * The plug-in ID | |
34 | */ | |
04835162 | 35 | public static final String PLUGIN_ID = "org.eclipse.linuxtools.lttng2.kernel.ui"; //$NON-NLS-1$ |
a7780cc8 FC |
36 | |
37 | /** | |
38 | * The shared instance | |
39 | */ | |
40 | private static Activator plugin; | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Constructors | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
46 | /** | |
47 | * The constructor | |
48 | */ | |
49 | public Activator() { | |
50 | } | |
51 | ||
52 | // ------------------------------------------------------------------------ | |
53 | // Accessors | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
56 | /** | |
57 | * Returns the shared instance | |
58 | * | |
59 | * @return the shared instance | |
60 | */ | |
61 | public static Activator getDefault() { | |
62 | return plugin; | |
63 | } | |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // AbstractUIPlugin | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | /* (non-Javadoc) | |
70 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) | |
71 | */ | |
72 | @Override | |
73 | public void start(BundleContext context) throws Exception { | |
74 | super.start(context); | |
75 | plugin = this; | |
76 | } | |
77 | ||
78 | /* (non-Javadoc) | |
79 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) | |
80 | */ | |
81 | @Override | |
82 | public void stop(BundleContext context) throws Exception { | |
83 | plugin = null; | |
84 | super.stop(context); | |
85 | } | |
86 | ||
87 | /* (non-Javadoc) | |
88 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry) | |
89 | */ | |
90 | @Override | |
91 | protected void initializeImageRegistry(ImageRegistry reg) { | |
92 | } | |
93 | ||
94 | // ------------------------------------------------------------------------ | |
95 | // Operations | |
96 | // ------------------------------------------------------------------------ | |
97 | ||
27f3a03d AM |
98 | /** |
99 | * Get the image object from a given path | |
100 | * | |
101 | * @param path | |
102 | * The path to the image file | |
103 | * @return The Image object | |
104 | */ | |
a7780cc8 FC |
105 | public Image getImageFromPath(String path) { |
106 | return getImageDescripterFromPath(path).createImage(); | |
107 | } | |
108 | ||
27f3a03d AM |
109 | /** |
110 | * Get the ImageDescriptor from a given path | |
111 | * | |
112 | * @param path | |
113 | * The path to the image file | |
114 | * @return The ImageDescriptor object | |
115 | */ | |
a7780cc8 FC |
116 | public ImageDescriptor getImageDescripterFromPath(String path) { |
117 | return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); | |
118 | } | |
119 | ||
27f3a03d AM |
120 | /** |
121 | * Get the Image from a registry | |
122 | * | |
123 | * @param path | |
124 | * The path to the image registry | |
125 | * @return The Image object | |
126 | */ | |
a7780cc8 FC |
127 | public Image getImageFromImageRegistry(String path) { |
128 | Image icon = getImageRegistry().get(path); | |
129 | if (icon == null) { | |
130 | icon = getImageDescripterFromPath(path).createImage(); | |
131 | plugin.getImageRegistry().put(path, icon); | |
132 | } | |
133 | return icon; | |
134 | } | |
27f3a03d | 135 | |
9fa32496 BH |
136 | /** |
137 | * Logs a message with severity INFO in the runtime log of the plug-in. | |
27f3a03d | 138 | * |
9fa32496 BH |
139 | * @param message A message to log |
140 | */ | |
141 | public void logInfo(String message) { | |
142 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); | |
143 | } | |
27f3a03d | 144 | |
9fa32496 BH |
145 | /** |
146 | * Logs a message and exception with severity INFO in the runtime log of the plug-in. | |
27f3a03d | 147 | * |
9fa32496 BH |
148 | * @param message A message to log |
149 | * @param exception A exception to log | |
150 | */ | |
151 | public void logInfo(String message, Throwable exception) { | |
152 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception)); | |
153 | } | |
154 | ||
155 | /** | |
156 | * Logs a message and exception with severity WARNING in the runtime log of the plug-in. | |
27f3a03d | 157 | * |
9fa32496 BH |
158 | * @param message A message to log |
159 | */ | |
160 | public void logWarning(String message) { | |
161 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
162 | } | |
27f3a03d | 163 | |
9fa32496 BH |
164 | /** |
165 | * Logs a message and exception with severity WARNING in the runtime log of the plug-in. | |
27f3a03d | 166 | * |
9fa32496 BH |
167 | * @param message A message to log |
168 | * @param exception A exception to log | |
169 | */ | |
170 | public void logWarning(String message, Throwable exception) { | |
171 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception)); | |
172 | } | |
173 | ||
174 | /** | |
175 | * Logs a message and exception with severity ERROR in the runtime log of the plug-in. | |
27f3a03d | 176 | * |
9fa32496 BH |
177 | * @param message A message to log |
178 | */ | |
179 | public void logError(String message) { | |
180 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
181 | } | |
27f3a03d | 182 | |
9fa32496 BH |
183 | /** |
184 | * Logs a message and exception with severity ERROR in the runtime log of the plug-in. | |
27f3a03d | 185 | * |
9fa32496 BH |
186 | * @param message A message to log |
187 | * @param exception A exception to log | |
188 | */ | |
189 | public void logError(String message, Throwable exception) { | |
190 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); | |
191 | } | |
a7780cc8 FC |
192 | |
193 | } |