001: // The UMLet source code is distributed under the terms of the GPL; see license.txt
002: package com.umlet.plugin;
003:
004: import org.osgi.framework.BundleContext;
005: import org.eclipse.ui.plugin.*;
006: import org.eclipse.core.resources.*;
007:
008: import java.io.IOException;
009: import java.net.URL;
010: import java.util.*;
011: import org.eclipse.core.runtime.Platform;
012: import org.eclipse.core.runtime.Path;
013:
014: /**
015: * The main plugin class to be used in the desktop.
016: */
017: public class UmletPlugin extends AbstractUIPlugin {
018: //The shared instance.
019: private static UmletPlugin plugin;
020: //Resource bundle.
021: private ResourceBundle resourceBundle;
022:
023: /**
024: * The constructor.
025: * [UB]: Changed to default constructor
026: * for eclipse-3.0 compatibility
027: */
028: public UmletPlugin() {
029: super ();
030: plugin = this ;
031: try {
032: resourceBundle = ResourceBundle
033: .getBundle("com.umlet.plugin.UmletPluginResources");
034: } catch (MissingResourceException x) {
035: resourceBundle = null;
036: }
037: }
038:
039: /**
040: * This method is called upon plug-in activation
041: * [UB]: added this standard method
042: */
043: public void start(BundleContext context) throws Exception {
044: super .start(context);
045: }
046:
047: /**
048: * This method is called when the plug-in is stopped
049: * [UB]: added this standard method
050: */
051: public void stop(BundleContext context) throws Exception {
052: super .stop(context);
053: }
054:
055: /**
056: * Returns the shared instance.
057: */
058: public static UmletPlugin getDefault() {
059: return plugin;
060: }
061:
062: /**
063: * Returns the workspace instance.
064: */
065: public static IWorkspace getWorkspace() {
066: return ResourcesPlugin.getWorkspace();
067: }
068:
069: /**
070: * Returns the string from the plugin's resource bundle,
071: * or 'key' if not found.
072: */
073: public static String getResourceString(String key) {
074: ResourceBundle bundle = UmletPlugin.getDefault()
075: .getResourceBundle();
076: try {
077: return bundle.getString(key);
078: } catch (MissingResourceException e) {
079: return key;
080: }
081: }
082:
083: /**
084: * Returns the plugin's resource bundle,
085: */
086: public ResourceBundle getResourceBundle() {
087: return resourceBundle;
088: }
089:
090: public static String getHomePath() {
091: String thePath = null;
092: try { //LME: load palette from plugin's homedirectory
093: //System.out.println("loading palette from url...");
094: URL homeURL = Platform.find(UmletPlugin.getDefault()
095: .getBundle(), new Path("/"));
096:
097: //LME: truncate the URL string to an absolute directory path
098: thePath = Platform.asLocalURL(homeURL).toString()
099: .substring(new String("file:/").length());
100: if (System.getProperty("file.separator").equals("/")) //[UB]: if UNIX
101: thePath = "/" + thePath;
102: } catch (IOException ioe) {
103: System.err.println("Umlet->init():" + ioe);
104: }
105: return thePath;
106: }
107: }
|