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