use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableMapTest method testAddKey.
@Test
public void testAddKey() throws Exception {
MapChangeEventTracker listener = new MapChangeEventTracker();
map.addMapChangeListener(listener);
Bean model3 = new Bean("3");
assertEquals(0, listener.count);
set.add(model3);
assertEquals(1, listener.count);
assertTrue(listener.event.diff.getAddedKeys().contains(model3));
assertEquals(model3.getValue(), map.get(model3));
String newValue = model3.getValue() + model3.getValue();
model3.setValue(newValue);
assertEquals(2, listener.count);
assertEquals(3, map.size());
}
use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanPropertyObservableMapTest 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
Bean bean = new AnnoyingBean();
bean.setMap(Collections.singletonMap("key", "old"));
IObservableMap map = BeansObservables.observeMap(new CurrentRealm(true), bean, "map");
MapChangeEventTracker tracker = MapChangeEventTracker.observe(map);
bean.setMap(Collections.singletonMap("key", "new"));
assertEquals(1, tracker.count);
assertEquals(Collections.EMPTY_SET, tracker.event.diff.getAddedKeys());
assertEquals(Collections.singleton("key"), tracker.event.diff.getChangedKeys());
assertEquals(Collections.EMPTY_SET, tracker.event.diff.getRemovedKeys());
assertEquals("old", tracker.event.diff.getOldValue("key"));
assertEquals("new", tracker.event.diff.getNewValue("key"));
}
use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testDetailObservableChangeEvent.
@Test
public void testDetailObservableChangeEvent() {
WritableSet masterKeySet = new WritableSet();
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
MapChangeEventTracker changeTracker = MapChangeEventTracker.observe(sdom);
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.
masterKeySet.add(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));
}
use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class CompositeMapTest method testChangeInFirstMap.
@Test
public void testChangeInFirstMap() {
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(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(42), tracker.event.diff.getOldValue(person1));
assertEquals(Integer.valueOf(0), tracker.event.diff.getNewValue(person1));
assertEquals(Integer.valueOf(0), composedMap.get(person1));
}
use of org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class CompositeMapTest method testRemoveFromFirstMap.
@Test
public void testRemoveFromFirstMap() {
MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
SimplePerson newPerson = new SimplePerson("p1", "a1", "c1", "s1");
newPerson.getCart().setNumItems(42);
persons.add(newPerson);
assertTrue("newPerson should be added", composedMap.containsKey(newPerson));
composedMap.addMapChangeListener(tracker);
assertEquals(0, tracker.count);
persons.remove(newPerson);
assertEquals(1, tracker.count);
assertEquals(0, tracker.event.diff.getAddedKeys().size());
assertEquals(0, tracker.event.diff.getChangedKeys().size());
assertEquals(Collections.singleton(newPerson), tracker.event.diff.getRemovedKeys());
assertEquals(Integer.valueOf(42), tracker.event.diff.getOldValue(newPerson));
assertFalse("newPerson should be removed", composedMap.containsKey(newPerson));
}
Aggregations