Search in sources :

Example 1 with ListChangeEventTracker

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

the class MutableObservableListContractTest method testMove_NoChangeEventAtSameIndex.

@Test
public void testMove_NoChangeEventAtSameIndex() throws Exception {
    Object element = delegate.createElement(list);
    list.add(element);
    ListChangeEventTracker tracker = ListChangeEventTracker.observe(list);
    final Object movedElement = list.move(0, 0);
    assertEquals(formatFail("IObservableList.move(int,int) should return the moved element"), element, movedElement);
    assertEquals(formatFail("IObservableLIst.move(int,int) should not fire a change event" + "when the old and new indices are the same"), 0, tracker.count);
}
Also used : ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) Test(org.junit.Test)

Example 2 with ListChangeEventTracker

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

the class ListDetailValueObservableListTest method testDuplicateMasterElements.

@Test
public void testDuplicateMasterElements() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    SimplePerson master = new SimplePerson();
    master.setName("name1");
    // Add the same master twice.
    masterList.add(master);
    masterList.add(master);
    // Attach the change listener to the detail list.
    ListChangeEventTracker changeTracker = ListChangeEventTracker.observe(ldol);
    // Setting the name on master should trigger an event on both
    // occurrences of in the master list.
    master.setName("name2");
    // We should have 2 replace diffs, i.e. 4 diff entries.
    assertEquals(1, changeTracker.count);
    assertEquals(4, changeTracker.event.diff.getDifferences().length);
    assertReplaceDiffAt(changeTracker.event.diff, 0, 0, "name1", "name2");
    assertReplaceDiffAt(changeTracker.event.diff, 2, 0, "name1", "name2");
    // Remove one instance of the master (one will remain).
    masterList.remove(master);
    // It should still be possible to work on the remaining master instance.
    ldol.set(0, "name3");
    assertEquals("name3", master.getName());
}
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 3 with ListChangeEventTracker

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

the class JavaBeanObservableListTest method testRegistersListenerAfterFirstListenerIsAdded.

@Test
public void testRegistersListenerAfterFirstListenerIsAdded() throws Exception {
    assertFalse(bean.changeSupport.hasListeners(propertyName));
    list.addListChangeListener(new ListChangeEventTracker());
    assertTrue(bean.changeSupport.hasListeners(propertyName));
}
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 4 with ListChangeEventTracker

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

the class JavaBeanObservableListTest method testRemoveAtIndexListChangeEvent.

@Test
public void testRemoveAtIndexListChangeEvent() throws Exception {
    String element = "1";
    list.add(element);
    assertEquals(1, list.size());
    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);
    list.remove(0);
    assertEquals(1, listener.count);
    ListChangeEvent event = listener.event;
    assertSame(list, event.getObservableList());
    assertDiff(event.diff, Collections.singletonList(element), Collections.EMPTY_LIST);
}
Also used : ListChangeEvent(org.eclipse.core.databinding.observable.list.ListChangeEvent) 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 5 with ListChangeEventTracker

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

the class JavaBeanObservableListTest 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.setList(Collections.singletonList("old"));
    IObservableList observable = BeansObservables.observeList(new CurrentRealm(true), bean, "list");
    ListChangeEventTracker tracker = ListChangeEventTracker.observe(observable);
    bean.setList(Collections.singletonList("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)

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