Fix variable view value modification and refactored XDebugAbstractValue and derived...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugBooleanValue.java
index 67e2713..e826240 100644 (file)
@@ -1,48 +1,54 @@
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
 import org.w3c.dom.Node;
 
 public class XDebugBooleanValue extends XDebugAbstractValue {
-       public XDebugBooleanValue(XDebugStackFrame variable, Node value) {
+       public XDebugBooleanValue(XDebugStackFrame variable, Node value) throws DebugException {
                super(variable, value);
+
+               renderValueString(rowValue);
        }
        
        public boolean supportsValueModification() {
                return true;
        }
 
-       public void renderValueString(String data) {
-               int value=-1;
-               try {
-                       value=Integer.parseInt(data);
-               } catch (NumberFormatException e) {
-                       data=data.toLowerCase();
-                       if (data.equals("true") || data.equals("false"))
-                               fValueString=data;
-                       else
-                               fValueString="not defined";
+       public boolean setValue(String expression) throws DebugException {
+               if (isValid(expression)) {
+                       renderValueString(expression);
+                       fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
+                       return true;
                }
-               if (value==0) 
-                       fValueString="false";
-               else if (value==1)
-                       fValueString="true";
-               else
-                       fValueString="not defined";
+               return false;
        }
 
-       public boolean verifyValue(String expression) {
-               int value=-1;
+       private void renderValueString(String data) {
+               if (data.equals("0") || data.toLowerCase().equals("false")) { 
+                       setValueString("false");
+               } else if (data.equals("1") || data.toLowerCase().equals("true")) {
+                       setValueString("true");
+               }
+       }
+
+       private boolean isValid(String expression) {
+               int value = -1;
                try {
-                       value=Integer.parseInt(expression);
+                       value = Integer.parseInt(expression);
                } catch (NumberFormatException e) {
-                       expression=expression.toLowerCase();
+                       expression = expression.toLowerCase();
                        if (expression.equals("true") || expression.equals("false"))
                                return true;
                        else
                                return false;
                }
-               if ((value>=0)&& (value <=1))
+               if ((value >= 0)&& (value <= 1))
                        return true;
                return false;
        }
+       
+       public boolean verifyValue(String expression) {
+               return isValid(expression);
+       }
 }
\ No newline at end of file