diff options
author | Nigel Westbury | 2013-07-24 16:50:29 +0000 |
---|---|---|
committer | Nigel Westbury | 2013-07-24 16:50:29 +0000 |
commit | 170ed5d0975b07f58c9f5b0eb21963083b64034a (patch) | |
tree | 00ee07acfb94eea36589dcd1b26fdc76dff91f7d | |
parent | 8f92cbd0d0c95606d6f8a7e60c5f525ecc6a7eaf (diff) | |
download | org.eclipse.e4.databinding-170ed5d0975b07f58c9f5b0eb21963083b64034a.tar.gz org.eclipse.e4.databinding-170ed5d0975b07f58c9f5b0eb21963083b64034a.tar.xz org.eclipse.e4.databinding-170ed5d0975b07f58c9f5b0eb21963083b64034a.zip |
bug 389394 - fix incorrect index in diff entries for removeAllI20131015-2200I20131014-2200I20131013-2200I20131012-2200I20131011-2200I20131011-0930I20131010-2200I20131009-2200I20131008-2200I20131007-2200I20131006-2200I20131005-2200I20131004-2200I20131004-0930I20131003-2200I20131002-2200I20131001-2200I20130930-2200I20130929-2200I20130928-2200I20130927-2200I20130927-0930I20130926-2200I20130925-2200I20130924-2200I20130923-2200I20130922-2200I20130921-2200I20130920-2200I20130920-0930I20130919-2200I20130918-2200I20130917-2200I20130916-2200I20130915-2200I20130914-2200I20130913-2200I20130913-0930I20130912-2200I20130912-0900I20130911-2200I20130910-2200I20130909-2200I20130908-2200I20130906-2200I20130906-1230I20130905-2200I20130904-2200I20130904-0900I20130903-2200I20130902-2200I20130901-2200I20130831-2200I20130830-2200I20130829-2200I20130828-2200I20130828-0900I20130827-2200I20130826-2200I20130825-2200I20130824-2200I20130823-2200I20130822-2200I20130821-2200I20130821-0900I20130820-2200I20130819-2200I20130818-2200I20130817-2200I20130816-2200I20130815-2200I20130814-2200I20130814-0900I20130813-2200I20130812-2200I20130811-2200I20130810-2200I20130809-2200I20130808-2200I20130807-2200I20130807-0900I20130806-2200I20130805-2200I20130804-2200I20130803-2200I20130802-2200I20130801-2200I20130731-2200I20130731-0900I20130730-2200I20130729-2200I20130728-2200I20130727-2200I20130726-2200I20130725-2200I20130724-2200
2 files changed, 51 insertions, 3 deletions
diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/WritableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/WritableList.java index d5d41d81..64d2639b 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/WritableList.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/WritableList.java @@ -13,7 +13,7 @@ * Sebastian Fuchs <spacehorst@gmail.com> - bug 243848 * Matthew Hall - bugs 208858, 213145, 243848, 208434 * Ovidio Mallo - bug 332367 - * Nigel Westbury - bug 335792 + * Nigel Westbury - bug 335792, 389394 *******************************************************************************/ package org.eclipse.core.databinding.observable.list; @@ -305,17 +305,29 @@ public class WritableList<E> extends ObservableList<E> { public boolean removeAll(Collection<?> c) { checkRealm(); + + /* + * First build the list of diff entries. All diff entries must be built + * before anything is removed from wrappedList, otherwise the indexes + * are incorrect. + */ List<ListDiffEntry<E>> entries = new ArrayList<ListDiffEntry<E>>(); for (Iterator<?> it = c.iterator(); it.hasNext();) { Object element = it.next(); int removeIndex = wrappedList.indexOf(element); if (removeIndex != -1) { E removedElement = wrappedList.get(removeIndex); - wrappedList.remove(removeIndex); entries.add(Diffs.createListDiffEntry(removeIndex, false, removedElement)); } } + + /* + * Now we have created all the diff entries with the correct indexes, we + * can remove the elements from wrappedList. + */ + wrappedList.removeAll(c); + if (entries.size() > 0) fireListChange(Diffs.createListDiff(entries)); return entries.size() > 0; diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java index 2fec7c5e..9c1a6cca 100755 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java @@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation * Brad Reynolds - bug 164653, 147515 * Matthew Hall - bug 213145 - * Nigel Westbury - bug 208434 + * Nigel Westbury - bug 208434, 389394 *******************************************************************************/ package org.eclipse.core.tests.databinding.observable.list; @@ -28,6 +28,9 @@ import junit.framework.TestSuite; import org.eclipse.core.databinding.observable.IObservable; import org.eclipse.core.databinding.observable.IObservableCollection; import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.list.IListChangeListener; +import org.eclipse.core.databinding.observable.list.ListChangeEvent; +import org.eclipse.core.databinding.observable.list.ListDiffEntry; import org.eclipse.core.databinding.observable.list.WritableList; import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; @@ -205,6 +208,39 @@ public class WritableListTest extends TestCase { assertEquals(2, wlist.size()); } + public void testRemoveAll() { + RealmTester.setDefault(new CurrentRealm(true)); + List<String> list = new ArrayList<String>(Arrays.asList(new String[] { + "a", "b", "c" })); + WritableList<String> wlist = new WritableList<String>(list, + String.class); + + final boolean[] flags = new boolean[wlist.size()]; + + wlist.addListChangeListener(new IListChangeListener<String>() { + public void handleListChange(ListChangeEvent<String> event) { + for (ListDiffEntry<String> diffEntry : event.diff + .getDifferencesAsList()) { + if (flags[diffEntry.getPosition()]) { + throw new RuntimeException("duplicate index in diff"); + } + flags[diffEntry.getPosition()] = true; + } + + } + }); + + List<String> removalList = new ArrayList<String>( + Arrays.asList(new String[] { "a", "c" })); + + wlist.removeAll(removalList); + + assertEquals(true, flags[0]); + assertEquals(false, flags[1]); + assertEquals(true, flags[2]); + assertEquals(1, wlist.size()); + } + public void testIteratorRemoval() { RealmTester.setDefault(new CurrentRealm(true)); List<String> list = new ArrayList<String>(Arrays.asList(new String[] { |