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