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