use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class MapDetailValueObservableMapTest method testMasterSetInitiallyNotEmpty.
@Test
public void testMasterSetInitiallyNotEmpty() {
WritableMap masterMap = new WritableMap();
SimplePerson person = new SimplePerson();
person.setName("name");
masterMap.put(person, person);
MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
// Make sure that a non-empty master key set is initialized correctly.
assertEquals(masterMap.size(), mdom.size());
assertEquals(person.getName(), mdom.get(person));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class MapDetailValueObservableMapTest method testPut.
@Test
public void testPut() {
WritableMap masterMap = new WritableMap();
MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
// Change the detail attribute explicitly.
SimplePerson person = new SimplePerson();
person.setName("name1");
masterMap.put(person, person);
assertEquals(person.getName(), mdom.get(person));
// Set a new name on the detail map.
mdom.put(person, "name2");
// Check that the name has been propagated to the master.
assertEquals("name2", person.getName());
assertEquals(person.getName(), mdom.get(person));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class MapDetailValueObservableMapTest method testChangeDetail.
@Test
public void testChangeDetail() {
WritableMap masterMap = new WritableMap();
MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
// Change the detail attribute explicitly.
SimplePerson p1 = new SimplePerson();
p1.setName("name1");
masterMap.put(p1, p1);
assertEquals(p1.getName(), mdom.get(p1));
p1.setName("name2");
assertEquals(p1.getName(), mdom.get(p1));
// Change the detail attribute by changing the master.
SimplePerson p2 = new SimplePerson();
p2.setName("name3");
masterMap.put(p1, p2);
assertEquals(p2.getName(), mdom.get(p1));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableValueTest method testBug198519.
@Test
public void testBug198519() {
final SimplePerson person = new SimplePerson();
final ComputedValue cv = new ComputedValue() {
final IObservableValue name = BeansObservables.observeValue(person, // $NON-NLS-1$
"name");
@Override
protected Object calculate() {
return Boolean.valueOf(name.getValue() != null);
}
};
cv.addChangeListener(event -> cv.getValue());
person.setName("foo");
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class SetDetailValueObservableMapTest method testDetailObservableChangeEvent.
@Test
public void testDetailObservableChangeEvent() {
WritableSet masterKeySet = new WritableSet();
SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
MapChangeEventTracker changeTracker = MapChangeEventTracker.observe(sdom);
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.
masterKeySet.add(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