REOPENED - bug 301774: [DataBinding] <List|Set|Map>Diff.simulateOn(List|Set|Map)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=301774
diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/SimpleListProperty.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/SimpleListProperty.java
index 9b3b88b..d3731aa 100644
--- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/SimpleListProperty.java
+++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/SimpleListProperty.java
@@ -8,10 +8,12 @@
* Contributors:
* Matthew Hall - initial API and implementation (bug 194734)
* Matthew Hall - bugs 195222, 247997, 265561
+ * Ovidio Mallo - bug 301774
******************************************************************************/
package org.eclipse.core.databinding.property.list;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.observable.Diffs;
@@ -87,7 +89,8 @@
}
protected void doUpdateList(Object source, ListDiff diff) {
- List list = diff.simulateOn(doGetList(source));
+ List list = new ArrayList(doGetList(source));
+ diff.applyTo(list);
doSetList(source, list, diff);
}
diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java
index 021ee91..6046537 100644
--- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java
+++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java
@@ -8,10 +8,12 @@
* Contributors:
* Matthew Hall - initial API and implementation
* Matthew Hall - bugs 195222, 247997, 265561
+ * Ovidio Mallo - bug 301774
******************************************************************************/
package org.eclipse.core.databinding.property.map;
+import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.databinding.observable.Diffs;
@@ -87,7 +89,8 @@
}
protected void doUpdateMap(Object source, MapDiff diff) {
- Map map = diff.simulateOn(doGetMap(source));
+ Map map = new HashMap(doGetMap(source));
+ diff.applyTo(map);
doSetMap(source, map, diff);
}
diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java
index 087a317..7e316a0 100644
--- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java
+++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java
@@ -8,10 +8,12 @@
* Contributors:
* Matthew Hall - initial API and implementation
* Matthew Hall - bugs 195222, 247997, 265561
+ * Ovidio Mallo - bug 301774
******************************************************************************/
package org.eclipse.core.databinding.property.set;
+import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.databinding.observable.Diffs;
@@ -86,7 +88,8 @@
}
protected void doUpdateSet(Object source, SetDiff diff) {
- Set set = diff.simulateOn(doGetSet(source));
+ Set set = new HashSet(doGetSet(source));
+ diff.applyTo(set);
doSetSet(source, set, diff);
}
diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java
index 2cd2758..fa96516 100644
--- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java
+++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java
@@ -8,6 +8,7 @@
* Contributors:
* Brad Reynolds - initial API and implementation
* Matthew Hall - bugs 221351, 213145, 244098, 246103, 194734, 268688
+ * Ovidio Mallo - bug 301774
******************************************************************************/
package org.eclipse.core.tests.internal.databinding.beans;
@@ -560,6 +561,30 @@
.singletonList("element"));
}
+ /**
+ * Makes sure that the list set on the Bean model after changing the
+ * observable list is modifiable (see bugs 285307 and 301774).
+ */
+ public void testUpdatedBeanListIsModifiable() {
+ Bean bean = new Bean(new ArrayList());
+ IObservableList observable = BeansObservables.observeList(bean, "list");
+
+ observable.add(new Object());
+ bean.getList().clear();
+ }
+
+ /**
+ * Makes sure that the list set on the Pojo model after changing the
+ * observable list is modifiable (see bugs 285307 and 301774).
+ */
+ public void testUpdatedPojoListIsModifiable() {
+ Bean bean = new Bean(new ArrayList());
+ IObservableList observable = PojoObservables.observeList(bean, "list");
+
+ observable.add(new Object());
+ bean.getList().clear();
+ }
+
private static void assertDiff(ListDiff diff, List oldList, List newList) {
oldList = new ArrayList(oldList); // defensive copy in case arg is
// unmodifiable
diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java
index 128672f..60ab20d 100644
--- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java
+++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java
@@ -8,12 +8,13 @@
* Contributors:
* Brad Reynolds - initial API and implementation
* Matthew Hall - bugs 221351, 213145, 244098, 246103, 194734, 268688
- * Ovidio Mallo - bug 247741
+ * Ovidio Mallo - bugs 247741, 301774
******************************************************************************/
package org.eclipse.core.tests.internal.databinding.beans;
import java.beans.PropertyDescriptor;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@@ -175,6 +176,30 @@
.singleton("element"));
}
+ /**
+ * Makes sure that the set set on the Bean model after changing the
+ * observable set is modifiable (see bugs 285307 and 301774).
+ */
+ public void testUpdatedBeanSetIsModifiable() {
+ Bean bean = new Bean(new ArrayList());
+ IObservableSet observable = BeansObservables.observeSet(bean, "set");
+
+ observable.add(new Object());
+ bean.getSet().clear();
+ }
+
+ /**
+ * Makes sure that the set set on the Pojo model after changing the
+ * observable set is modifiable (see bugs 285307 and 301774).
+ */
+ public void testUpdatedPojoSetIsModifiable() {
+ Bean bean = new Bean(new ArrayList());
+ IObservableSet observable = PojoObservables.observeSet(bean, "set");
+
+ observable.add(new Object());
+ bean.getSet().clear();
+ }
+
private static void assertDiff(SetDiff diff, Set oldSet, Set newSet) {
oldSet = new HashSet(oldSet); // defensive copy in case arg is
// unmodifiable
diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java
index bcd9899..6fffceb 100644
--- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java
+++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java
@@ -7,13 +7,16 @@
*
* Contributors:
* Matthew Hall - initial API and implementation (bug 246103)
+ * Ovidio Mallo - bug 301774
******************************************************************************/
package org.eclipse.core.tests.internal.databinding.beans;
+import java.util.ArrayList;
import java.util.Collections;
import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker;
@@ -53,4 +56,27 @@
assertEquals("new", tracker.event.diff.getNewValue("key"));
}
+ /**
+ * Makes sure that the map set on the Bean model after changing the
+ * observable map is modifiable (see bugs 285307 and 301774).
+ */
+ public void testUpdatedBeanMapIsModifiable() {
+ Bean bean = new Bean(new ArrayList());
+ IObservableMap observable = BeansObservables.observeMap(bean, "map");
+
+ observable.put(new Object(), new Object());
+ bean.getMap().clear();
+ }
+
+ /**
+ * Makes sure that the map set on the Pojo model after changing the
+ * observable map is modifiable (see bugs 285307 and 301774).
+ */
+ public void testUpdatedPojoMapIsModifiable() {
+ Bean bean = new Bean(new ArrayList());
+ IObservableMap observable = PojoObservables.observeMap(bean, "map");
+
+ observable.put(new Object(), new Object());
+ bean.getMap().clear();
+ }
}