changeset 9228:b2f8540a4924 9-b79

8129401: Bindings.bindContentBidirectional does not work correctly Reviewed-by: ckyang
author vadim
date Sat, 22 Aug 2015 00:31:37 +0300
parents 8ae42f7a7011
children f0e68522a757 321fdaf68551
files modules/base/src/main/java/com/sun/javafx/binding/BidirectionalContentBinding.java modules/base/src/main/java/com/sun/javafx/collections/ObservableMapWrapper.java modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingListTest.java modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingMapTest.java
diffstat 4 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/modules/base/src/main/java/com/sun/javafx/binding/BidirectionalContentBinding.java	Thu Aug 20 19:04:48 2015 -0700
+++ b/modules/base/src/main/java/com/sun/javafx/binding/BidirectionalContentBinding.java	Sat Aug 22 00:31:37 2015 +0300
@@ -308,7 +308,8 @@
                         final Map<K, V> dest = (map1 == change.getMap())? map2 : map1;
                         if (change.wasRemoved()) {
                             dest.remove(change.getKey());
-                        } else {
+                        }
+                        if (change.wasAdded()) {
                             dest.put(change.getKey(), change.getValueAdded());
                         }
                     } finally {
--- a/modules/base/src/main/java/com/sun/javafx/collections/ObservableMapWrapper.java	Thu Aug 20 19:04:48 2015 -0700
+++ b/modules/base/src/main/java/com/sun/javafx/collections/ObservableMapWrapper.java	Sat Aug 22 00:31:37 2015 +0300
@@ -98,12 +98,12 @@
             StringBuilder builder = new StringBuilder();
             if (wasAdded) {
                 if (wasRemoved) {
-                    builder.append("replaced ").append(old).append("by ").append(added);
+                    builder.append(old).append(" replaced by ").append(added);
                 } else {
-                    builder.append("added ").append(added);
+                    builder.append(added).append(" added");
                 }
             } else {
-                builder.append("removed ").append(old);
+                builder.append(old).append(" removed");
             }
             builder.append(" at key ").append(key);
             return builder.toString();
--- a/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingListTest.java	Thu Aug 20 19:04:48 2015 -0700
+++ b/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingListTest.java	Sat Aug 22 00:31:37 2015 +0300
@@ -270,4 +270,12 @@
         assertFalse(binding3.equals(binding1));
         assertFalse(binding3.equals(binding4));
     }
+
+    @Test
+    public void testChangeValue() {
+        Bindings.bindContentBidirectional(op1, op2);
+        assertEquals(2, op2.get(0).intValue());
+        op1.set(0, 1);
+        assertEquals(1, op2.get(0).intValue());
+    }
 }
--- a/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingMapTest.java	Thu Aug 20 19:04:48 2015 -0700
+++ b/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingMapTest.java	Sat Aug 22 00:31:37 2015 +0300
@@ -282,4 +282,12 @@
         assertFalse(binding3.equals(binding1));
         assertFalse(binding3.equals(binding4));
     }
+
+    @Test
+    public void testChangeValue() {
+        Bindings.bindContentBidirectional(op1, op2);
+        assertEquals(2, op2.get(key2_1).intValue());
+        op1.put(key2_1, 1);
+        assertEquals(1, op2.get(key2_1).intValue());
+    }
 }