1 19 20 package org.netbeans.modules.debugger.importd; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 25 import org.openide.TopManager; 26 import org.openide.debugger.Debugger; 27 import org.openide.debugger.DebuggerException; 28 import org.openide.text.Line; 29 30 import org.netbeans.modules.debugger.*; 31 32 33 40 public class ImportWatch extends AbstractWatch implements Validator.Object { 41 42 static final long serialVersionUID = 3431277044447811206L; 43 44 45 47 private String errorMessage = null; 48 private String name = ""; 49 private String type; 50 private String value; 51 private boolean isHidden; 52 private boolean valid = false; 53 private ImportDebugger debugger; 54 private transient PropertyChangeSupport pcs; 55 56 57 59 63 ImportWatch (ImportDebugger debugger, boolean hidden) { 64 this.debugger = debugger; 65 this.isHidden = hidden; 66 init (); 67 } 68 69 protected void init () { 70 pcs = new PropertyChangeSupport (this); 71 debugger.getValidator ().add (this); 72 } 73 74 private void readObject(java.io.ObjectInputStream in) 75 throws java.io.IOException , ClassNotFoundException { 76 in.defaultReadObject (); 77 init (); 78 } 79 80 81 83 84 86 public void remove () { 87 debugger.removeWatch (this); 88 } 89 90 94 public String getVariableName () { 95 return name; 96 } 97 98 102 public void setVariableName (String name) { 103 this.name = name; 104 valid = false; 105 } 106 107 114 public String getAsText () { 115 if (!valid) refresh (); 116 return value; 117 } 118 119 125 public void setAsText (String value) throws DebuggerException { 126 valid = false; 127 } 128 129 133 public String getType () { 134 if (!valid) refresh (); 135 return type; 136 } 137 138 145 public boolean isHidden () { 146 return isHidden; 147 } 148 149 155 public void addPropertyChangeListener (PropertyChangeListener l) { 156 pcs.addPropertyChangeListener (l); 157 } 158 159 164 public void removePropertyChangeListener (PropertyChangeListener l) { 165 pcs.removePropertyChangeListener (l); 166 } 167 168 169 171 public String getErrorMessage () { 172 if (!valid) refresh (); 173 return errorMessage; 174 } 175 176 179 public void validate () { 180 valid = false; 181 firePropertyChange (); 182 } 183 184 private void refresh () { 185 type = ""; 186 value = ""; 187 if ((debugger.getState () == debugger.DEBUGGER_NOT_RUNNING) || 188 (debugger.getState () == debugger.DEBUGGER_STARTING) 189 ) { 190 errorMessage = ImportDebugger.getLocString ("EXC_No_session"); 191 firePropertyChange (); 192 return; 193 } 194 if (debugger.getState () != debugger.DEBUGGER_STOPPED) { 195 errorMessage = ImportDebugger.getLocString ("CTL_No_context"); 196 firePropertyChange (); 197 return; 198 } 199 try { 200 Line l = debugger.getCurrentLine (); 201 if (l == null) { 202 errorMessage = ImportDebugger.getLocString ("CTL_No_context"); 203 firePropertyChange (); 204 return; 205 } 206 errorMessage = null; 207 String s = ImportDebugger.getText (l); 208 int i = s.indexOf (getVariableName ()); 209 if (i >= 0) { 210 value = s.substring (i); 211 type = s.substring (0, i); 212 } else 213 errorMessage = ImportDebugger.getLocString ("Unknown_variable"); 214 } catch (Exception e) { 215 value = ""; 216 errorMessage = e.toString (); 217 } 218 } 219 220 protected void firePropertyChange () { 221 pcs.firePropertyChange (null, null, null); 222 } 223 224 231 public boolean canRemove () { 232 return false; 233 } 234 235 } 236 237 | Popular Tags |