A massive organize imports and formatting of the sources using default Eclipse code...
[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.IStatus;
7 import org.eclipse.core.runtime.Status;
8 import org.eclipse.jface.dialogs.ErrorDialog;
9 import org.eclipse.swt.widgets.Display;
10 import org.eclipse.swt.widgets.Shell;
11 import org.eclipse.ui.IWorkbenchPage;
12 import org.eclipse.ui.IWorkbenchWindow;
13 import org.eclipse.ui.plugin.AbstractUIPlugin;
14 import org.osgi.framework.BundleContext;
15
16 public class PHPDebugUiPlugin extends AbstractUIPlugin {
17         public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.debug.ui"; //$NON-NLS-1$
18
19         protected static PHPDebugUiPlugin plugin;
20
21         public PHPDebugUiPlugin() {
22                 super();
23                 plugin = this;
24         }
25
26         public static IWorkbenchWindow getActiveWorkbenchWindow() {
27                 return getDefault().getWorkbench().getActiveWorkbenchWindow();
28         }
29
30         public static IWorkbenchPage getActivePage() {
31                 return PHPDebugUiPlugin.getActiveWorkbenchWindow().getActivePage();
32         }
33
34         public static PHPDebugUiPlugin getDefault() {
35                 return plugin;
36         }
37
38         public static IWorkspace getWorkspace() {
39                 return PHPeclipsePlugin.getWorkspace();
40         }
41
42         /**
43          * Convenience method which returns the unique identifier of this plugin.
44          */
45         // public static String getUniqueIdentifier()
46         // {
47         // if ( getDefault() == null )
48         // {
49         // // If the default instance is not yet initialized,
50         // // return a static identifier. This identifier must
51         // // match the plugin id defined in plugin.xml
52         // return PLUGIN_ID;
53         // }
54         // return getDefault().getDescriptor().getUniqueIdentifier();
55         // }
56         /**
57          * Returns the standard display to be used. The method first checks, if the
58          * thread calling this method has an associated display. If so, this display
59          * 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                 log(status);
84                 Shell shell = getActiveWorkbenchShell();
85                 if (shell != null) {
86                         ErrorDialog.openError(shell, "Error", message, status);
87                 }
88         }
89
90         public static void errorDialog(String message, Throwable t) {
91                 log(t);
92                 Shell shell = getActiveWorkbenchShell();
93                 if (shell != null) {
94                         IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, /* ICDebugUIConstants.INTERNAL_ERROR */
95                                         150, t.getMessage(), null); //$NON-NLS-1$       
96                         ErrorDialog.openError(shell, "Error", message, status);
97                 }
98         }
99
100         public static void log(IStatus status) {
101                 getDefault().getLog().log(status);
102         }
103
104         public static void log(Throwable e) {
105                 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
106                                 PHPDebugUiMessages
107                                                 .getString("RdtDebugUiPlugin.internalErrorOccurred"), e)); //$NON-NLS-1$
108         }
109
110         /**
111          * This method is called upon plug-in activation
112          */
113         public void start(BundleContext context) throws Exception {
114                 super.start(context);
115         }
116
117         /**
118          * This method is called when the plug-in is stopped
119          */
120         public void stop(BundleContext context) throws Exception {
121                 super.stop(context);
122         }
123
124         // protected void initializeDefaultPreferences(IPreferenceStore store) {
125         // super.initializeDefaultPreferences(store);
126         //              
127         // store.setDefault(RdtDebugUiConstants.PREFERENCE_KEYWORDS,
128         // getDefaultKeywords());
129         // }
130
131         // protected String getDefaultKeywords() {
132         // return "class,def,end,if,module,new,puts,require,rescue,throw,while";
133         // }
134 }