Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2010-05-10 21:47:11 +0000
committerkmoore2010-05-10 21:47:11 +0000
commit3d5c7a5dbb100aaed9b54bd4b0cb2fef96fdaa8e (patch)
treeb4306929c291427ef9d62e407f9dfb455d093a61 /jpa
parent20b6515f09629d044b6ec02b9d083ccfbd730f49 (diff)
downloadwebtools.dali-3d5c7a5dbb100aaed9b54bd4b0cb2fef96fdaa8e.tar.gz
webtools.dali-3d5c7a5dbb100aaed9b54bd4b0cb2fef96fdaa8e.tar.xz
webtools.dali-3d5c7a5dbb100aaed9b54bd4b0cb2fef96fdaa8e.zip
311112 - @Convert value can get unset - CompositeListValueModel listChanged events fixed by Brian
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CompositeListValueModel.java155
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java468
3 files changed, 547 insertions, 78 deletions
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<E> extends AbstractComboModelAdapter<E> {
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<E1, E2>
final ArrayList<E2> items;
// the component LVM's beginning index within the composite LVM
int begin;
- Info(E1 source, ListValueModel<E2> componentLVM, ArrayList<E2> items, int begin) {
+ protected Info(E1 source, ListValueModel<E2> componentLVM, ArrayList<E2> items, int begin) {
super();
this.source = source;
this.componentLVM = componentLVM;
@@ -232,7 +233,7 @@ public class CompositeListValueModel<E1, E2>
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
@@ -256,13 +257,6 @@ public class CompositeListValueModel<E1, E2>
}
/**
- * Do not fire an event.
- */
- protected void addComponentSources(int addedSourcesIndex, Iterable<? extends E1> 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.
*/
@@ -309,13 +303,6 @@ public class CompositeListValueModel<E1, E2>
}
/**
- * 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.
*/
protected void removeComponentSources(int removedSourcesIndex, int removedSourcesSize, boolean fireEvent) {
@@ -413,7 +400,11 @@ public class CompositeListValueModel<E1, E2>
*/
@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<E1, E2>
*/
@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<E1>(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<? extends E1> buildSubListHolder(int fromIndex) {
+ int listHolderSize = this.listHolder.size();
+ return CollectionTools.list(this.listHolder, listHolderSize).subList(fromIndex, listHolderSize);
+ }
+
+ protected Iterable<? extends E1> 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<E1, E2>
* 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<E1, E2>
* 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<E2> 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<E1, E2>
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<E2> items = new ArrayList<E2>(info.items);
+ ArrayList<E2> items = new ArrayList<E2>(info.items); // make a copy
info.items.clear();
// translate the event
@@ -569,26 +608,58 @@ public class CompositeListValueModel<E1, E2>
/**
* 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<E2> subList = info.items.subList(newItemsSize, oldItemsSize);
+ ArrayList<E2> removedItems = new ArrayList<E2>(subList); // make a copy
+ subList.clear();
+ this.fireItemsRemoved(LIST_VALUES, info.begin + newItemsSize, removedItems);
+ return;
+ }
+
+ // newItemsSize > oldItemsSize
+ ArrayList<E2> addedItems = new ArrayList<E2>(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<E1, E2>
// minimize scope of suppressed warnings
@SuppressWarnings("unchecked")
- protected ListValueModel<E2> componentLVM(ListEvent event) {
+ protected ListValueModel<E2> getComponentLVM(ListEvent event) {
return (ListValueModel<E2>) 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<String> lvm0;
- private SimpleListValueModel<String> lvm1;
- private SimpleListValueModel<String> lvm2;
- private SimpleListValueModel<String> lvm3;
- private SimpleListValueModel<SimpleListValueModel<String>> uberLVM;
- private CompositeListValueModel<SimpleListValueModel<String>, String> compositeLVM;
+ private LocalListValueModel<String> lvm0;
+ private LocalListValueModel<String> lvm1;
+ private LocalListValueModel<String> lvm2;
+ private LocalListValueModel<String> lvm3;
+ private LocalListValueModel<LocalListValueModel<String>> uberLVM;
+ private CompositeListValueModel<LocalListValueModel<String>, 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<String>();
+ this.lvm0 = new LocalListValueModel<String>();
this.lvm0.add("aaa");
this.lvm0.add("bbb");
this.lvm0.add("ccc");
- this.lvm1 = new SimpleListValueModel<String>();
+ this.lvm1 = new LocalListValueModel<String>();
this.lvm1.add("ddd");
this.lvm1.add("eee");
- this.lvm2 = new SimpleListValueModel<String>();
+ this.lvm2 = new LocalListValueModel<String>();
this.lvm2.add("fff");
- this.lvm3 = new SimpleListValueModel<String>();
+ this.lvm3 = new LocalListValueModel<String>();
this.lvm3.add("ggg");
this.lvm3.add("hhh");
this.lvm3.add("iii");
this.lvm3.add("jjj");
this.lvm3.add("kkk");
- this.uberLVM = new SimpleListValueModel<SimpleListValueModel<String>>();
+ this.uberLVM = new LocalListValueModel<LocalListValueModel<String>>();
this.uberLVM.add(this.lvm0);
this.uberLVM.add(this.lvm1);
this.uberLVM.add(this.lvm2);
this.uberLVM.add(this.lvm3);
- this.compositeLVM = new CompositeListValueModel<SimpleListValueModel<String>, String>((ListValueModel<SimpleListValueModel<String>>) this.uberLVM);
+ this.compositeLVM = new CompositeListValueModel<LocalListValueModel<String>, String>((ListValueModel<LocalListValueModel<String>>) this.uberLVM);
}
@Override
@@ -134,7 +144,7 @@ public class CompositeListValueModelTests extends TestCase {
public void testAddSource_Begin() {
CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM);
- SimpleListValueModel<String> lvm = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm = new LocalListValueModel<String>();
lvm.add("xxx");
lvm.add("yyy");
lvm.add("zzz");
@@ -152,7 +162,7 @@ public class CompositeListValueModelTests extends TestCase {
public void testAddSource_Middle() {
CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM);
- SimpleListValueModel<String> lvm = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm = new LocalListValueModel<String>();
lvm.add("xxx");
lvm.add("yyy");
lvm.add("zzz");
@@ -170,7 +180,7 @@ public class CompositeListValueModelTests extends TestCase {
public void testAddSource_End() {
CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM);
- SimpleListValueModel<String> lvm = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm = new LocalListValueModel<String>();
lvm.add("xxx");
lvm.add("yyy");
lvm.add("zzz");
@@ -188,15 +198,15 @@ public class CompositeListValueModelTests extends TestCase {
public void testAddSources() {
CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM);
- SimpleListValueModel<String> lvmA = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvmA = new LocalListValueModel<String>();
lvmA.add("xxx");
lvmA.add("yyy");
lvmA.add("zzz");
- SimpleListValueModel<String> lvmB = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvmB = new LocalListValueModel<String>();
lvmB.add("ppp");
lvmB.add("qqq");
lvmB.add("rrr");
- Collection<SimpleListValueModel<String>> c = new ArrayList<SimpleListValueModel<String>>();
+ Collection<LocalListValueModel<String>> c = new ArrayList<LocalListValueModel<String>>();
c.add(lvmA);
c.add(lvmB);
this.uberLVM.addAll(2, c);
@@ -269,15 +279,15 @@ public class CompositeListValueModelTests extends TestCase {
public void testReplaceSources() {
CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM);
- SimpleListValueModel<String> lvmA = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvmA = new LocalListValueModel<String>();
lvmA.add("xxx");
lvmA.add("yyy");
lvmA.add("zzz");
- SimpleListValueModel<String> lvmB = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvmB = new LocalListValueModel<String>();
lvmB.add("ppp");
lvmB.add("qqq");
lvmB.add("rrr");
- List<SimpleListValueModel<String>> list = new ArrayList<SimpleListValueModel<String>>();
+ List<LocalListValueModel<String>> list = new ArrayList<LocalListValueModel<String>>();
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<String> lvm4 = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm4 = new LocalListValueModel<String>();
lvm4.add("lll");
lvm4.add("mmm");
this.uberLVM.add(lvm4);
- SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm5 = new LocalListValueModel<String>();
lvm5.add("nnn");
lvm5.add("ooo");
lvm5.add("ppp");
@@ -332,12 +342,12 @@ public class CompositeListValueModelTests extends TestCase {
}
public void testMoveSources_End() {
- SimpleListValueModel<String> lvm4 = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm4 = new LocalListValueModel<String>();
lvm4.add("lll");
lvm4.add("mmm");
this.uberLVM.add(lvm4);
- SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm5 = new LocalListValueModel<String>();
lvm5.add("nnn");
lvm5.add("ooo");
lvm5.add("ppp");
@@ -358,12 +368,12 @@ public class CompositeListValueModelTests extends TestCase {
}
public void testMoveSource() {
- SimpleListValueModel<String> lvm4 = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm4 = new LocalListValueModel<String>();
lvm4.add("lll");
lvm4.add("mmm");
this.uberLVM.add(lvm4);
- SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm5 = new LocalListValueModel<String>();
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<SimpleListValueModel<String>> newList = new ArrayList<SimpleListValueModel<String>>();
- SimpleListValueModel<String> lvm4 = new SimpleListValueModel<String>();
+ public void testChangeSources1() {
+ List<LocalListValueModel<String>> newList = new ArrayList<LocalListValueModel<String>>();
+ LocalListValueModel<String> lvm4 = new LocalListValueModel<String>();
lvm4.add("lll");
lvm4.add("mmm");
newList.add(lvm4);
- SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>();
+ LocalListValueModel<String> lvm5 = new LocalListValueModel<String>();
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<LocalListValueModel<String>> newList = new ArrayList<LocalListValueModel<String>>();
+ LocalListValueModel<String> lvm4 = new LocalListValueModel<String>();
+ lvm4.add("lll");
+ lvm4.add("mmm");
+ newList.add(lvm4);
+
+ LocalListValueModel<String> lvm5 = new LocalListValueModel<String>();
+ lvm5.add("nnn");
+ lvm5.add("ooo");
+ lvm5.add("ppp");
+ lvm5.add("qqq");
+ newList.add(lvm5);
+
+ CoordinatedList<String> coordList = new CoordinatedList<String>(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<LocalListValueModel<String>> newList = new ArrayList<LocalListValueModel<String>>();
+ newList.add(this.lvm0);
+ newList.add(this.lvm1);
+ newList.add(this.lvm2);
+ newList.add(this.lvm3);
+
+ CoordinatedList<String> coordList = new CoordinatedList<String>(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<LocalListValueModel<String>> newList = new ArrayList<LocalListValueModel<String>>();
+ newList.add(this.lvm0);
+ newList.add(this.lvm1);
+ newList.add(this.lvm2);
+ newList.add(this.lvm3);
+ LocalListValueModel<String> lvm4 = new LocalListValueModel<String>();
+ lvm4.add("lll");
+ lvm4.add("mmm");
+ newList.add(lvm4);
+
+
+ CoordinatedList<String> coordList = new CoordinatedList<String>(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<LocalListValueModel<String>> newList = new ArrayList<LocalListValueModel<String>>();
+ newList.add(this.lvm0);
+ newList.add(this.lvm1);
+ newList.add(this.lvm2);
+
+ CoordinatedList<String> coordList = new CoordinatedList<String>(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<LocalListValueModel<String>> newList = new ArrayList<LocalListValueModel<String>>();
+ newList.add(this.lvm0);
+ newList.add(this.lvm1);
+
+ LocalListValueModel<String> lvm4 = new LocalListValueModel<String>();
+ lvm4.add("lll");
+ lvm4.add("mmm");
+ newList.add(lvm4);
+
+ newList.add(this.lvm3);
+
+ CoordinatedList<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<String> coordList = new CoordinatedList<String>(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<E> extends SimpleListValueModel<E> {
+ LocalListValueModel() {
+ super();
+ }
+ void changeListValues(Iterable<E> listValues) {
+ if (listValues == null) {
+ throw new NullPointerException();
+ }
+ this.list.clear();
+ CollectionTools.addAll(this.list, listValues);
+ this.fireListChanged(LIST_VALUES, this.list);
+ }
+ }
+
}

Back to the top