diff options
author | Henri Sara <henri.sara@itmill.com> | 2010-06-30 12:17:29 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2010-06-30 12:17:29 +0000 |
commit | f2cdd8f99d4e51e1893a9603a09fd4cb5a2faba2 (patch) | |
tree | 0b9429740c15e935932d0e1ebb128cf72c52bc44 /src/com/vaadin/data/util/ContainerHierarchicalWrapper.java | |
parent | f7f9e8fba62e981c2f7e63b9ce18199c97003fef (diff) | |
download | vaadin-framework-f2cdd8f99d4e51e1893a9603a09fd4cb5a2faba2.tar.gz vaadin-framework-f2cdd8f99d4e51e1893a9603a09fd4cb5a2faba2.zip |
#5280 make ContainerHierarchicalWrapper serializable
svn changeset:13974/svn branch:6.4
Diffstat (limited to 'src/com/vaadin/data/util/ContainerHierarchicalWrapper.java')
-rw-r--r-- | src/com/vaadin/data/util/ContainerHierarchicalWrapper.java | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java b/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java index 668a3fc5dd..4dca5cf52b 100644 --- a/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java +++ b/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java @@ -4,6 +4,7 @@ package com.vaadin.data.util; +import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -59,6 +60,33 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, private boolean hierarchical; /** + * A comparator that sorts the listed items before other items. Otherwise, + * the order is undefined. + */ + private static class ListedItemsFirstComparator implements + Comparator<Object>, Serializable { + private final Collection<?> itemIds; + + private ListedItemsFirstComparator(Collection<?> itemIds) { + this.itemIds = itemIds; + } + + public int compare(Object o1, Object o2) { + if (o1.equals(o2)) { + return 0; + } + for (Object id : itemIds) { + if (id == o1) { + return -1; + } else if (id == o2) { + return 1; + } + } + return 0; + } + }; + + /** * Constructs a new hierarchical wrapper for an existing Container. Works * even if the to-be-wrapped container already implements the * <code>Container.Hierarchical</code> interface. @@ -113,22 +141,9 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, // ensure order of root and child lists is same as in wrapped // container - final Collection<?> itemIds = container.getItemIds(); - Comparator<Object> basedOnOrderFromWrappedContainer = new Comparator<Object>() { - public int compare(Object o1, Object o2) { - if (o1.equals(o2)) { - return 0; - } - for (Object id : itemIds) { - if (id == o1) { - return -1; - } else if (id == o2) { - return 1; - } - } - return 0; - } - }; + Collection<?> itemIds = container.getItemIds(); + Comparator<Object> basedOnOrderFromWrappedContainer = new ListedItemsFirstComparator( + itemIds); // Calculate the set of all items in the hierarchy final HashSet<Object> s = new HashSet<Object>(); |