[snow-cvs] r7 - in trunk: src/java/snow/binding test/src/snow

Alessio Stalla astalla at common-lisp.net
Tue Oct 20 18:24:44 UTC 2009


Author: astalla
Date: Tue Oct 20 14:24:43 2009
New Revision: 7

Log:
Fixed BeanPropertyPathBinding


Modified:
   trunk/src/java/snow/binding/BeanPropertyPathBinding.java
   trunk/test/src/snow/BindingTest.java

Modified: trunk/src/java/snow/binding/BeanPropertyPathBinding.java
==============================================================================
--- trunk/src/java/snow/binding/BeanPropertyPathBinding.java	(original)
+++ trunk/src/java/snow/binding/BeanPropertyPathBinding.java	Tue Oct 20 14:24:43 2009
@@ -82,9 +82,10 @@
 	reader = pd.getReadMethod();
 	writer = pd.getWriteMethod();
 	if(nextPropertyPath.length > 0) {
-	    Object subObj = getValue();
+	    Object subObj = getLocalValue();
 	    if(subObj != null) {
 		nextListener = new BeanPropertyPathBinding(subObj, nextPropertyPath, this);
+		
 	    }
 	}
     }
@@ -137,20 +138,66 @@
 	    fireValueChange(evt.getOldValue(), evt.getNewValue(), false);
 	}
     }
+
+    private BeanPropertyPathBinding getTarget() {
+	if(nextPropertyPath.length == 0) {
+	    return this;
+	} else if(nextListener != null) {
+	    return nextListener.getTarget();
+	} else {
+	    return null;
+	}
+    }
 	
+    public Object getLocalValue() {
+	try {
+	    return reader.invoke(object);
+	} catch(Exception e) {
+	    throw new RuntimeException(e);
+	}
+    }
+
     @Override
     public Object getValue() {
 	try {
-	    return reader.invoke(object);
+	    BeanPropertyPathBinding target = getTarget();
+	    if(target != null) {
+		return target.getLocalValue();
+	    } else {
+		return null;
+	    }
+	} catch(Exception e) {
+	    throw new RuntimeException(e);
+	}
+    }
+
+    public void setLocalValue(Object value) {
+	try {
+	    System.err.println(object + " " + writer + " " + value);
+	    writer.invoke(object, value);
 	} catch(Exception e) {
 	    throw new RuntimeException(e);
 	}
     }
 
+
     @Override
     public void setValue(Object value) {
 	try {
-	    writer.invoke(object, value);
+	    BeanPropertyPathBinding target = getTarget();
+	    if(target != null) {
+		target.setLocalValue(value);
+	    } else {
+		StringBuilder sb = new StringBuilder();
+		assert(nextPropertyPath != null);
+		for(String s : nextPropertyPath) {
+		    if(sb.length() > 0) {
+			sb.append('.');
+		    }
+		    sb.append(s);
+		}
+		throw new NullPointerException("Property " + sb + " not reachable.");
+	    }
 	} catch(Exception e) {
 	    throw new RuntimeException(e);
 	}

Modified: trunk/test/src/snow/BindingTest.java
==============================================================================
--- trunk/test/src/snow/BindingTest.java	(original)
+++ trunk/test/src/snow/BindingTest.java	Tue Oct 20 14:24:43 2009
@@ -11,6 +11,7 @@
 import net.miginfocom.swing.MigLayout;
 
 import org.junit.*;
+import static org.junit.Assert.*;
 
 import com.jgoodies.binding.adapter.Bindings;
 import com.jgoodies.binding.beans.Model;
@@ -67,13 +68,17 @@
 	    });
 	bean.getBean().setProperty("value2");
 	if(flag[0]) {
-	    Assert.fail("value was set but listener not fired");
+	    Assert.fail("value was set but listener didn't fire");
 	}
 	flag[0] = true;
 	bean.getBean().setProperty("value2");
 	if(!flag[0]) {
 	    Assert.fail("value was set to same value and listener fired");
 	}
+	model.setValue("42");
+	System.err.println("outer bean: " + bean);
+	System.err.println("inner bean: " + bean.getBean());
+	assertEquals("42", bean.getBean().getProperty());
     }
     
     public static void main(String[] args) {




More information about the snow-cvs mailing list