use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testAddRemove.
@Test
public void testAddRemove() {
WritableSet masterKeySet = new WritableSet();
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
// Initially, the detail map is empty.
assertTrue(sdom.isEmpty());
// Add a first person and check that its name is in the detail list.
SimplePerson p1 = new SimplePerson();
p1.setName("name1");
masterKeySet.add(p1);
assertEquals(masterKeySet.size(), sdom.size());
assertEquals(p1.getName(), sdom.get(p1));
// Add a second person and check that it's name is in the detail list.
SimplePerson p2 = new SimplePerson();
p2.setName("name2");
masterKeySet.add(p2);
assertEquals(masterKeySet.size(), sdom.size());
assertEquals(p2.getName(), sdom.get(p2));
// Remove the first person from the master list and check that we still
// have the name of the second person in the detail list.
masterKeySet.remove(p1);
assertEquals(masterKeySet.size(), sdom.size());
assertEquals(p2.getName(), sdom.get(p2));
// Remove the second person as well.
masterKeySet.remove(p2);
assertTrue(sdom.isEmpty());
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class PersonTests method testSetName.
@Test
public void testSetName() {
SimplePerson person = new SimplePerson();
Listener listener = new Listener();
person.addPropertyChangeListener(listener);
assertEquals(0, listener.count);
assertNull(listener.lastEvent);
// $NON-NLS-1$
person.setState("new state");
assertEquals(1, listener.count);
assertNotNull(listener.lastEvent);
// $NON-NLS-1$
assertEquals("state", listener.lastEvent.getPropertyName());
assertEquals("", listener.lastEvent.getOldValue());
// $NON-NLS-1$
assertEquals("new state", listener.lastEvent.getNewValue());
assertEquals("new state", person.getState());
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class ListDetailValueObservableListTest method testDetailObservableChangeEvent.
@Test
public void testDetailObservableChangeEvent() {
WritableList masterList = new WritableList();
ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
ListChangeEventTracker changeTracker = ListChangeEventTracker.observe(ldol);
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.
masterList.add(person);
assertEquals(1, changeTracker.count);
assertEquals(1, changeTracker.event.diff.getDifferences().length);
assertTrue(changeTracker.event.diff.getDifferences()[0].isAddition());
assertEquals(0, changeTracker.event.diff.getDifferences()[0].getPosition());
assertEquals(person.getName(), changeTracker.event.diff.getDifferences()[0].getElement());
// Change the detail property and check that we receive a replace event.
person.setName("new name");
assertEquals(2, changeTracker.count);
assertIsSingleReplaceDiff(changeTracker.event.diff, 0, "old name", "new name");
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class ListDetailValueObservableListTest method testChangeDetail.
@Test
public void testChangeDetail() {
WritableList masterList = new WritableList();
ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
// Change the detail attribute explicitly.
SimplePerson p1 = new SimplePerson();
p1.setName("name1");
masterList.add(p1);
assertEquals(p1.getName(), ldol.get(0));
p1.setName("name2");
assertEquals(p1.getName(), ldol.get(0));
// Change the detail attribute by changing the master.
SimplePerson p2 = new SimplePerson();
p2.setName("name3");
masterList.set(0, p2);
assertEquals(p2.getName(), ldol.get(0));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class ListDetailValueObservableListTest method testSet.
@Test
public void testSet() {
WritableList masterList = new WritableList();
ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
// Change the detail attribute explicitly.
SimplePerson person = new SimplePerson();
person.setName("name1");
masterList.add(person);
assertEquals(person.getName(), ldol.get(0));
// Set a new name on the detail list.
ldol.set(0, "name2");
// Check that the name has been propagated to the master.
assertEquals("name2", person.getName());
assertEquals(person.getName(), ldol.get(0));
}
Aggregations