001: package net.refractions.udig.catalog.hsql.internal;
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.Status;
008: import org.eclipse.jface.resource.ImageDescriptor;
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 HsqlPlugin extends AbstractUIPlugin {
016:
017: //The shared instance.
018: private static HsqlPlugin plugin;
019: //Resource bundle.
020: private ResourceBundle resourceBundle;
021:
022: public static final String ID = "net.refractions.udig.catalog.hsql.internal"; //$NON-NLS-1$
023:
024: /**
025: * The constructor.
026: */
027: public HsqlPlugin() {
028: super ();
029: plugin = this ;
030: }
031:
032: /**
033: * This method is called upon plug-in activation
034: */
035: public void start(BundleContext context) throws Exception {
036: super .start(context);
037: }
038:
039: /**
040: * This method is called when the plug-in is stopped
041: */
042: public void stop(BundleContext context) throws Exception {
043: plugin = null;
044: resourceBundle = null;
045: super .stop(context);
046: }
047:
048: /**
049: * Returns the shared instance.
050: */
051: public static HsqlPlugin getDefault() {
052: return plugin;
053: }
054:
055: /**
056: * Returns the string from the plugin's resource bundle,
057: * or 'key' if not found.
058: * @param key
059: * @return x
060: */
061: public static String getResourceString(String key) {
062: ResourceBundle bundle = HsqlPlugin.getDefault()
063: .getResourceBundle();
064: try {
065: return (bundle != null) ? bundle.getString(key) : key;
066: } catch (MissingResourceException e) {
067: return key;
068: }
069: }
070:
071: /**
072: * Returns the plugin's resource bundle,
073: * @return x
074: */
075: public ResourceBundle getResourceBundle() {
076: try {
077: if (resourceBundle == null)
078: resourceBundle = ResourceBundle
079: .getBundle("net.refractions.udig.catalog.internal.hsql.HsqlPluginResources"); //$NON-NLS-1$
080: } catch (MissingResourceException x) {
081: resourceBundle = null;
082: }
083: return resourceBundle;
084: }
085:
086: /**
087: * Logs the Throwable in the plugin's log.
088: * <p>
089: * This will be a user visable ERROR iff:
090: * <ul>
091: * <li>t is an Exception we are assuming it is human readable or if a message is provided
092: * </ul>
093: * </p>
094: * @param message
095: * @param t
096: */
097: public static void log(String message, Throwable t) {
098: int status = t instanceof Exception || message != null ? IStatus.ERROR
099: : IStatus.WARNING;
100: getDefault().getLog().log(
101: new Status(status, ID, IStatus.OK, message, t));
102: }
103:
104: /**
105: * Returns an image descriptor for the image file at the given
106: * plug-in relative path.
107: *
108: * @param path the path
109: * @return the image descriptor
110: */
111: public static ImageDescriptor getImageDescriptor(String path) {
112: return AbstractUIPlugin.imageDescriptorFromPlugin(
113: "net.refractions.udig.catalog.hsql", path); //$NON-NLS-1$
114: }
115: }
|