001: package net.refractions.udig.location;
002:
003: import java.net.URL;
004:
005: import net.refractions.udig.location.internal.Images;
006:
007: import org.eclipse.core.runtime.IStatus;
008: import org.eclipse.core.runtime.Platform;
009: import org.eclipse.core.runtime.Status;
010: import org.eclipse.ui.plugin.AbstractUIPlugin;
011: import org.osgi.framework.BundleContext;
012:
013: /**
014: * The main plugin class to be used in the desktop.
015: */
016: public class LocationUIPlugin extends AbstractUIPlugin {
017:
018: public static String ID = "net.refractions.udig.location"; //$NON-NLS-1$
019: /** Icons path (value "icons/") */
020: public final static String ICONS_PATH = "icons/";//$NON-NLS-1$
021:
022: //The shared instance.
023: private static LocationUIPlugin plugin;
024: private Images images = new Images();
025:
026: /**
027: * The constructor.
028: */
029: public LocationUIPlugin() {
030: plugin = this ;
031: }
032:
033: /**
034: * Set up shared images.
035: *
036: * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
037: * @param context
038: * @throws Exception
039: */
040: public void start(BundleContext context) throws Exception {
041: super .start(context);
042: final URL iconsUrl = context.getBundle().getEntry(ICONS_PATH);
043:
044: images.initializeImages(iconsUrl, getImageRegistry());
045: }
046:
047: /**
048: * Cleanup after shared images.
049: *
050: * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
051: * @param context
052: * @throws Exception
053: */
054: public void stop(BundleContext context) throws Exception {
055: images.cleanUp();
056: super .stop(context);
057: }
058:
059: /**
060: * Returns the shared instance.
061: */
062: public static LocationUIPlugin getDefault() {
063: return plugin;
064: }
065:
066: public Images getImages() {
067: return images;
068: }
069:
070: /**
071: * Logs the Throwable in the plugin's log.
072: * <p>
073: * This will be a user visable ERROR iff:
074: * <ul>
075: * <li>t is an Exception we are assuming it is human readable or if a message is provided
076: * </ul>
077: * </p>
078: *
079: * @param message
080: * @param t
081: */
082: public static void log(String message, Throwable t) {
083: if (message == null)
084: message = ""; //$NON-NLS-1$
085: int status = t instanceof Exception || message != null ? IStatus.ERROR
086: : IStatus.WARNING;
087: getDefault().getLog().log(
088: new Status(status, ID, IStatus.OK, message, t));
089: }
090:
091: /**
092: * Messages that only engage if getDefault().isDebugging()
093: * <p>
094: * It is much prefered to do this:
095: *
096: * <pre><code>
097: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
098: * if (ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase(RENDERING)) {
099: * System.out.println("your message here");
100: * }
101: * </code></pre>
102: *
103: * </p>
104: *
105: * @param message
106: * @param e
107: */
108: public static void trace(String message, Throwable e) {
109: if (getDefault().isDebugging()) {
110: if (message != null)
111: System.out.println(message);
112: if (e != null)
113: e.printStackTrace();
114: }
115: }
116:
117: public static void trace(String message) {
118: if (getDefault().isDebugging()) {
119: if (message != null)
120: System.out.println(message);
121: }
122: }
123:
124: /**
125: * Performs the Platform.getDebugOption true check on the provided trace
126: * <p>
127: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
128: * <ul>
129: * <li>Trace.RENDER - trace rendering progress
130: * </ul>
131: * </p>
132: *
133: * @param trace currently only RENDER is defined
134: * @return true if -debug is on for this plugin
135: */
136: public static boolean isDebugging(final String trace) {
137: return getDefault().isDebugging()
138: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
139: }
140: }
|