From 3d5c7a5dbb100aaed9b54bd4b0cb2fef96fdaa8e Mon Sep 17 00:00:00 2001 From: kmoore Date: Mon, 10 May 2010 21:47:11 +0000 Subject: 311112 - @Convert value can get unset - CompositeListValueModel listChanged events fixed by Brian --- .../jpt/ui/internal/swt/ComboModelAdapter.java | 2 - .../model/value/CompositeListValueModel.java | 155 +++++-- .../model/value/CompositeListValueModelTests.java | 468 +++++++++++++++++++-- 3 files changed, 547 insertions(+), 78 deletions(-) (limited to 'jpa') diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java index 3b79556550..d926c06cea 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java @@ -204,8 +204,6 @@ public class ComboModelAdapter extends AbstractComboModelAdapter { else { this.selectedItem = null; } - - this.combo.select(this.combo.indexOf(item)); this.combo.setText(item); } } diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CompositeListValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CompositeListValueModel.java index 07a13cdbbf..b454a0141d 100644 --- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CompositeListValueModel.java +++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CompositeListValueModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. + * Copyright (c) 2008, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -18,6 +18,7 @@ import org.eclipse.jpt.utility.internal.ArrayTools; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.jpt.utility.internal.Transformer; +import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable; import org.eclipse.jpt.utility.internal.iterators.ReadOnlyCompositeListIterator; import org.eclipse.jpt.utility.internal.iterators.TransformationListIterator; import org.eclipse.jpt.utility.model.event.ListAddEvent; @@ -68,7 +69,7 @@ public class CompositeListValueModel final ArrayList items; // the component LVM's beginning index within the composite LVM int begin; - Info(E1 source, ListValueModel componentLVM, ArrayList items, int begin) { + protected Info(E1 source, ListValueModel componentLVM, ArrayList items, int begin) { super(); this.source = source; this.componentLVM = componentLVM; @@ -232,7 +233,7 @@ public class CompositeListValueModel super.engageModel(); // synch our cache *after* we start listening to the wrapped list, // since its value might change when a listener is added - this.addComponentSources(0, this.listHolder, this.listHolder.size()); + this.addComponentSources(0, this.listHolder, this.listHolder.size(), false); // false = do not fire event } @Override @@ -255,13 +256,6 @@ public class CompositeListValueModel this.addComponentSources(event.getIndex(), this.getItems(event), event.getItemsSize(), true); // true = fire event } - /** - * Do not fire an event. - */ - protected void addComponentSources(int addedSourcesIndex, Iterable addedSources, int addedSourcesSize) { - this.addComponentSources(addedSourcesIndex, addedSources, addedSourcesSize, false); // false = do not fire event - } - /** * Add infos corresponding to the specified sources to our cache. * Fire the appropriate event if requested. @@ -308,13 +302,6 @@ public class CompositeListValueModel this.removeComponentSources(event.getIndex(), event.getItemsSize(), true); // true = fire event } - /** - * Do not fire an event. - */ - protected void removeComponentSources(int removedSourcesIndex, int removedSourcesSize) { - this.removeComponentSources(removedSourcesIndex, removedSourcesSize, false); // false = do not fire event - } - /** * Remove the infos corresponding to the specified sources from our cache. */ @@ -413,7 +400,11 @@ public class CompositeListValueModel */ @Override protected void listCleared(ListClearEvent event) { - this.removeComponentSources(0, this.infoList.size()); + this.clearComponentSources(); + } + + protected void clearComponentSources() { + this.removeComponentSources(0, this.infoList.size(), false); // false = do not fire event this.fireListCleared(LIST_VALUES); } @@ -422,9 +413,51 @@ public class CompositeListValueModel */ @Override protected void listChanged(ListChangeEvent event) { - this.removeComponentSources(0, this.infoList.size()); - this.addComponentSources(0, this.listHolder, this.listHolder.size()); - this.fireListChanged(LIST_VALUES, CollectionTools.list(this.listIterator())); + int newSize = this.listHolder.size(); + if (newSize == 0) { + this.clearComponentSources(); + return; + } + + int oldSize = this.infoList.size(); + if (oldSize == 0) { + this.addComponentSources(0, this.listHolder, newSize, true); // true = fire event + return; + } + + int min = Math.min(newSize, oldSize); + // handle replaced sources individually so we don't fire events for unchanged sources + for (int i = 0; i < min; i++) { + E1 newSource = this.listHolder.get(i); + E1 oldSource = this.infoList.get(i).source; + if (this.valuesAreDifferent(newSource, oldSource)) { + this.replaceComponentSources(i, new SingleElementIterable(newSource), 1, true); // true = fire event + } + } + + if (newSize == oldSize) { + return; + } + + if (newSize < oldSize) { + this.removeComponentSources(min, oldSize - newSize, true); // true = fire event + return; + } + + // newSize > oldSize + this.addComponentSources(min, this.buildSubListHolder(min), newSize - oldSize, true); // true = fire event + } + + protected Iterable buildSubListHolder(int fromIndex) { + int listHolderSize = this.listHolder.size(); + return CollectionTools.list(this.listHolder, listHolderSize).subList(fromIndex, listHolderSize); + } + + protected Iterable buildSubListHolder(int fromIndex, int toIndex) { + int listHolderSize = this.listHolder.size(); + return ((fromIndex == 0) && (toIndex == listHolderSize)) ? + this.listHolder : + CollectionTools.list(this.listHolder, listHolderSize).subList(fromIndex, toIndex); } @Override @@ -461,7 +494,7 @@ public class CompositeListValueModel * Return the index of the specified event's component LVM. */ protected int indexFor(ListEvent event) { - return this.indexOf(this.componentLVM(event)); + return this.indexOf(this.getComponentLVM(event)); } /** @@ -469,20 +502,22 @@ public class CompositeListValueModel * synchronize our cache. */ protected void componentItemsAdded(ListAddEvent event) { - // update the affected 'begin' indices int componentLVMIndex = this.indexFor(event); - int newItemsSize = event.getItemsSize(); + this.addComponentItems(componentLVMIndex, this.infoList.get(componentLVMIndex), event.getIndex(), this.getComponentItems(event), event.getItemsSize()); + } + + protected void addComponentItems(int componentLVMIndex, Info info, int addedItemsIndex, Iterable addedItems, int addedItemsSize) { + // update the affected 'begin' indices for (int i = componentLVMIndex + 1; i < this.infoList.size(); i++) { - this.infoList.get(i).begin += newItemsSize; + this.infoList.get(i).begin += addedItemsSize; } - this.size += newItemsSize; + this.size += addedItemsSize; // synchronize the cached list - Info info = this.infoList.get(componentLVMIndex); - CollectionTools.addAll(info.items, event.getIndex(), this.getComponentItems(event), event.getItemsSize()); + CollectionTools.addAll(info.items, addedItemsIndex, addedItems, addedItemsSize); // translate the event - this.fireItemsAdded(event.clone(this, LIST_VALUES, info.begin)); + this.fireItemsAdded(LIST_VALUES, info.begin + addedItemsIndex, info.items.subList(addedItemsIndex, addedItemsIndex + addedItemsSize)); } /** @@ -554,13 +589,17 @@ public class CompositeListValueModel protected void clearComponentList(int componentLVMIndex, Info info) { // update the affected 'begin' indices int removedItemsSize = info.items.size(); + if (removedItemsSize == 0) { + return; + } + for (int i = componentLVMIndex + 1; i < this.infoList.size(); i++) { this.infoList.get(i).begin -= removedItemsSize; } this.size -= removedItemsSize; // synchronize the cached list - ArrayList items = new ArrayList(info.items); + ArrayList items = new ArrayList(info.items); // make a copy info.items.clear(); // translate the event @@ -569,26 +608,58 @@ public class CompositeListValueModel /** * One of the component lists changed; - * synchronize our cache by clearing out the appropriate - * list and rebuilding it. + * synchronize our cache by synchronizing the appropriate + * list and firing the appropriate events. */ protected void componentListChanged(ListChangeEvent event) { int componentLVMIndex = this.indexFor(event); Info info = this.infoList.get(componentLVMIndex); - this.clearComponentList(componentLVMIndex, info); - // update the affected 'begin' indices int newItemsSize = info.componentLVM.size(); - for (int i = componentLVMIndex + 1; i < this.infoList.size(); i++) { - this.infoList.get(i).begin += newItemsSize; + if (newItemsSize == 0) { + this.clearComponentList(componentLVMIndex, info); + return; } - this.size += newItemsSize; - // synchronize the cached list - CollectionTools.addAll(info.items, info.componentLVM.listIterator(), newItemsSize); + int oldItemsSize = info.items.size(); + if (oldItemsSize == 0) { + this.addComponentItems(componentLVMIndex, info, 0, info.componentLVM, newItemsSize); + return; + } - // translate the event - this.fireItemsAdded(LIST_VALUES, info.begin, info.items); + int min = Math.min(newItemsSize, oldItemsSize); + // handle replaced items individually so we don't fire events for unchanged items + for (int i = 0; i < min; i++) { + E2 newItem = info.componentLVM.get(i); + E2 oldItem = info.items.set(i, newItem); + this.fireItemReplaced(LIST_VALUES, info.begin + i, newItem, oldItem); + } + + int delta = newItemsSize - oldItemsSize; + if (delta == 0) { // newItemsSize == oldItemsSize + return; + } + + for (int i = componentLVMIndex + 1; i < this.infoList.size(); i++) { + this.infoList.get(i).begin += delta; + } + this.size += delta; + + if (delta < 0) { // newItemsSize < oldItemsSize + List subList = info.items.subList(newItemsSize, oldItemsSize); + ArrayList removedItems = new ArrayList(subList); // make a copy + subList.clear(); + this.fireItemsRemoved(LIST_VALUES, info.begin + newItemsSize, removedItems); + return; + } + + // newItemsSize > oldItemsSize + ArrayList addedItems = new ArrayList(delta); + for (int i = oldItemsSize; i < newItemsSize; i++) { + addedItems.add(info.componentLVM.get(i)); + } + info.items.addAll(addedItems); + this.fireItemsAdded(LIST_VALUES, info.begin + oldItemsSize, addedItems); } // minimize scope of suppressed warnings @@ -605,7 +676,7 @@ public class CompositeListValueModel // minimize scope of suppressed warnings @SuppressWarnings("unchecked") - protected ListValueModel componentLVM(ListEvent event) { + protected ListValueModel getComponentLVM(ListEvent event) { return (ListValueModel) event.getSource(); } diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java index 3532f88f2f..06e7cde4a2 100644 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java +++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java @@ -14,20 +14,30 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; + import junit.framework.TestCase; + +import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; +import org.eclipse.jpt.utility.model.event.ListAddEvent; +import org.eclipse.jpt.utility.model.event.ListChangeEvent; +import org.eclipse.jpt.utility.model.event.ListClearEvent; +import org.eclipse.jpt.utility.model.event.ListMoveEvent; +import org.eclipse.jpt.utility.model.event.ListRemoveEvent; +import org.eclipse.jpt.utility.model.event.ListReplaceEvent; +import org.eclipse.jpt.utility.model.listener.ListChangeListener; import org.eclipse.jpt.utility.model.value.ListValueModel; import org.eclipse.jpt.utility.tests.internal.TestTools; @SuppressWarnings("nls") public class CompositeListValueModelTests extends TestCase { - private SimpleListValueModel lvm0; - private SimpleListValueModel lvm1; - private SimpleListValueModel lvm2; - private SimpleListValueModel lvm3; - private SimpleListValueModel> uberLVM; - private CompositeListValueModel, String> compositeLVM; + private LocalListValueModel lvm0; + private LocalListValueModel lvm1; + private LocalListValueModel lvm2; + private LocalListValueModel lvm3; + private LocalListValueModel> uberLVM; + private CompositeListValueModel, String> compositeLVM; public CompositeListValueModelTests(String name) { super(name); @@ -37,32 +47,32 @@ public class CompositeListValueModelTests extends TestCase { protected void setUp() throws Exception { super.setUp(); - this.lvm0 = new SimpleListValueModel(); + this.lvm0 = new LocalListValueModel(); this.lvm0.add("aaa"); this.lvm0.add("bbb"); this.lvm0.add("ccc"); - this.lvm1 = new SimpleListValueModel(); + this.lvm1 = new LocalListValueModel(); this.lvm1.add("ddd"); this.lvm1.add("eee"); - this.lvm2 = new SimpleListValueModel(); + this.lvm2 = new LocalListValueModel(); this.lvm2.add("fff"); - this.lvm3 = new SimpleListValueModel(); + this.lvm3 = new LocalListValueModel(); this.lvm3.add("ggg"); this.lvm3.add("hhh"); this.lvm3.add("iii"); this.lvm3.add("jjj"); this.lvm3.add("kkk"); - this.uberLVM = new SimpleListValueModel>(); + this.uberLVM = new LocalListValueModel>(); this.uberLVM.add(this.lvm0); this.uberLVM.add(this.lvm1); this.uberLVM.add(this.lvm2); this.uberLVM.add(this.lvm3); - this.compositeLVM = new CompositeListValueModel, String>((ListValueModel>) this.uberLVM); + this.compositeLVM = new CompositeListValueModel, String>((ListValueModel>) this.uberLVM); } @Override @@ -134,7 +144,7 @@ public class CompositeListValueModelTests extends TestCase { public void testAddSource_Begin() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); - SimpleListValueModel lvm = new SimpleListValueModel(); + LocalListValueModel lvm = new LocalListValueModel(); lvm.add("xxx"); lvm.add("yyy"); lvm.add("zzz"); @@ -152,7 +162,7 @@ public class CompositeListValueModelTests extends TestCase { public void testAddSource_Middle() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); - SimpleListValueModel lvm = new SimpleListValueModel(); + LocalListValueModel lvm = new LocalListValueModel(); lvm.add("xxx"); lvm.add("yyy"); lvm.add("zzz"); @@ -170,7 +180,7 @@ public class CompositeListValueModelTests extends TestCase { public void testAddSource_End() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); - SimpleListValueModel lvm = new SimpleListValueModel(); + LocalListValueModel lvm = new LocalListValueModel(); lvm.add("xxx"); lvm.add("yyy"); lvm.add("zzz"); @@ -188,15 +198,15 @@ public class CompositeListValueModelTests extends TestCase { public void testAddSources() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); - SimpleListValueModel lvmA = new SimpleListValueModel(); + LocalListValueModel lvmA = new LocalListValueModel(); lvmA.add("xxx"); lvmA.add("yyy"); lvmA.add("zzz"); - SimpleListValueModel lvmB = new SimpleListValueModel(); + LocalListValueModel lvmB = new LocalListValueModel(); lvmB.add("ppp"); lvmB.add("qqq"); lvmB.add("rrr"); - Collection> c = new ArrayList>(); + Collection> c = new ArrayList>(); c.add(lvmA); c.add(lvmB); this.uberLVM.addAll(2, c); @@ -269,15 +279,15 @@ public class CompositeListValueModelTests extends TestCase { public void testReplaceSources() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); - SimpleListValueModel lvmA = new SimpleListValueModel(); + LocalListValueModel lvmA = new LocalListValueModel(); lvmA.add("xxx"); lvmA.add("yyy"); lvmA.add("zzz"); - SimpleListValueModel lvmB = new SimpleListValueModel(); + LocalListValueModel lvmB = new LocalListValueModel(); lvmB.add("ppp"); lvmB.add("qqq"); lvmB.add("rrr"); - List> list = new ArrayList>(); + List> list = new ArrayList>(); list.add(lvmA); list.add(lvmB); this.uberLVM.set(2, list); @@ -306,12 +316,12 @@ public class CompositeListValueModelTests extends TestCase { } public void testMoveSources_Middle() { - SimpleListValueModel lvm4 = new SimpleListValueModel(); + LocalListValueModel lvm4 = new LocalListValueModel(); lvm4.add("lll"); lvm4.add("mmm"); this.uberLVM.add(lvm4); - SimpleListValueModel lvm5 = new SimpleListValueModel(); + LocalListValueModel lvm5 = new LocalListValueModel(); lvm5.add("nnn"); lvm5.add("ooo"); lvm5.add("ppp"); @@ -332,12 +342,12 @@ public class CompositeListValueModelTests extends TestCase { } public void testMoveSources_End() { - SimpleListValueModel lvm4 = new SimpleListValueModel(); + LocalListValueModel lvm4 = new LocalListValueModel(); lvm4.add("lll"); lvm4.add("mmm"); this.uberLVM.add(lvm4); - SimpleListValueModel lvm5 = new SimpleListValueModel(); + LocalListValueModel lvm5 = new LocalListValueModel(); lvm5.add("nnn"); lvm5.add("ooo"); lvm5.add("ppp"); @@ -358,12 +368,12 @@ public class CompositeListValueModelTests extends TestCase { } public void testMoveSource() { - SimpleListValueModel lvm4 = new SimpleListValueModel(); + LocalListValueModel lvm4 = new LocalListValueModel(); lvm4.add("lll"); lvm4.add("mmm"); this.uberLVM.add(lvm4); - SimpleListValueModel lvm5 = new SimpleListValueModel(); + LocalListValueModel lvm5 = new LocalListValueModel(); lvm5.add("nnn"); lvm5.add("ooo"); lvm5.add("ppp"); @@ -395,14 +405,14 @@ public class CompositeListValueModelTests extends TestCase { assertTrue(Arrays.equals(expected, coordList.toArray())); } - public void testChangeSources() { - List> newList = new ArrayList>(); - SimpleListValueModel lvm4 = new SimpleListValueModel(); + public void testChangeSources1() { + List> newList = new ArrayList>(); + LocalListValueModel lvm4 = new LocalListValueModel(); lvm4.add("lll"); lvm4.add("mmm"); newList.add(lvm4); - SimpleListValueModel lvm5 = new SimpleListValueModel(); + LocalListValueModel lvm5 = new LocalListValueModel(); lvm5.add("nnn"); lvm5.add("ooo"); lvm5.add("ppp"); @@ -422,6 +432,145 @@ public class CompositeListValueModelTests extends TestCase { assertEquals("ooo", coordList.get(3)); } + public void testChangeSources2() { + List> newList = new ArrayList>(); + LocalListValueModel lvm4 = new LocalListValueModel(); + lvm4.add("lll"); + lvm4.add("mmm"); + newList.add(lvm4); + + LocalListValueModel lvm5 = new LocalListValueModel(); + lvm5.add("nnn"); + lvm5.add("ooo"); + lvm5.add("ppp"); + lvm5.add("qqq"); + newList.add(lvm5); + + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.uberLVM.changeListValues(newList); + + Object[] expected = new Object[] { "lll", "mmm", "nnn", "ooo", "ppp", "qqq" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ooo", this.compositeLVM.get(3)); + assertEquals("ooo", coordList.get(3)); + } + + public void testChangeSources3() { + ListChangeListener listener = new ErrorListener(); + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + + List> newList = new ArrayList>(); + newList.add(this.lvm0); + newList.add(this.lvm1); + newList.add(this.lvm2); + newList.add(this.lvm3); + + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.uberLVM.changeListValues(newList); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ddd", this.compositeLVM.get(3)); + assertEquals("ddd", coordList.get(3)); + } + + public void testChangeSources4() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsAdded(ListAddEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + + List> newList = new ArrayList>(); + newList.add(this.lvm0); + newList.add(this.lvm1); + newList.add(this.lvm2); + newList.add(this.lvm3); + LocalListValueModel lvm4 = new LocalListValueModel(); + lvm4.add("lll"); + lvm4.add("mmm"); + newList.add(lvm4); + + + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.uberLVM.changeListValues(newList); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ddd", this.compositeLVM.get(3)); + assertEquals("ddd", coordList.get(3)); + } + + public void testChangeSources5() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsRemoved(ListRemoveEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + + List> newList = new ArrayList>(); + newList.add(this.lvm0); + newList.add(this.lvm1); + newList.add(this.lvm2); + + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.uberLVM.changeListValues(newList); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ddd", this.compositeLVM.get(3)); + assertEquals("ddd", coordList.get(3)); + } + + public void testChangeSources6() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsAdded(ListAddEvent event) { /* OK */ } + @Override + public void itemsRemoved(ListRemoveEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + + List> newList = new ArrayList>(); + newList.add(this.lvm0); + newList.add(this.lvm1); + + LocalListValueModel lvm4 = new LocalListValueModel(); + lvm4.add("lll"); + lvm4.add("mmm"); + newList.add(lvm4); + + newList.add(this.lvm3); + + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.uberLVM.changeListValues(newList); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "lll", "mmm", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ddd", this.compositeLVM.get(3)); + assertEquals("ddd", coordList.get(3)); + } + public void testAddItem_Begin() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); @@ -803,7 +952,7 @@ public class CompositeListValueModelTests extends TestCase { assertEquals("fff", coordList.get(5)); } - public void testChangeItems_Begin() { + public void testChangeItems_Begin1() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); this.lvm0.setListValues(Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); @@ -817,7 +966,7 @@ public class CompositeListValueModelTests extends TestCase { assertEquals("ggg", coordList.get(6)); } - public void testChangeItems_Middle() { + public void testChangeItems_Middle1() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); this.lvm1.setListValues(Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); @@ -831,7 +980,7 @@ public class CompositeListValueModelTests extends TestCase { assertEquals("ggg", coordList.get(7)); } - public void testChangeItems_End() { + public void testChangeItems_End1() { CoordinatedList coordList = new CoordinatedList(this.compositeLVM); this.lvm3.setListValues(Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); @@ -845,4 +994,255 @@ public class CompositeListValueModelTests extends TestCase { assertEquals("fff", coordList.get(5)); } + public void testChangeItems_Begin2() { + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, new ErrorListener()); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm0.changeListValues(Arrays.asList(new String[] { "aaa", "bbb", "ccc" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ggg", this.compositeLVM.get(6)); + assertEquals("ggg", coordList.get(6)); + } + + public void testChangeItems_Middle2() { + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, new ErrorListener()); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm1.changeListValues(Arrays.asList(new String[] { "ddd", "eee" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("hhh", this.compositeLVM.get(7)); + assertEquals("hhh", coordList.get(7)); + } + + public void testChangeItems_End2() { + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, new ErrorListener()); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm3.changeListValues(Arrays.asList(new String[] { "ggg", "hhh", "iii", "jjj", "kkk" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("fff", this.compositeLVM.get(5)); + assertEquals("fff", coordList.get(5)); + } + + public void testChangeItems_Begin3() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsReplaced(ListReplaceEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm0.changeListValues(Arrays.asList(new String[] { "aaa", "bbb", "xxx" })); + + Object[] expected = new Object[] { "aaa", "bbb", "xxx", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ggg", this.compositeLVM.get(6)); + assertEquals("ggg", coordList.get(6)); + } + + public void testChangeItems_Middle3() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsReplaced(ListReplaceEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm1.changeListValues(Arrays.asList(new String[] { "ddd", "xxx" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "xxx", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("hhh", this.compositeLVM.get(7)); + assertEquals("hhh", coordList.get(7)); + } + + public void testChangeItems_End3() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsReplaced(ListReplaceEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm3.changeListValues(Arrays.asList(new String[] { "ggg", "hhh", "iii", "xxx", "kkk" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "xxx", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("fff", this.compositeLVM.get(5)); + assertEquals("fff", coordList.get(5)); + } + + public void testChangeItems_Begin4() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsAdded(ListAddEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm0.changeListValues(Arrays.asList(new String[] { "aaa", "bbb", "ccc", "xxx" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "xxx", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("fff", this.compositeLVM.get(6)); + assertEquals("fff", coordList.get(6)); + } + + public void testChangeItems_Middle4() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsAdded(ListAddEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm1.changeListValues(Arrays.asList(new String[] { "ddd", "eee", "xxx" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "xxx", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("ggg", this.compositeLVM.get(7)); + assertEquals("ggg", coordList.get(7)); + } + + public void testChangeItems_End4() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsAdded(ListAddEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm3.changeListValues(Arrays.asList(new String[] { "ggg", "hhh", "iii", "jjj", "kkk", "xxx" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "xxx" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("fff", this.compositeLVM.get(5)); + assertEquals("fff", coordList.get(5)); + } + + public void testChangeItems_Begin5() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsRemoved(ListRemoveEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm0.changeListValues(Arrays.asList(new String[] { "aaa" })); + + Object[] expected = new Object[] { "aaa", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("iii", this.compositeLVM.get(6)); + assertEquals("iii", coordList.get(6)); + } + + public void testChangeItems_Middle5() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsRemoved(ListRemoveEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm1.changeListValues(Arrays.asList(new String[] { "ddd" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("iii", this.compositeLVM.get(7)); + assertEquals("iii", coordList.get(7)); + } + + public void testChangeItems_End5() { + ListChangeListener listener = new ErrorListener() { + @Override + public void itemsRemoved(ListRemoveEvent event) { /* OK */ } + }; + this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, listener); + CoordinatedList coordList = new CoordinatedList(this.compositeLVM); + + this.lvm3.changeListValues(Arrays.asList(new String[] { "ggg", "hhh", "iii" })); + + Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii" }; + assertEquals(expected.length, this.compositeLVM.size()); + assertEquals(expected.length, coordList.size()); + assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); + assertTrue(Arrays.equals(expected, coordList.toArray())); + assertEquals("fff", this.compositeLVM.get(5)); + assertEquals("fff", coordList.get(5)); + } + + class ErrorListener implements ListChangeListener { + public void itemsAdded(ListAddEvent event) { + fail(); + } + public void itemsRemoved(ListRemoveEvent event) { + fail(); + } + public void itemsMoved(ListMoveEvent event) { + fail(); + } + public void itemsReplaced(ListReplaceEvent event) { + fail(); + } + public void listCleared(ListClearEvent event) { + fail(); + } + public void listChanged(ListChangeEvent event) { + fail(); + } + } + + class LocalListValueModel extends SimpleListValueModel { + LocalListValueModel() { + super(); + } + void changeListValues(Iterable listValues) { + if (listValues == null) { + throw new NullPointerException(); + } + this.list.clear(); + CollectionTools.addAll(this.list, listValues); + this.fireListChanged(LIST_VALUES, this.list); + } + } + } -- cgit v1.2.1