use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap in project eclipse.platform.ui by eclipse-platform.
the class MapDetailValueObservableMapTest method testContainsValue.
@Test
public void testContainsValue() {
WritableMap masterMap = new WritableMap();
MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
// Add a person with a given name.
SimplePerson person = new SimplePerson();
person.setName("name");
masterMap.put(person, person);
// Make sure the name of the person is contained.
assertTrue(mdom.containsValue(person.getName()));
// Remove the person and make sure that it's name cannot be found
// anymore.
masterMap.remove(person);
assertFalse(mdom.containsValue(person.getName()));
}
use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap 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));
}
use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap in project eclipse.platform.ui by eclipse-platform.
the class MapDetailValueObservableMapTest method testGetKeyType.
@Test
public void testGetKeyType() {
MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(new WritableMap(SimplePerson.class, SimplePerson.class), BeansObservables.valueFactory("name"), String.class);
assertSame(SimplePerson.class, mdom.getKeyType());
}
use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap in project eclipse.platform.ui by eclipse-platform.
the class MapDetailValueObservableMapTest method testAddRemove.
@Test
public void testAddRemove() {
WritableMap masterMap = new WritableMap();
MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
// Initially, the detail map is empty.
assertTrue(mdom.isEmpty());
// Add a first person and check that its name is in the detail map.
SimplePerson p1 = new SimplePerson();
p1.setName("name1");
masterMap.put(p1, p1);
assertEquals(masterMap.size(), mdom.size());
assertEquals(p1.getName(), mdom.get(p1));
// Add a second person and check that it's name is in the detail map.
SimplePerson p2 = new SimplePerson();
p2.setName("name2");
masterMap.put(p2, p2);
assertEquals(masterMap.size(), mdom.size());
assertEquals(p2.getName(), mdom.get(p2));
// Remove the first person from the master map and check that we still
// have the name of the second person in the detail map.
masterMap.remove(p1);
assertEquals(masterMap.size(), mdom.size());
assertEquals(p2.getName(), mdom.get(p2));
// Remove the second person as well.
masterMap.remove(p2);
assertTrue(mdom.isEmpty());
}
use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap in project eclipse.platform.ui by eclipse-platform.
the class MapDetailValueObservableMapTest method testRemove.
@Test
public void testRemove() {
WritableMap masterMap = new WritableMap();
MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
// Add two person objects to the map.
SimplePerson p1 = new SimplePerson();
SimplePerson p2 = new SimplePerson();
masterMap.put(p1, p1);
masterMap.put(p2, p2);
// Initially, both person objects should be contained in the detail map.
assertTrue(mdom.containsKey(p1));
assertTrue(mdom.containsKey(p2));
// Remove one person and check that it is not contained anymore.
mdom.remove(p1);
assertFalse(mdom.containsKey(p1));
assertTrue(mdom.containsKey(p2));
// Trying to remove a non-existent is allowed but has no effect.
mdom.remove(p1);
assertFalse(mdom.containsKey(p1));
assertTrue(mdom.containsKey(p2));
}
Aggregations