Search in sources :

Example 21 with CurrentRealm

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);
}
Also used : ValueChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) MutableObservableValueContractTest(org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest) Test(org.junit.Test)

Example 22 with CurrentRealm

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"));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 23 with CurrentRealm

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);
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) GenericListenerBean(org.eclipse.core.tests.internal.databinding.beans.BeanPropertyListenerSupportTest.GenericListenerBean) IValueProperty(org.eclipse.core.databinding.property.value.IValueProperty) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 24 with CurrentRealm

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);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Example 25 with CurrentRealm

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"));
}
Also used : CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Aggregations

CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)39 Test (org.junit.Test)35 MutableObservableListContractTest (org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)10 ObservableListContractTest (org.eclipse.jface.databinding.conformance.ObservableListContractTest)10 ArrayList (java.util.ArrayList)7 Realm (org.eclipse.core.databinding.observable.Realm)6 WritableList (org.eclipse.core.databinding.observable.list.WritableList)6 IObservableMap (org.eclipse.core.databinding.observable.map.IObservableMap)5 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)4 IObservableSet (org.eclipse.core.databinding.observable.set.IObservableSet)4 MutableObservableSetContractTest (org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)4 ListChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker)4 SetChangeEventTracker (org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker)4 Before (org.junit.Before)4 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)3 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)3 MapChangeEventTracker (org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker)3 List (java.util.List)2 IObservable (org.eclipse.core.databinding.observable.IObservable)2 AssertionFailedException (org.eclipse.core.runtime.AssertionFailedException)2