use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableValueTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.
@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
Bean bean = new Bean("old");
CurrentRealm realm = new CurrentRealm(true);
IObservableValue observable = BeansObservables.observeValue(realm, bean, "value");
ValueChangeEventTracker tracker = ValueChangeEventTracker.observe(observable);
realm.setCurrent(false);
bean.setValue("new");
assertEquals(0, tracker.count);
realm.setCurrent(true);
assertEquals(1, tracker.count);
assertEquals(Diffs.createValueDiff("old", "new"), tracker.event.diff);
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanPropertyObservableMapTest method testSetBeanProperty_CorrectForNullOldAndNewValues.
@Test
public void testSetBeanProperty_CorrectForNullOldAndNewValues() {
// The java bean spec allows the old and new values in a
// PropertyChangeEvent to be null, which indicates that an unknown
// change occured.
// This test ensures that JavaBeanObservableValue fires the correct
// value diff even if the bean implementor is lazy :-P
Bean bean = new AnnoyingBean();
bean.setMap(Collections.singletonMap("key", "old"));
IObservableMap map = BeansObservables.observeMap(new CurrentRealm(true), bean, "map");
MapChangeEventTracker tracker = MapChangeEventTracker.observe(map);
bean.setMap(Collections.singletonMap("key", "new"));
assertEquals(1, tracker.count);
assertEquals(Collections.EMPTY_SET, tracker.event.diff.getAddedKeys());
assertEquals(Collections.singleton("key"), tracker.event.diff.getChangedKeys());
assertEquals(Collections.EMPTY_SET, tracker.event.diff.getRemovedKeys());
assertEquals("old", tracker.event.diff.getOldValue("key"));
assertEquals("new", tracker.event.diff.getNewValue("key"));
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class BeanValuePropertyTest method testChangeListenerIsOnlyNotifiedWhenWatchedPropertyChanges.
@Test
public void testChangeListenerIsOnlyNotifiedWhenWatchedPropertyChanges() throws Exception {
GenericListenerBean bean = new GenericListenerBean();
IValueProperty property = BeanProperties.value(GenericListenerBean.class, "value");
class Listener implements IValueChangeListener {
private int count = 0;
@Override
public void handleValueChange(ValueChangeEvent event) {
count++;
}
}
Listener listener = new Listener();
IObservableValue observable = property.observe(new CurrentRealm(true), bean);
observable.addValueChangeListener(listener);
assertEquals(0, listener.count);
bean.setValue("1");
assertEquals(1, listener.count);
bean.setOther("2");
assertEquals(1, listener.count);
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableArrayBasedListTest method testSetBeanProperty_CorrectForNullOldAndNewValues.
@Test
public void testSetBeanProperty_CorrectForNullOldAndNewValues() {
// The java bean spec allows the old and new values in a
// PropertyChangeEvent to be null, which indicates that an unknown
// change occured.
// This test ensures that JavaBeanObservableValue fires the correct
// value diff even if the bean implementor is lazy :-P
Bean bean = new AnnoyingBean();
bean.setArray(new Object[] { "old" });
IObservableList observable = BeansObservables.observeList(new CurrentRealm(true), bean, "array");
ListChangeEventTracker tracker = ListChangeEventTracker.observe(observable);
bean.setArray(new Object[] { "new" });
assertEquals(1, tracker.count);
List list = new ArrayList();
list.add("old");
tracker.event.diff.applyTo(list);
assertEquals(Collections.singletonList("new"), list);
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableArrayBasedListTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.
@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
Bean bean = new Bean(new Object[0]);
CurrentRealm realm = new CurrentRealm(true);
IObservableList observable = BeansObservables.observeList(realm, bean, "array");
ListChangeEventTracker tracker = ListChangeEventTracker.observe(observable);
realm.setCurrent(false);
bean.setArray(new Object[] { "element" });
assertEquals(0, tracker.count);
realm.setCurrent(true);
assertEquals(1, tracker.count);
assertDiff(tracker.event.diff, Collections.EMPTY_LIST, Collections.singletonList("element"));
}
Aggregations