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
1 package net.sourceforge.phpeclipse.xdebug.php.model;
2
3 import org.eclipse.debug.core.DebugEvent;
4 import org.eclipse.debug.core.DebugException;
5 import org.w3c.dom.Node;
6
7 public class XDebugBooleanValue extends XDebugAbstractValue {
8         public XDebugBooleanValue(XDebugStackFrame variable, Node value) throws DebugException {
9                 super(variable, value);
10
11                 renderValueString(rowValue);
12         }
13         
14         public boolean supportsValueModification() {
15                 return true;
16         }
17
18         public boolean setValue(String expression) throws DebugException {
19                 if (isValid(expression)) {
20                         renderValueString(expression);
21                         fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
22                         return true;
23                 }
24                 return false;
25         }
26
27         private void renderValueString(String data) {
28                 if (data.equals("0") || data.toLowerCase().equals("false")) { 
29                         setValueString("false");
30                 } else if (data.equals("1") || data.toLowerCase().equals("true")) {
31                         setValueString("true");
32                 }
33         }
34
35         private boolean isValid(String expression) {
36                 int value = -1;
37                 try {
38                         value = Integer.parseInt(expression);
39                 } catch (NumberFormatException e) {
40                         expression = expression.toLowerCase();
41                         if (expression.equals("true") || expression.equals("false"))
42                                 return true;
43                         else
44                                 return false;
45                 }
46                 if ((value >= 0)&& (value <= 1))
47                         return true;
48                 return false;
49         }
50         
51         public boolean verifyValue(String expression) {
52                 return isValid(expression);
53         }
54 }