Search in sources :

Example 16 with MapChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class CompositeMapTest method testAddToFirstMap.

@Test
public void testAddToFirstMap() {
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    SimplePerson newPerson = new SimplePerson("p1", "a1", "c1", "s1");
    newPerson.getCart().setNumItems(42);
    persons.add(newPerson);
    assertEquals(1, tracker.count);
    assertEquals(0, tracker.event.diff.getRemovedKeys().size());
    assertEquals(0, tracker.event.diff.getChangedKeys().size());
    assertEquals(Collections.singleton(newPerson), tracker.event.diff.getAddedKeys());
    assertEquals(Integer.valueOf(42), tracker.event.diff.getNewValue(newPerson));
    assertEquals(Integer.valueOf(42), composedMap.get(newPerson));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 17 with MapChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class CompositeMapTest method testAddSharedToFirstMap.

@Test
public void testAddSharedToFirstMap() {
    SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1");
    person1.getCart().setNumItems(42);
    persons.add(person1);
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    SimplePerson person2 = new SimplePerson("p1", "a1", "c1", "s1");
    person2.setCart(person1.getCart());
    persons.add(person2);
    assertEquals(1, tracker.count);
    assertEquals(0, tracker.event.diff.getRemovedKeys().size());
    assertEquals(0, tracker.event.diff.getChangedKeys().size());
    assertEquals(Collections.singleton(person2), tracker.event.diff.getAddedKeys());
    assertEquals(Integer.valueOf(42), tracker.event.diff.getNewValue(person2));
    assertEquals(Integer.valueOf(42), composedMap.get(person2));
    assertEquals(Integer.valueOf(42), composedMap.get(person1));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 18 with MapChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class CompositeMapTest method testChangeInFirstMapToShared.

@Test
public void testChangeInFirstMapToShared() {
    SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0");
    person0.getCart().setNumItems(13);
    persons.add(person0);
    SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1");
    person1.getCart().setNumItems(42);
    persons.add(person1);
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    person1.setCart(person0.getCart());
    assertEquals(1, tracker.count);
    assertEquals(0, tracker.event.diff.getAddedKeys().size());
    assertEquals(0, tracker.event.diff.getRemovedKeys().size());
    assertEquals(Collections.singleton(person1), tracker.event.diff.getChangedKeys());
    assertEquals(Integer.valueOf(42), tracker.event.diff.getOldValue(person1));
    assertEquals(Integer.valueOf(13), tracker.event.diff.getNewValue(person1));
    assertEquals(Integer.valueOf(13), composedMap.get(person1));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Aggregations

MapChangeEventTracker (org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker)18 Test (org.junit.Test)18 SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)10 IObservableMap (org.eclipse.core.databinding.observable.map.IObservableMap)4 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)3 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)2 SimpleCart (org.eclipse.jface.examples.databinding.model.SimpleCart)2 WritableMap (org.eclipse.core.databinding.observable.map.WritableMap)1 MapDetailValueObservableMap (org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap)1 SetDetailValueObservableMap (org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap)1