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