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" }));
}
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());
}
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);
}
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");
}
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"));
}
Aggregations