From affb4dbd876eba5527d39edda404013fea2e28c2 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Fri, 4 Mar 2011 11:14:32 +0000 Subject: #6527 Container refactoring: moved most of Sortable implementation to AbstractInMemoryContainer svn changeset:17604/svn branch:6.6 --- .../vaadin/data/util/AbstractBeanContainer.java | 60 ++------------ .../data/util/AbstractInMemoryContainer.java | 91 ++++++++++++++++++++++ src/com/vaadin/data/util/IndexedContainer.java | 64 ++------------- 3 files changed, 106 insertions(+), 109 deletions(-) diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java index 56e93733a8..3b8c32455b 100644 --- a/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -9,10 +9,8 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.Map; import com.vaadin.data.Container.Filterable; @@ -133,11 +131,6 @@ public abstract class AbstractBeanContainer extends */ private BeanIdResolver beanIdResolver = null; - /** - * The item sorter which is used for sorting the container. - */ - private ItemSorter itemSorter = new DefaultItemSorter(); - /** * Maps all item ids in the container (including filtered) to their * corresponding BeanItem. @@ -454,16 +447,8 @@ public abstract class AbstractBeanContainer extends * * @see com.vaadin.data.Container.Sortable#getSortableContainerPropertyIds() */ - public Collection getSortableContainerPropertyIds() { - LinkedList sortables = new LinkedList(); - for (Object propertyId : getContainerPropertyIds()) { - Class propertyType = getType(propertyId); - if (Comparable.class.isAssignableFrom(propertyType) - || propertyType.isPrimitive()) { - sortables.add(propertyId); - } - } - return sortables; + public Collection getSortableContainerPropertyIds() { + return getSortablePropertyIds(); } /* @@ -472,48 +457,19 @@ public abstract class AbstractBeanContainer extends * @see com.vaadin.data.Container.Sortable#sort(java.lang.Object[], * boolean[]) */ + @Override public void sort(Object[] propertyId, boolean[] ascending) { - itemSorter.setSortProperties(this, propertyId, ascending); - - doSort(); - - // notifies if anything changes in the filtered list, including order - filterAll(); + super.sort(propertyId, ascending); } - /** - * Perform the sorting of the data structures in the container. This is - * invoked when the itemSorter has been prepared for the sort - * operation. Typically this method calls - * Collections.sort(aCollection, getItemSorter()) on all arrays - * (containing item ids) that need to be sorted. - * - */ - protected void doSort() { - Collections.sort(allItemIds, getItemSorter()); - } - - /** - * Returns the ItemSorter that is used for sorting the container. - * - * @see #setItemSorter(ItemSorter) - * - * @return The ItemSorter that is used for sorting the container - */ + @Override public ItemSorter getItemSorter() { - return itemSorter; + return super.getItemSorter(); } - /** - * Sets the ItemSorter that is used for sorting the container. The - * {@link ItemSorter#compare(Object, Object)} method is called to compare - * two beans (item ids). - * - * @param itemSorter - * The ItemSorter to use when sorting the container - */ + @Override public void setItemSorter(ItemSorter itemSorter) { - this.itemSorter = itemSorter; + super.setItemSorter(itemSorter); } /** diff --git a/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/src/com/vaadin/data/util/AbstractInMemoryContainer.java index 32ac3a70be..2197c28905 100644 --- a/src/com/vaadin/data/util/AbstractInMemoryContainer.java +++ b/src/com/vaadin/data/util/AbstractInMemoryContainer.java @@ -69,6 +69,11 @@ public abstract class AbstractInMemoryContainer filters = new HashSet(); + /** + * The item sorter which is used for sorting the container. + */ + private ItemSorter itemSorter = new DefaultItemSorter(); + // Constructors /** @@ -351,6 +356,92 @@ public abstract class AbstractInMemoryContaineritemSorter has been prepared for the sort + * operation. Typically this method calls + * Collections.sort(aCollection, getItemSorter()) on all arrays + * (containing item ids) that need to be sorted. + * + */ + protected void doSort() { + Collections.sort(allItemIds, getItemSorter()); + } + + /** + * Returns the sortable property identifiers for the container. Can be used + * to implement {@link Sortable#getSortableContainerPropertyIds()}. + */ + protected Collection getSortablePropertyIds() { + LinkedList sortables = new LinkedList(); + for (Object propertyId : getContainerPropertyIds()) { + Class propertyType = getType(propertyId); + if (Comparable.class.isAssignableFrom(propertyType) + || propertyType.isPrimitive()) { + sortables.add(propertyId); + } + } + return sortables; + } + // removing items /** diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java index 62ace0f80d..117e1e24ec 100644 --- a/src/com/vaadin/data/util/IndexedContainer.java +++ b/src/com/vaadin/data/util/IndexedContainer.java @@ -89,11 +89,6 @@ public class IndexedContainer extends */ private Hashtable>> singlePropertyValueChangeListeners = null; - /** - * The item sorter which is used for sorting the container. - */ - private ItemSorter itemSorter = new DefaultItemSorter(); - private HashMap defaultPropertyValues; private int nextGeneratedItemId = 1; @@ -964,32 +959,9 @@ public class IndexedContainer extends * @see com.vaadin.data.Container.Sortable#sort(java.lang.Object[], * boolean[]) */ + @Override public void sort(Object[] propertyId, boolean[] ascending) { - // Set up the item sorter for the sort operation - itemSorter.setSortProperties(this, propertyId, ascending); - - // Perform the actual sort - doSort(); - - // Post sort updates - if (getFilteredItemIds() != null) { - filterAll(); - } else { - fireItemSetChange(); - } - - } - - /** - * Perform the sorting of the data structures in the container. This is - * invoked when the itemSorter has been prepared for the sort - * operation. Typically this method calls - * Collections.sort(aCollection, getItemSorter()) on all arrays - * (containing item ids) that need to be sorted. - * - */ - protected void doSort() { - Collections.sort(allItemIds, getItemSorter()); + super.sort(propertyId, ascending); } /* @@ -999,39 +971,17 @@ public class IndexedContainer extends * () */ public Collection getSortableContainerPropertyIds() { - - final List list = new LinkedList(); - for (final Iterator i = propertyIds.iterator(); i.hasNext();) { - final Object id = i.next(); - final Class type = getType(id); - if (type != null && Comparable.class.isAssignableFrom(type)) { - list.add(id); - } - } - - return list; + return getSortablePropertyIds(); } - /** - * Returns the ItemSorter used for comparing items in a sort. See - * {@link #setItemSorter(ItemSorter)} for more information. - * - * @return The ItemSorter used for comparing two items in a sort. - */ + @Override public ItemSorter getItemSorter() { - return itemSorter; + return super.getItemSorter(); } - /** - * Sets the ItemSorter used for comparing items in a sort. The ItemSorter is - * called for each collection that needs sorting. A default ItemSorter is - * used if this is not explicitly set. - * - * @param itemSorter - * The ItemSorter used for comparing two items in a sort. - */ + @Override public void setItemSorter(ItemSorter itemSorter) { - this.itemSorter = itemSorter; + super.setItemSorter(itemSorter); } /** -- cgit v1.2.3