f2c34dab13df4bb201978277edd3fa9301d987e2
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDebugCorePlugin.java
1 package net.sourceforge.phpdt.internal.debug.core;
2
3 import java.util.MissingResourceException;
4 import java.util.ResourceBundle;
5
6 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
7
8 import org.eclipse.core.resources.IWorkspace;
9 import org.eclipse.core.runtime.IStatus;
10 import org.eclipse.core.runtime.Status;
11 //import org.eclipse.swt.widgets.Shell;
12 import org.eclipse.ui.IWorkbenchPage;
13 import org.eclipse.ui.IWorkbenchWindow;
14 import org.eclipse.ui.plugin.AbstractUIPlugin;
15 import org.osgi.framework.BundleContext;
16
17 /**
18  * The main plugin class to be used in the desktop.
19  */
20 public class PHPDebugCorePlugin extends AbstractUIPlugin {
21         // The shared instance.
22         protected static PHPDebugCorePlugin plugin;
23
24         public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.debug.core"; //$NON-NLS-1$
25
26         public static IWorkbenchPage getActivePage() {
27                 return getDefault().internalGetActivePage();
28         }
29
30 //      public static Shell getActiveWorkbenchShell() {
31 //              return getActiveWorkbenchWindow().getShell();
32 //      }
33
34         public static IWorkbenchWindow getActiveWorkbenchWindow() {
35                 return getDefault().getWorkbench().getActiveWorkbenchWindow();
36         }
37
38         /**
39          * Returns the shared instance.
40          */
41         public static PHPDebugCorePlugin getDefault() {
42                 return plugin;
43         }
44
45 //      public static String getFormattedMessage(String key, String arg) {
46 //              String text = getResourceString(key);
47 //              return java.text.MessageFormat.format(text, new Object[] { arg });
48 //      }
49
50         public static String getResourceString(String key) {
51                 ResourceBundle bundle = plugin.getResourceBundle();
52                 if (bundle != null) {
53                         try {
54                                 String bundleString = bundle.getString(key);
55                                 // return "$"+bundleString;
56                                 return bundleString;
57                         } catch (MissingResourceException e) {
58                                 // default actions is to return key, which is OK
59                         }
60                 }
61                 return key;
62         }
63
64         /**
65          * Convenience method which returns the unique identifier of this plugin.
66          */
67         public static String getUniqueIdentifier() {
68                 return PLUGIN_ID;
69         }
70
71         /**
72          * Returns the workspace instance.
73          */
74         public static IWorkspace getWorkspace() {
75                 return PHPeclipsePlugin.getWorkspace();
76         }
77
78         public static void log(int severity, String message) {
79                 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
80                                 null);
81                 PHPDebugCorePlugin.log(status);
82         }
83
84         public static void log(IStatus status) {
85                 getDefault().getLog().log(status);
86         }
87
88         public static void log(Throwable e) {
89                 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
90                                 "PHPLaunchingPlugin.internalErrorOccurred", e)); //$NON-NLS-1$
91         }
92
93         private ResourceBundle resourceBundle;
94
95         /**
96          * The constructor.
97          */
98 //      public PHPDebugCorePlugin() {
99 //              super();
100 //              plugin = this;
101 //              try {
102 //                      resourceBundle = ResourceBundle
103 //                                      .getBundle("net.sourceforge.phpdt.internal.debug.core.debugresources"); //$NON-NLS-1$
104 //              } catch (MissingResourceException x) {
105 //                      resourceBundle = null;
106 //              }
107 //      }
108
109         public java.util.ResourceBundle getResourceBundle() {
110                 return resourceBundle;
111         }
112
113         private IWorkbenchPage internalGetActivePage() {
114                 return getWorkbench().getActiveWorkbenchWindow().getActivePage();
115         }
116
117         /**
118          * @see Plugin#shutdown()
119          */
120         /*
121          * public void shutdown() throws CoreException { plugin = null;
122          * super.shutdown(); }
123          */
124         /**
125          * This method is called upon plug-in activation
126          */
127         public void start(BundleContext context) throws Exception {
128                 super.start(context);
129         }
130
131         /**
132          * This method is called when the plug-in is stopped
133          */
134         public void stop(BundleContext context) throws Exception {
135                 plugin = null;
136                 super.stop(context);
137         }
138 }