Search in sources :

Example 21 with ListChangeEventTracker

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

the class JavaBeanObservableListTest 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)

Example 22 with ListChangeEventTracker

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

the class UnmodifiableObservableListTest method testFiresListChangeEvents.

@Test
public void testFiresListChangeEvents() throws Exception {
    ListChangeEventTracker mutableListener = new ListChangeEventTracker();
    ListChangeEventTracker unmodifiableListener = new ListChangeEventTracker();
    mutable.addListChangeListener(mutableListener);
    unmodifiable.addListChangeListener(unmodifiableListener);
    assertEquals(0, mutableListener.count);
    assertEquals(0, unmodifiableListener.count);
    String element = "3";
    mutable.add(element);
    assertEquals(1, mutableListener.count);
    assertEquals(mutable, mutableListener.event.getObservableList());
    assertEquals(1, mutableListener.event.diff.getDifferences().length);
    ListDiffEntry difference = mutableListener.event.diff.getDifferences()[0];
    assertEquals(element, difference.getElement());
    assertTrue(difference.isAddition());
    assertEquals(3, mutable.size());
    assertEquals(1, unmodifiableListener.count);
    assertEquals(unmodifiable, unmodifiableListener.event.getObservableList());
    assertEquals(1, unmodifiableListener.event.diff.getDifferences().length);
    difference = unmodifiableListener.event.diff.getDifferences()[0];
    assertEquals(element, difference.getElement());
    assertTrue(difference.isAddition());
    assertEquals(3, unmodifiable.size());
}
Also used : ListDiffEntry(org.eclipse.core.databinding.observable.list.ListDiffEntry) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 23 with ListChangeEventTracker

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

the class MutableObservableListContractTest method assertListChangeEventFired.

private void assertListChangeEventFired(Runnable runnable, String methodName, IObservableList list, List newList) {
    List oldList = new ArrayList(list);
    List<IObservablesListener> queue = new ArrayList<>();
    ListChangeEventTracker listListener = new ListChangeEventTracker(queue);
    ChangeEventTracker changeListener = new ChangeEventTracker(queue);
    list.addListChangeListener(listListener);
    list.addChangeListener(changeListener);
    runnable.run();
    assertEquals(formatFail(methodName + " should fire one ListChangeEvent."), 1, listListener.count);
    assertEquals(formatFail(methodName + "'s change event observable should be the created List."), list, listListener.event.getObservable());
    assertEquals(formatFail("Two notifications should have been received."), 2, queue.size());
    assertEquals("ChangeEvent of " + methodName + " should have fired before the ListChangeEvent.", changeListener, queue.get(0));
    assertEquals("ListChangeEvent of " + methodName + " should have fired after the ChangeEvent.", listListener, queue.get(1));
    assertEquals(formatFail(methodName + " did not leave observable list with the expected contents"), newList, list);
    ListDiff diff = listListener.event.diff;
    diff.applyTo(oldList);
    assertEquals(formatFail(methodName + " fired a diff which does not represent the expected list change"), newList, oldList);
}
Also used : IObservablesListener(org.eclipse.core.databinding.observable.IObservablesListener) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) ChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ChangeEventTracker) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List) ListDiff(org.eclipse.core.databinding.observable.list.ListDiff) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker)

Example 24 with ListChangeEventTracker

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

the class ListDetailValueObservableListTest method testDetailObservableChangeEvent.

@Test
public void testDetailObservableChangeEvent() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    ListChangeEventTracker changeTracker = ListChangeEventTracker.observe(ldol);
    SimplePerson person = new SimplePerson();
    person.setName("old name");
    // Initially, we should not have received any event.
    assertEquals(0, changeTracker.count);
    // Add the person and check that we receive an addition event on the
    // correct index and with the correct value.
    masterList.add(person);
    assertEquals(1, changeTracker.count);
    assertEquals(1, changeTracker.event.diff.getDifferences().length);
    assertTrue(changeTracker.event.diff.getDifferences()[0].isAddition());
    assertEquals(0, changeTracker.event.diff.getDifferences()[0].getPosition());
    assertEquals(person.getName(), changeTracker.event.diff.getDifferences()[0].getElement());
    // Change the detail property and check that we receive a replace event.
    person.setName("new name");
    assertEquals(2, changeTracker.count);
    assertIsSingleReplaceDiff(changeTracker.event.diff, 0, "old name", "new name");
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 25 with ListChangeEventTracker

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

the class JavaBeanObservableListTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.

@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
    Bean bean = new Bean(Collections.EMPTY_LIST);
    CurrentRealm realm = new CurrentRealm(true);
    IObservableList observable = BeansObservables.observeList(realm, bean, "list");
    ListChangeEventTracker tracker = ListChangeEventTracker.observe(observable);
    realm.setCurrent(false);
    bean.setList(Collections.singletonList("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

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