Search in sources :

Example 1 with MapChangeEventTracker

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

the class CompositeMapTest method testChangeInSecondMap.

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

Example 2 with MapChangeEventTracker

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

the class CompositeMapTest method testRemoveSharedFromFirstMap.

@Test
public void testRemoveSharedFromFirstMap() {
    SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1");
    person1.getCart().setNumItems(42);
    persons.add(person1);
    SimplePerson person2 = new SimplePerson("p1", "a1", "c1", "s1");
    person2.setCart(person1.getCart());
    persons.add(person2);
    assertTrue("person2 should be added", composedMap.containsKey(person2));
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    persons.remove(person2);
    assertEquals(1, tracker.count);
    assertEquals(0, tracker.event.diff.getAddedKeys().size());
    assertEquals(0, tracker.event.diff.getChangedKeys().size());
    assertEquals(Collections.singleton(person2), tracker.event.diff.getRemovedKeys());
    assertEquals(Integer.valueOf(42), tracker.event.diff.getOldValue(person2));
    assertFalse("person2 should be removed", composedMap.containsKey(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 3 with MapChangeEventTracker

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

the class CompositeMapTest method testChangeInFirstMapFromShared.

@Test
public void testChangeInFirstMapFromShared() {
    SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0");
    person0.getCart().setNumItems(13);
    persons.add(person0);
    SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1");
    person1.setCart(person0.getCart());
    persons.add(person1);
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    person1.setCart(new SimpleCart());
    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(13), tracker.event.diff.getOldValue(person1));
    assertEquals(Integer.valueOf(0), tracker.event.diff.getNewValue(person1));
    assertEquals(Integer.valueOf(0), composedMap.get(person1));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) SimpleCart(org.eclipse.jface.examples.databinding.model.SimpleCart) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 4 with MapChangeEventTracker

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

the class MapDetailValueObservableMapTest method testDetailObservableChangeEvent.

@Test
public void testDetailObservableChangeEvent() {
    WritableMap masterMap = new WritableMap();
    MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
    MapChangeEventTracker changeTracker = MapChangeEventTracker.observe(mdom);
    SimplePerson person = new SimplePerson();
    person.setName("old name");
    // Initially, we should not have received any event.
    assertEquals(0, changeTracker.count);
    // Add the person and check that we receive an addition event on the
    // correct index and with the correct value.
    masterMap.put(person, person);
    assertEquals(1, changeTracker.count);
    assertEquals(1, changeTracker.event.diff.getAddedKeys().size());
    assertEquals(0, changeTracker.event.diff.getRemovedKeys().size());
    assertEquals(0, changeTracker.event.diff.getChangedKeys().size());
    assertSame(person, changeTracker.event.diff.getAddedKeys().iterator().next());
    assertNull(changeTracker.event.diff.getOldValue(person));
    assertEquals("old name", changeTracker.event.diff.getNewValue(person));
    // Change the detail property and check that we receive a replace
    person.setName("new name");
    assertEquals(2, changeTracker.count);
    assertEquals(0, changeTracker.event.diff.getAddedKeys().size());
    assertEquals(0, changeTracker.event.diff.getRemovedKeys().size());
    assertEquals(1, changeTracker.event.diff.getChangedKeys().size());
    assertSame(person, changeTracker.event.diff.getChangedKeys().iterator().next());
    assertEquals("old name", changeTracker.event.diff.getOldValue(person));
    assertEquals("new name", changeTracker.event.diff.getNewValue(person));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) MapDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 5 with MapChangeEventTracker

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

the class JavaBeanObservableMapTest method testSetBeanProperty_CorrectForNullOldAndNewValues.

@Test
public void testSetBeanProperty_CorrectForNullOldAndNewValues() {
    // The java bean spec allows the old and new values in a
    // PropertyChangeEvent to be null, which indicates that an unknown
    // change occured.
    // This test ensures that JavaBeanObservableValue fires the correct
    // value diff even if the bean implementor is lazy :-P
    WritableSet set = new WritableSet(new CurrentRealm(true));
    Bean bean = new AnnoyingBean();
    bean.setValue("old");
    set.add(bean);
    IObservableMap map = BeansObservables.observeMap(set, Bean.class, "value");
    MapChangeEventTracker tracker = MapChangeEventTracker.observe(map);
    bean.setValue("new");
    assertEquals(1, tracker.count);
    assertEquals(Collections.EMPTY_SET, tracker.event.diff.getAddedKeys());
    assertEquals(Collections.singleton(bean), tracker.event.diff.getChangedKeys());
    assertEquals(Collections.EMPTY_SET, tracker.event.diff.getRemovedKeys());
    assertEquals("old", tracker.event.diff.getOldValue(bean));
    assertEquals("new", tracker.event.diff.getNewValue(bean));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) 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