Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / core / XDebugCorePlugin.java
1 package net.sourceforge.phpeclipse.xdebug.core;
2
3
4 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
5 //import org.eclipse.ui.plugin.AbstractUIPlugin;// *;
6 import org.eclipse.ui.preferences.ScopedPreferenceStore;
7 //import org.eclipse.core.resources.IWorkspace;
8 //import org.eclipse.core.resources.ResourcesPlugin;
9 //import org.eclipse.core.resources.IWorkspace;
10 //import org.eclipse.core.resources.ResourcesPlugin;
11 import org.eclipse.core.runtime.IStatus;
12 import org.eclipse.core.runtime.Plugin;
13 //import org.eclipse.core.runtime.Plugin;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.core.runtime.preferences.InstanceScope;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.IBreakpointManager;
18 import org.eclipse.debug.core.model.IBreakpoint;
19 import org.eclipse.jface.preference.IPreferenceStore;
20 //import org.eclipse.jface.resource.ImageDescriptor;
21 import org.osgi.framework.BundleContext;
22
23 public class XDebugCorePlugin extends Plugin {
24         private static XDebugCorePlugin plugin;
25         public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.xdebug.core"; //$NON-NLS-1$
26         
27         private XDebugProxy fXDebugProxy;
28
29         private ScopedPreferenceStore preferenceStore;
30
31         
32         /**
33          * The constructor.
34          */
35         public XDebugCorePlugin() {
36                 plugin = this;
37         }
38
39         /**
40          * This method is called upon plug-in activation
41          */
42         public void start(BundleContext context) throws Exception {
43                 super.start(context);
44         }
45
46         /**
47          * This method is called when the plug-in is stopped
48          */
49         public void stop(BundleContext context) throws Exception {
50                 super.stop(context);
51                 if (fXDebugProxy != null)
52                         fXDebugProxy.stop();
53                 plugin = null;
54         }
55
56         /**
57          * Returns the shared instance.
58          */
59         public static XDebugCorePlugin getDefault() {
60                 return plugin;
61         }
62         
63         /*public static IWorkspace getWorkspace() {
64                 return ResourcesPlugin.getWorkspace();
65         }*/
66                    
67         public static IBreakpoint[] getBreakpoints() {
68                 return getBreakpointManager().getBreakpoints(IXDebugConstants.ID_PHP_DEBUG_MODEL);
69         }
70         
71         public static /*static*/ IBreakpointManager getBreakpointManager() {
72                 return DebugPlugin.getDefault().getBreakpointManager();
73         }
74
75         public static void log(int severity, String message) {
76                 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null) ;
77                 XDebugCorePlugin.log(status) ;
78         }
79
80         public static void log(IStatus status) {
81                 getDefault().getLog().log(status);
82         }
83
84         public static void log(Throwable e) {
85                 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPLaunchingPlugin.internalErrorOccurred", e)); //$NON-NLS-1$
86         }
87         
88         public static String getUniqueIdentifier() {
89                 return PLUGIN_ID;
90         }
91         
92         public void setProxyPort(int port) {
93                 if(fXDebugProxy!=null) {
94                         if (fXDebugProxy.isRunning()) {
95                                 fXDebugProxy.stop();
96                         }
97                         fXDebugProxy=null;
98                 }
99         }
100
101         public XDebugProxy getXDebugProxy() {
102                 if (fXDebugProxy == null) {
103                         int debugPort=getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE);
104                         if (debugPort<1024)
105                                 debugPort=IXDebugPreferenceConstants.DEFAULT_DEBUGPORT;
106                         fXDebugProxy= new XDebugProxy(debugPort);
107                 }
108                 return fXDebugProxy;
109         }
110         
111     public IPreferenceStore getPreferenceStore() {
112         // Create the preference store lazily.
113         if (preferenceStore == null) {
114             preferenceStore = new ScopedPreferenceStore(new InstanceScope(),getBundle().getSymbolicName());
115
116         }
117         return preferenceStore;
118     }
119 }