Search in sources :

Example 26 with ListChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker 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 27 with ListChangeEventTracker

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

the class JavaBeanObservableArrayBasedListTest method testRetainAllListChangeEvent.

@Test
public void testRetainAllListChangeEvent() throws Exception {
    List elements = Arrays.asList(new String[] { "0", "1", "2", "3" });
    list.addAll(elements);
    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);
    assertEquals(0, listener.count);
    list.retainAll(elements.subList(0, 2));
    assertEquals(1, listener.count);
    ListChangeEvent event = listener.event;
    assertSame(list, event.getObservableList());
    assertDiff(event.diff, Arrays.asList(new Object[] { "0", "1", "2", "3" }), Arrays.asList(new Object[] { "0", "1" }));
}
Also used : ListChangeEvent(org.eclipse.core.databinding.observable.list.ListChangeEvent) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Example 28 with ListChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker 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)

Example 29 with ListChangeEventTracker

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

the class JavaBeanObservableArrayBasedListTest method testListChangeEventFiresWhenNewListIsSet.

@Test
public void testListChangeEventFiresWhenNewListIsSet() throws Exception {
    Bean[] elements = new Bean[] { new Bean(), new Bean() };
    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);
    assertEquals(0, listener.count);
    bean.setArray(elements);
    assertEquals(1, listener.count);
}
Also used : ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Example 30 with ListChangeEventTracker

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

the class JavaBeanObservableArrayBasedListTest method testAddAllListChangEvent.

@Test
public void testAddAllListChangEvent() throws Exception {
    List elements = Arrays.asList(new String[] { "1", "2" });
    assertEquals(0, list.size());
    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);
    assertEquals(0, listener.count);
    list.addAll(elements);
    assertEquals(1, listener.count);
    ListChangeEvent event = listener.event;
    assertSame(list, event.getObservableList());
    assertDiff(event.diff, Collections.EMPTY_LIST, Arrays.asList(new String[] { "1", "2" }));
}
Also used : ListChangeEvent(org.eclipse.core.databinding.observable.list.ListChangeEvent) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Aggregations

ListChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker)37 Test (org.junit.Test)36 ObservableListContractTest (org.eclipse.jface.databinding.conformance.ObservableListContractTest)35 MutableObservableListContractTest (org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)32 ListChangeEvent (org.eclipse.core.databinding.observable.list.ListChangeEvent)18 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)16 ArrayList (java.util.ArrayList)13 List (java.util.List)12 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)4 WritableList (org.eclipse.core.databinding.observable.list.WritableList)2 ListDetailValueObservableList (org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList)2 SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)2 IObservablesListener (org.eclipse.core.databinding.observable.IObservablesListener)1 ListDiff (org.eclipse.core.databinding.observable.list.ListDiff)1 ListDiffEntry (org.eclipse.core.databinding.observable.list.ListDiffEntry)1 ChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ChangeEventTracker)1