Search in sources :

Example 16 with SetChangeEventTracker

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

the class JavaBeanObservableArrayBasedSetTest method testRemove_SetChangeEvent.

@Test
public void testRemove_SetChangeEvent() throws Exception {
    String element = "1";
    set.add(element);
    assertEquals(1, set.size());
    SetChangeEventTracker listener = SetChangeEventTracker.observe(set);
    assertEquals(0, listener.count);
    set.remove(element);
    assertEquals(1, listener.count);
    SetChangeEvent event = listener.event;
    assertEquals(set, event.getObservableSet());
    assertEquals(Collections.singleton(element), event.diff.getRemovals());
    assertEquals(Collections.EMPTY_SET, event.diff.getAdditions());
}
Also used : SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) SetChangeEvent(org.eclipse.core.databinding.observable.set.SetChangeEvent) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Example 17 with SetChangeEventTracker

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

the class JavaBeanObservableArrayBasedSetTest method testRetainAll_SetChangeEvent.

@Test
public void testRetainAll_SetChangeEvent() throws Exception {
    set.addAll(Arrays.asList(new String[] { "0", "1", "2", "3" }));
    SetChangeEventTracker listener = SetChangeEventTracker.observe(set);
    assertEquals(0, listener.count);
    set.retainAll(Arrays.asList(new String[] { "0", "1" }));
    assertEquals(1, listener.count);
    SetChangeEvent event = listener.event;
    assertEquals(set, event.getObservableSet());
    assertEquals(Collections.EMPTY_SET, event.diff.getAdditions());
    assertEquals(new HashSet(Arrays.asList(new String[] { "2", "3" })), event.diff.getRemovals());
}
Also used : 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 18 with SetChangeEventTracker

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

the class JavaBeanObservableArrayBasedSetTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.

@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
    Bean bean = new Bean(new Object[0]);
    CurrentRealm realm = new CurrentRealm(true);
    IObservableSet observable = BeansObservables.observeSet(realm, bean, "array");
    SetChangeEventTracker tracker = SetChangeEventTracker.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_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 19 with SetChangeEventTracker

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

the class JavaBeanObservableArrayBasedSetTest method testRemovesListenerAfterLastListenerIsRemoved.

@Test
public void testRemovesListenerAfterLastListenerIsRemoved() throws Exception {
    SetChangeEventTracker listener = SetChangeEventTracker.observe(set);
    assertTrue(bean.changeSupport.hasListeners(propertyName));
    set.removeSetChangeListener(listener);
    assertFalse(bean.changeSupport.hasListeners(propertyName));
}
Also used : SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Example 20 with SetChangeEventTracker

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

the class JavaBeanObservableArrayBasedSetTest method testAddAll_SetChangeEvent.

@Test
public void testAddAll_SetChangeEvent() throws Exception {
    Collection elements = Arrays.asList(new String[] { "1", "2" });
    assertEquals(0, set.size());
    SetChangeEventTracker listener = SetChangeEventTracker.observe(set);
    assertEquals(0, listener.count);
    set.addAll(elements);
    assertEquals(1, listener.count);
    SetChangeEvent event = listener.event;
    assertEquals(set, event.getObservableSet());
    assertEquals(new HashSet(elements), event.diff.getAdditions());
    assertEquals(Collections.EMPTY_SET, 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)

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