use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testChangeDetail.
@Test
public void testChangeDetail() {
WritableSet masterKeySet = new WritableSet();
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
// Change the detail attribute explicitly.
SimplePerson p1 = new SimplePerson();
p1.setName("name1");
masterKeySet.add(p1);
assertEquals(p1.getName(), sdom.get(p1));
p1.setName("name2");
assertEquals(p1.getName(), sdom.get(p1));
// Change the detail attribute by changing the master.
SimplePerson p2 = new SimplePerson();
p2.setName("name3");
masterKeySet.add(p2);
assertEquals(p2.getName(), sdom.get(p2));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testRemove.
@Test
public void testRemove() {
WritableSet masterKeySet = new WritableSet();
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
// Add two person objects to the map.
SimplePerson p1 = new SimplePerson();
SimplePerson p2 = new SimplePerson();
masterKeySet.add(p1);
masterKeySet.add(p2);
// Initially, both person objects should be contained in the detail map.
assertTrue(sdom.containsKey(p1));
assertTrue(sdom.containsKey(p2));
// Remove one person and check that it is not contained anymore.
sdom.remove(p1);
assertFalse(sdom.containsKey(p1));
assertTrue(sdom.containsKey(p2));
// Trying to remove a non-existent is allowed but has no effect.
sdom.remove(p1);
assertFalse(sdom.containsKey(p1));
assertTrue(sdom.containsKey(p2));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson 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.examples.databinding.model.SimplePerson 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));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson 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));
}
Aggregations