001: package net.refractions.udig.tool.select;
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.ui.plugin.AbstractUIPlugin;
009: import org.osgi.framework.BundleContext;
010:
011: /**
012: * The main plugin class to be used in the desktop.
013: */
014: public class SelectPlugin extends AbstractUIPlugin {
015: //The shared instance.
016: private static SelectPlugin plugin;
017: //Resource bundle.
018: private ResourceBundle resourceBundle;
019: /**
020: * Comment for <code>ID</code>
021: */
022: public static final String ID = "net.refractions.udig.tool.select"; //$NON-NLS-1$
023:
024: /**
025: * The constructor.
026: */
027: public SelectPlugin() {
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: super .stop(context);
044: plugin = null;
045: resourceBundle = null;
046: }
047:
048: /**
049: * Returns the shared instance.
050: * @return x
051: */
052: public static SelectPlugin getDefault() {
053: return plugin;
054: }
055:
056: /**
057: * Returns the string from the plugin's resource bundle,
058: * or 'key' if not found.
059: * @param key
060: * @return x
061: */
062: public static String getResourceString(String key) {
063: ResourceBundle bundle = SelectPlugin.getDefault()
064: .getResourceBundle();
065: try {
066: return (bundle != null) ? bundle.getString(key) : key;
067: } catch (MissingResourceException e) {
068: return key;
069: }
070: }
071:
072: /**
073: * Returns the plugin's resource bundle,
074: * @return x
075: */
076: public ResourceBundle getResourceBundle() {
077: try {
078: if (resourceBundle == null)
079: resourceBundle = ResourceBundle
080: .getBundle("net.refractions.udig.tool.select.SelectPluginResources"); //$NON-NLS-1$
081: } catch (MissingResourceException x) {
082: resourceBundle = null;
083: }
084: return resourceBundle;
085: }
086:
087: /**
088: * Writes an info log in the plugin's log.
089: * <p>
090: * This should be used for user level messages.
091: * </p>
092: */
093: public static void log(String message2, Throwable e) {
094: String message = message2;
095: if (message == null)
096: message = "Error in Table View plugin" + e.getLocalizedMessage(); //$NON-NLS-1$
097: getDefault().getLog().log(
098: new Status(IStatus.INFO, ID, IStatus.OK, message, e));
099: }
100: }
|