use of org.eclipse.jface.examples.databinding.model.SimplePerson 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.jface.examples.databinding.model.SimplePerson 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));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testContainsValue.
@Test
public void testContainsValue() {
WritableSet masterKeySet = new WritableSet();
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
// Add a person with a given name.
SimplePerson person = new SimplePerson();
person.setName("name");
masterKeySet.add(person);
// Make sure the name of the person is contained.
assertTrue(sdom.containsValue(person.getName()));
// Remove the person and make sure that it's name cannot be found
// anymore.
masterKeySet.remove(person);
assertFalse(sdom.containsValue(person.getName()));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testMasterSetInitiallyNotEmpty.
@Test
public void testMasterSetInitiallyNotEmpty() {
WritableSet masterKeySet = new WritableSet();
SimplePerson person = new SimplePerson();
person.setName("name");
masterKeySet.add(person);
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
// Make sure that a non-empty master key set is initialized correctly.
assertEquals(masterKeySet.size(), sdom.size());
assertEquals(person.getName(), sdom.get(person));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testPut.
@Test
public void testPut() {
WritableSet masterKeySet = new WritableSet();
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
// Change the detail attribute explicitly.
SimplePerson person = new SimplePerson();
person.setName("name1");
masterKeySet.add(person);
assertEquals(person.getName(), sdom.get(person));
// Set a new name on the detail map.
sdom.put(person, "name2");
// Check that the name has been propagated to the master.
assertEquals("name2", person.getName());
assertEquals(person.getName(), sdom.get(person));
}
Aggregations