added textArea as a temporary report area. will be replaced by a tree at some point...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / PHPDebugUiPlugin.java
1 package net.sourceforge.phpdt.internal.debug.ui;
2
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
4
5 import org.eclipse.core.resources.IWorkspace;
6 import org.eclipse.core.runtime.IPluginDescriptor;
7 import org.eclipse.core.runtime.IStatus;
8 import org.eclipse.core.runtime.Status;
9 import org.eclipse.ui.IWorkbenchPage;
10 import org.eclipse.ui.IWorkbenchWindow;
11 import org.eclipse.ui.plugin.AbstractUIPlugin;
12 import org.eclipse.swt.widgets.Shell;
13 import org.eclipse.jface.dialogs.ErrorDialog;
14 import org.eclipse.swt.widgets.Display;
15
16 public class PHPDebugUiPlugin extends AbstractUIPlugin {
17         public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.debug.ui"; //$NON-NLS-1$
18         protected static PHPDebugUiPlugin plugin;
19
20         public PHPDebugUiPlugin(IPluginDescriptor descriptor) {
21                 super(descriptor);
22                 plugin = this;
23         }
24
25         public static IWorkbenchWindow getActiveWorkbenchWindow() {
26                 return getDefault().getWorkbench().getActiveWorkbenchWindow();
27         }
28
29         public static IWorkbenchPage getActivePage() {
30                 return PHPDebugUiPlugin.getActiveWorkbenchWindow().getActivePage();
31         }
32
33         public static PHPDebugUiPlugin getDefault() {
34                 return plugin;
35         }
36
37         public static IWorkspace getWorkspace() {
38                 return PHPeclipsePlugin.getWorkspace();
39         }
40         
41         /**
42          * Convenience method which returns the unique identifier of this plugin.
43          */
44         public static String getUniqueIdentifier()
45         {
46                 if ( getDefault() == null )
47                 {
48                         // If the default instance is not yet initialized,
49                         // return a static identifier. This identifier must
50                         // match the plugin id defined in plugin.xml
51                         return PLUGIN_ID;
52                 }
53                 return getDefault().getDescriptor().getUniqueIdentifier();
54         }
55         
56         /**
57          * Returns the standard display to be used. The method first checks, if
58          * the thread calling this method has an associated display. If so, this
59          * display is returned. Otherwise the method returns the default display.
60          */
61         public static Display getStandardDisplay() {
62                 Display display;
63                 display= Display.getCurrent();
64                 if (display == null)
65                         display= Display.getDefault();
66                 return display;         
67         }
68         
69         /**
70          * Returns the active workbench shell or <code>null</code> if none
71          * 
72          * @return the active workbench shell or <code>null</code> if none
73          */
74         public static Shell getActiveWorkbenchShell() {
75                 IWorkbenchWindow window = getActiveWorkbenchWindow();
76                 if (window != null) {
77                         return window.getShell();
78                 }
79                 return null;
80         }
81         
82         public static void errorDialog( String message, IStatus status )
83                 {
84                         log( status );
85                         Shell shell = getActiveWorkbenchShell();
86                         if ( shell != null )
87                         {
88                                 ErrorDialog.openError( shell, "Error", message, status );
89                         }
90                 }
91
92                 public static void errorDialog( String message, Throwable t )
93                 {
94                         log( t );
95                         Shell shell = getActiveWorkbenchShell();
96                         if ( shell != null )
97                         {
98                                 IStatus status = new Status( IStatus.ERROR, getUniqueIdentifier(), /*ICDebugUIConstants.INTERNAL_ERROR*/ 150, t.getMessage(), null ); //$NON-NLS-1$     
99                                 ErrorDialog.openError( shell, "Error", message, status );
100                         }
101                 }                       
102
103         public static void log(IStatus status) {
104                 getDefault().getLog().log(status);
105         }
106
107         public static void log(Throwable e) {
108                 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, PHPDebugUiMessages.getString("RdtDebugUiPlugin.internalErrorOccurred"), e)); //$NON-NLS-1$
109         }
110
111 //      protected void initializeDefaultPreferences(IPreferenceStore store) {
112 //              super.initializeDefaultPreferences(store);
113 //              
114 //              store.setDefault(RdtDebugUiConstants.PREFERENCE_KEYWORDS, getDefaultKeywords());
115 //      }
116
117 //      protected String getDefaultKeywords() {
118 //              return "class,def,end,if,module,new,puts,require,rescue,throw,while";
119 //      }
120 }