Commit | Line | Data |
---|---|---|
a7780cc8 | 1 | /******************************************************************************* |
11252342 | 2 | * Copyright (c) 2012, 2013 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 | ||
a7780cc8 FC |
69 | @Override |
70 | public void start(BundleContext context) throws Exception { | |
71 | super.start(context); | |
72 | plugin = this; | |
73 | } | |
74 | ||
a7780cc8 FC |
75 | @Override |
76 | public void stop(BundleContext context) throws Exception { | |
77 | plugin = null; | |
78 | super.stop(context); | |
79 | } | |
80 | ||
a7780cc8 FC |
81 | @Override |
82 | protected void initializeImageRegistry(ImageRegistry reg) { | |
83 | } | |
84 | ||
85 | // ------------------------------------------------------------------------ | |
86 | // Operations | |
87 | // ------------------------------------------------------------------------ | |
88 | ||
27f3a03d AM |
89 | /** |
90 | * Get the image object from a given path | |
91 | * | |
92 | * @param path | |
93 | * The path to the image file | |
94 | * @return The Image object | |
95 | */ | |
a7780cc8 FC |
96 | public Image getImageFromPath(String path) { |
97 | return getImageDescripterFromPath(path).createImage(); | |
98 | } | |
99 | ||
27f3a03d AM |
100 | /** |
101 | * Get the ImageDescriptor from a given path | |
102 | * | |
103 | * @param path | |
104 | * The path to the image file | |
105 | * @return The ImageDescriptor object | |
106 | */ | |
a7780cc8 FC |
107 | public ImageDescriptor getImageDescripterFromPath(String path) { |
108 | return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); | |
109 | } | |
110 | ||
27f3a03d AM |
111 | /** |
112 | * Get the Image from a registry | |
113 | * | |
114 | * @param path | |
115 | * The path to the image registry | |
116 | * @return The Image object | |
117 | */ | |
a7780cc8 FC |
118 | public Image getImageFromImageRegistry(String path) { |
119 | Image icon = getImageRegistry().get(path); | |
120 | if (icon == null) { | |
121 | icon = getImageDescripterFromPath(path).createImage(); | |
122 | plugin.getImageRegistry().put(path, icon); | |
123 | } | |
124 | return icon; | |
125 | } | |
27f3a03d | 126 | |
9fa32496 BH |
127 | /** |
128 | * Logs a message with severity INFO in the runtime log of the plug-in. | |
27f3a03d | 129 | * |
9fa32496 BH |
130 | * @param message A message to log |
131 | */ | |
132 | public void logInfo(String message) { | |
133 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); | |
134 | } | |
27f3a03d | 135 | |
9fa32496 BH |
136 | /** |
137 | * Logs a message and exception with severity INFO in the runtime log of the plug-in. | |
27f3a03d | 138 | * |
9fa32496 BH |
139 | * @param message A message to log |
140 | * @param exception A exception to log | |
141 | */ | |
142 | public void logInfo(String message, Throwable exception) { | |
143 | getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception)); | |
144 | } | |
145 | ||
146 | /** | |
147 | * Logs a message and exception with severity WARNING in the runtime log of the plug-in. | |
27f3a03d | 148 | * |
9fa32496 BH |
149 | * @param message A message to log |
150 | */ | |
151 | public void logWarning(String message) { | |
152 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
153 | } | |
27f3a03d | 154 | |
9fa32496 BH |
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 | * @param exception A exception to log | |
160 | */ | |
161 | public void logWarning(String message, Throwable exception) { | |
162 | getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception)); | |
163 | } | |
164 | ||
165 | /** | |
166 | * Logs a message and exception with severity ERROR in the runtime log of the plug-in. | |
27f3a03d | 167 | * |
9fa32496 BH |
168 | * @param message A message to log |
169 | */ | |
170 | public void logError(String message) { | |
171 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
172 | } | |
27f3a03d | 173 | |
9fa32496 BH |
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 | * @param exception A exception to log | |
179 | */ | |
180 | public void logError(String message, Throwable exception) { | |
181 | getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); | |
182 | } | |
a7780cc8 FC |
183 | |
184 | } |