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