1) Although dbg will be dropped from being supported or bundled with PHPeclipse,...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDebugCorePlugin.java
index 0e6f79f..e6dcd86 100644 (file)
@@ -1,29 +1,39 @@
 package net.sourceforge.phpdt.internal.debug.core;
 
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
 import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.runtime.IPluginDescriptor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Plugin;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.*;
+//import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
 /**
  * The main plugin class to be used in the desktop.
  */
-public class PHPDebugCorePlugin extends Plugin {
-       public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.debug.core"; //$NON-NLS-1$
-       //      The shared instance.
+public class PHPDebugCorePlugin extends AbstractUIPlugin {
+       // The shared instance.
        protected static PHPDebugCorePlugin plugin;
 
-       /**
-        * The constructor.
-        */
-       public PHPDebugCorePlugin(IPluginDescriptor descriptor) {
-               super(descriptor);
-               plugin = this;
-       } 
+       public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.debug.core"; //$NON-NLS-1$
+
+       public static IWorkbenchPage getActivePage() {
+               return getDefault().internalGetActivePage();
+       }
+
+//     public static Shell getActiveWorkbenchShell() {
+//             return getActiveWorkbenchWindow().getShell();
+//     }
+
+       public static IWorkbenchWindow getActiveWorkbenchWindow() {
+               return getDefault().getWorkbench().getActiveWorkbenchWindow();
+       }
 
        /**
         * Returns the shared instance.
@@ -32,16 +42,43 @@ public class PHPDebugCorePlugin extends Plugin {
                return plugin;
        }
 
+//     public static String getFormattedMessage(String key, String arg) {
+//             String text = getResourceString(key);
+//             return java.text.MessageFormat.format(text, new Object[] { arg });
+//     }
+
+       public static String getResourceString(String key) {
+               ResourceBundle bundle = plugin.getResourceBundle();
+               if (bundle != null) {
+                       try {
+                               String bundleString = bundle.getString(key);
+                               // return "$"+bundleString;
+                               return bundleString;
+                       } catch (MissingResourceException e) {
+                               // default actions is to return key, which is OK
+                       }
+               }
+               return key;
+       }
+
+       /**
+        * Convenience method which returns the unique identifier of this plugin.
+        */
+       public static String getUniqueIdentifier() {
+               return PLUGIN_ID;
+       }
+
        /**
         * Returns the workspace instance.
         */
        public static IWorkspace getWorkspace() {
                return PHPeclipsePlugin.getWorkspace();
        }
-       
+
        public static void log(int severity, String message) {
-               Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null) ;
-               PHPDebugCorePlugin.log(status) ;
+               Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
+                               null);
+               PHPDebugCorePlugin.log(status);
        }
 
        public static void log(IStatus status) {
@@ -49,29 +86,41 @@ public class PHPDebugCorePlugin extends Plugin {
        }
 
        public static void log(Throwable e) {
-               log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPLaunchingPlugin.internalErrorOccurred", e)); //$NON-NLS-1$
+               log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
+                               "PHPLaunchingPlugin.internalErrorOccurred", e)); //$NON-NLS-1$
        }
 
+       private ResourceBundle resourceBundle;
+
        /**
-        * Convenience method which returns the unique identifier of this plugin.
+        * The constructor.
         */
-//     public static String getUniqueIdentifier() {
-//             if (getDefault() == null) {
-//                     // If the default instance is not yet initialized,
-//                     // return a static identifier. This identifier must
-//                     // match the plugin id defined in plugin.xml
-//                     return PLUGIN_ID;
-//             }
-//             return getDefault().getDescriptor().getUniqueIdentifier();
-//     }
-       
+       public PHPDebugCorePlugin() {
+               super();
+               plugin = this;
+               try {
+                       resourceBundle = ResourceBundle
+                                       .getBundle("net.sourceforge.phpdt.internal.debug.core.debugresources"); //$NON-NLS-1$
+               } catch (MissingResourceException x) {
+                       resourceBundle = null;
+               }
+       }
+
+       public java.util.ResourceBundle getResourceBundle() {
+               return resourceBundle;
+       }
+
+       private IWorkbenchPage internalGetActivePage() {
+               return getWorkbench().getActiveWorkbenchWindow().getActivePage();
+       }
+
        /**
         * @see Plugin#shutdown()
         */
-       public void shutdown() throws CoreException {
-               plugin = null;
-               super.shutdown();
-       }
+       /*
+        * public void shutdown() throws CoreException { plugin = null;
+        * super.shutdown(); }
+        */
        /**
         * This method is called upon plug-in activation
         */
@@ -83,6 +132,7 @@ public class PHPDebugCorePlugin extends Plugin {
         * This method is called when the plug-in is stopped
         */
        public void stop(BundleContext context) throws Exception {
+               plugin = null;
                super.stop(context);
        }
 }