Search in sources :

Example 1 with SetChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class ComputedSetTest method testDependency_SetChangeEventFiresOnlyWhenNotDirty.

@Test
public void testDependency_SetChangeEventFiresOnlyWhenNotDirty() {
    SetChangeEventTracker tracker = SetChangeEventTracker.observe(set);
    set.dependency.fireChange();
    assertEquals("ComputedSet should fire set change event when its dependency changes", 1, tracker.count);
    set.dependency.fireChange();
    assertEquals("ComputedSet should not fire set change events when dirty", 1, tracker.count);
    // Force set to recompute.
    set.size();
    set.dependency.fireChange();
    assertEquals("ComputedSet should fire set change event when its dependency changes", 2, tracker.count);
}
Also used : SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) ObservableCollectionContractTest(org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest)

Example 2 with SetChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableSetTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.

@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
    Bean bean = new Bean(Collections.EMPTY_SET);
    CurrentRealm realm = new CurrentRealm(true);
    IObservableSet observable = BeansObservables.observeSet(realm, bean, "set");
    SetChangeEventTracker tracker = SetChangeEventTracker.observe(observable);
    realm.setCurrent(false);
    bean.setSet(Collections.singleton("element"));
    assertEquals(0, tracker.count);
    realm.setCurrent(true);
    assertEquals(1, tracker.count);
    assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections.singleton("element"));
}
Also used : IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Example 3 with SetChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableSetTest method testModifyObservableSet_FiresSetChange.

@Test
public void testModifyObservableSet_FiresSetChange() {
    Bean bean = new Bean(new HashSet());
    IObservableSet observable = BeansObservables.observeSet(bean, "set");
    SetChangeEventTracker tracker = SetChangeEventTracker.observe(observable);
    Object element = new Object();
    observable.add(element);
    assertEquals(1, tracker.count);
    assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections.singleton(element));
}
Also used : IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) HashSet(java.util.HashSet) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Example 4 with SetChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableArrayBasedSetTest method testRemoveAll_SetChangeEvent.

@Test
public void testRemoveAll_SetChangeEvent() throws Exception {
    Collection elements = Arrays.asList(new String[] { "1", "2" });
    set.addAll(elements);
    SetChangeEventTracker listener = SetChangeEventTracker.observe(set);
    assertEquals(0, listener.count);
    set.removeAll(elements);
    SetChangeEvent event = listener.event;
    assertEquals(set, event.getObservableSet());
    assertEquals(Collections.EMPTY_SET, event.diff.getAdditions());
    assertEquals(new HashSet(elements), event.diff.getRemovals());
}
Also used : Collection(java.util.Collection) TestCollection(org.eclipse.jface.databinding.conformance.util.TestCollection) IObservableCollection(org.eclipse.core.databinding.observable.IObservableCollection) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) SetChangeEvent(org.eclipse.core.databinding.observable.set.SetChangeEvent) HashSet(java.util.HashSet) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Example 5 with SetChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableArrayBasedSetTest method testModifyObservableSet_FiresSetChange.

@Test
public void testModifyObservableSet_FiresSetChange() {
    Bean bean = new Bean(new Object[] {});
    IObservableSet observable = BeansObservables.observeSet(bean, "array");
    SetChangeEventTracker tracker = SetChangeEventTracker.observe(observable);
    observable.add("new");
    assertEquals(1, tracker.count);
    assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections.singleton("new"));
}
Also used : IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Aggregations

SetChangeEventTracker (org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker)21 Test (org.junit.Test)17 MutableObservableSetContractTest (org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)15 IObservableSet (org.eclipse.core.databinding.observable.set.IObservableSet)8 SetChangeEvent (org.eclipse.core.databinding.observable.set.SetChangeEvent)5 HashSet (java.util.HashSet)4 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)4 Collection (java.util.Collection)2 Set (java.util.Set)2 IObservableCollection (org.eclipse.core.databinding.observable.IObservableCollection)2 ObservableCollectionContractTest (org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest)2 TestCollection (org.eclipse.jface.databinding.conformance.util.TestCollection)2 ArrayList (java.util.ArrayList)1 IObservablesListener (org.eclipse.core.databinding.observable.IObservablesListener)1 ChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ChangeEventTracker)1 Before (org.junit.Before)1