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