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