01: package net.refractions.udig.legend;
02:
03: import org.eclipse.ui.plugin.*;
04: import org.eclipse.core.runtime.IStatus;
05: import org.eclipse.core.runtime.Status;
06: import org.eclipse.jface.resource.ImageDescriptor;
07: import org.osgi.framework.BundleContext;
08:
09: /**
10: * The main plugin class to be used in the desktop.
11: */
12: public class LegendPlugin extends AbstractUIPlugin {
13:
14: //The shared instance.
15: private static LegendPlugin plugin;
16: public static final String ID = "net.refractions.udig.legend"; //$NON-NLS-1$
17:
18: /**
19: * The constructor.
20: */
21: public LegendPlugin() {
22: plugin = this ;
23: }
24:
25: /**
26: * This method is called upon plug-in activation
27: */
28: public void start(BundleContext context) throws Exception {
29: super .start(context);
30: }
31:
32: /**
33: * This method is called when the plug-in is stopped
34: */
35: public void stop(BundleContext context) throws Exception {
36: super .stop(context);
37: plugin = null;
38: }
39:
40: /**
41: * Returns the shared instance.
42: */
43: public static LegendPlugin getDefault() {
44: return plugin;
45: }
46:
47: /**
48: * Returns an image descriptor for the image file at the given
49: * plug-in relative path.
50: *
51: * @param path the path
52: * @return the image descriptor
53: */
54: public static ImageDescriptor getImageDescriptor(String path) {
55: return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path);
56: }
57:
58: /**
59: * Logs the Throwable in the plugin's log.
60: * <p>
61: * This will be a user visable ERROR iff:
62: * <ul>
63: * <li>t is an Exception we are assuming it is human readable or if a message is provided
64: * </ul>
65: * </p>
66: * @param message
67: * @param t
68: */
69: public static void log(String message, Throwable t) {
70: int status = t instanceof Exception || message != null ? IStatus.ERROR
71: : IStatus.WARNING;
72: getDefault().getLog().log(
73: new Status(status, ID, IStatus.OK, message, t));
74: }
75: }
|