use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class ListDetailValueObservableListTest method testDuplicateMasterElements.
@Test
public void testDuplicateMasterElements() {
WritableList masterList = new WritableList();
ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
SimplePerson master = new SimplePerson();
master.setName("name1");
// Add the same master twice.
masterList.add(master);
masterList.add(master);
// Attach the change listener to the detail list.
ListChangeEventTracker changeTracker = ListChangeEventTracker.observe(ldol);
// Setting the name on master should trigger an event on both
// occurrences of in the master list.
master.setName("name2");
// We should have 2 replace diffs, i.e. 4 diff entries.
assertEquals(1, changeTracker.count);
assertEquals(4, changeTracker.event.diff.getDifferences().length);
assertReplaceDiffAt(changeTracker.event.diff, 0, 0, "name1", "name2");
assertReplaceDiffAt(changeTracker.event.diff, 2, 0, "name1", "name2");
// Remove one instance of the master (one will remain).
masterList.remove(master);
// It should still be possible to work on the remaining master instance.
ldol.set(0, "name3");
assertEquals("name3", master.getName());
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class ListDetailValueObservableListTest method testAddRemove.
@Test
public void testAddRemove() {
WritableList masterList = new WritableList();
ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
// Initially, the detail list is empty.
assertTrue(ldol.isEmpty());
// Add a first person and check that its name is in the detail list.
SimplePerson p1 = new SimplePerson();
p1.setName("name1");
masterList.add(p1);
assertEquals(masterList.size(), ldol.size());
assertEquals(p1.getName(), ldol.get(0));
// Add a second person and check that it's name is in the detail list.
SimplePerson p2 = new SimplePerson();
p2.setName("name2");
masterList.add(p2);
assertEquals(masterList.size(), ldol.size());
assertEquals(p2.getName(), ldol.get(1));
// Remove the first person from the master list and check that we still
// have the name of the second person in the detail list.
masterList.remove(0);
assertEquals(masterList.size(), ldol.size());
assertEquals(p2.getName(), ldol.get(0));
// Remove the second person as well.
masterList.remove(0);
assertTrue(ldol.isEmpty());
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class ListDetailValueObservableListTest method testMasterListInitiallyNotEmpty.
@Test
public void testMasterListInitiallyNotEmpty() {
WritableList masterList = new WritableList();
SimplePerson person = new SimplePerson();
person.setName("name");
masterList.add(person);
ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
// Make sure that a non-empty master list is initialized correctly.
assertEquals(masterList.size(), ldol.size());
assertEquals(person.getName(), ldol.get(0));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson 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.jface.examples.databinding.model.SimplePerson 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));
}
Aggregations