1 19 20 package org.netbeans.modules.scripting.php.dbginterface.breakpoints; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import org.netbeans.api.debugger.Breakpoint; 26 import org.netbeans.api.debugger.DebuggerEngine; 27 import org.netbeans.api.debugger.DebuggerManager; 28 import org.netbeans.api.debugger.LazyDebuggerManagerListener; 29 import org.netbeans.api.debugger.Properties; 30 import org.netbeans.api.debugger.Session; 31 import org.netbeans.api.debugger.Watch; 32 33 41 public class PersistenceManager implements LazyDebuggerManagerListener { 42 43 private static final String DEBUGGER = "debugger"; private static final String PHP_DBG = "PHP-DBG"; 46 public Breakpoint[] initBreakpoints() { 47 Properties p = Properties.getDefault().getProperties(DEBUGGER). 48 getProperties(DebuggerManager.PROP_BREAKPOINTS); 49 return (Breakpoint[]) p.getArray( 50 PHP_DBG, 51 new Breakpoint [0] 52 ); 53 } 54 55 public void initWatches() { 56 } 57 58 public String [] getProperties() { 59 return new String [] { 60 DebuggerManager.PROP_BREAKPOINTS_INIT, 61 DebuggerManager.PROP_BREAKPOINTS, 62 }; 63 } 64 65 public void breakpointAdded(Breakpoint breakpoint) { 66 Properties p = Properties.getDefault().getProperties(DEBUGGER). 67 getProperties(DebuggerManager.PROP_BREAKPOINTS); 68 p.setArray( 69 PHP_DBG, 70 getBreakpoints() 71 ); 72 breakpoint.addPropertyChangeListener(this); 73 } 74 75 public void breakpointRemoved(Breakpoint breakpoint) { 76 Properties p = Properties.getDefault().getProperties(DEBUGGER). 77 getProperties(DebuggerManager.PROP_BREAKPOINTS); 78 p.setArray( 79 PHP_DBG, 80 getBreakpoints() 81 ); 82 breakpoint.removePropertyChangeListener(this); 83 } 84 public void watchAdded(Watch watch) { 85 } 86 87 public void watchRemoved(Watch watch) { 88 } 89 public void propertyChange(PropertyChangeEvent evt) { 90 if (evt.getSource() instanceof Breakpoint) { 91 Properties.getDefault().getProperties(DEBUGGER). 92 getProperties(DebuggerManager.PROP_BREAKPOINTS).setArray( 93 PHP_DBG, 94 getBreakpoints() 95 ); 96 } 97 } 98 99 public void sessionAdded(Session session) {} 100 public void sessionRemoved(Session session) {} 101 public void engineAdded(DebuggerEngine engine) {} 102 public void engineRemoved(DebuggerEngine engine) {} 103 104 105 private static Breakpoint[] getBreakpoints() { 106 Breakpoint[] bs = DebuggerManager.getDebuggerManager(). 107 getBreakpoints(); 108 int i, k = bs.length; 109 List <Breakpoint> bb = new ArrayList <Breakpoint>(); 110 for (i = 0; i < k; i++) { 111 if (bs[i] instanceof PhpBreakpoint) { 113 bb.add(bs[i]); 114 } 115 } 116 bs = new Breakpoint [bb.size()]; 117 return (Breakpoint[]) bb.toArray(bs); 118 } 119 } | Popular Tags |