diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-01-28 17:46:50 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-01-28 17:46:50 +0000 |
commit | 810017204ef10e2d5fbea15ed17b0c1e8a6b0daa (patch) | |
tree | 86dd95e68bddc78016f5eeab6687554ea79563a7 /src/com/vaadin/data/util | |
parent | 1e2a4afc96a7376b922b342224f8e2e4297385aa (diff) | |
download | vaadin-framework-810017204ef10e2d5fbea15ed17b0c1e8a6b0daa.tar.gz vaadin-framework-810017204ef10e2d5fbea15ed17b0c1e8a6b0daa.zip |
some preliminary drag and drop stuff
svn changeset:11052/svn branch:6.3_dd
Diffstat (limited to 'src/com/vaadin/data/util')
-rw-r--r-- | src/com/vaadin/data/util/ContainerHierarchicalWrapper.java | 23 | ||||
-rw-r--r-- | src/com/vaadin/data/util/HierarchicalContainer.java | 26 | ||||
-rw-r--r-- | src/com/vaadin/data/util/IndexedContainer.java | 3 |
3 files changed, 41 insertions, 11 deletions
diff --git a/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java b/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java index 6420aaf838..d516c870a2 100644 --- a/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java +++ b/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java @@ -129,16 +129,6 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, return 0; } }; - Object[] array = roots.toArray(); - Arrays.sort(array, basedOnOrderFromWrappedContainer); - roots = new LinkedHashSet<Object>(); - for (int i = 0; i < array.length; i++) { - roots.add(array[i]); - } - for (Object object : children.keySet()) { - LinkedList<Object> object2 = children.get(object); - Collections.sort(object2, basedOnOrderFromWrappedContainer); - } // Calculate the set of all items in the hierarchy final HashSet<Object> s = new HashSet<Object>(); @@ -163,6 +153,18 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, s.add(id); } } + + Object[] array = roots.toArray(); + Arrays.sort(array, basedOnOrderFromWrappedContainer); + roots = new LinkedHashSet<Object>(); + for (int i = 0; i < array.length; i++) { + roots.add(array[i]); + } + for (Object object : children.keySet()) { + LinkedList<Object> object2 = children.get(object); + Collections.sort(object2, basedOnOrderFromWrappedContainer); + } + } } } @@ -204,6 +206,7 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, */ private void addToHierarchyWrapper(Object itemId) { roots.add(itemId); + } /* diff --git a/src/com/vaadin/data/util/HierarchicalContainer.java b/src/com/vaadin/data/util/HierarchicalContainer.java index f5b65f1dad..2b5519e651 100644 --- a/src/com/vaadin/data/util/HierarchicalContainer.java +++ b/src/com/vaadin/data/util/HierarchicalContainer.java @@ -139,6 +139,25 @@ public class HierarchicalContainer extends IndexedContainer implements return true; } + @Override + public Item addItemAt(int index, Object newItemId) { + Item retval = super.addItemAt(index, newItemId); + if (getParent(newItemId) == null) { + int refIndex = roots.size() - 1; + int indexOfId = indexOfId(roots.get(refIndex)); + while (indexOfId > index) { + refIndex--; + if (refIndex < 0) { + // inserts as first + break; + } + indexOfId = indexOfId(roots.get(refIndex)); + } + roots.add(refIndex + 1, newItemId); + } + return retval; + } + /** * <p> * Sets the parent of an Item. The new parent item must exist and be able to @@ -293,7 +312,12 @@ public class HierarchicalContainer extends IndexedContainer implements if (isRoot(itemId)) { roots.remove(itemId); } - children.remove(itemId); + LinkedList<Object> remove = children.remove(itemId); + if (remove != null) { + for (Object object : remove) { + removeItem(object); + } + } final Object p = parent.get(itemId); if (p != null) { final LinkedList c = children.get(p); diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java index f5dddf5e23..d6d6d9e77c 100644 --- a/src/com/vaadin/data/util/IndexedContainer.java +++ b/src/com/vaadin/data/util/IndexedContainer.java @@ -557,6 +557,9 @@ public class IndexedContainer implements Container.Indexed, return null; } } + if (index < 0) { + index = 0; + } return addItemAt(index, newItemId); } |