summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2011-03-04 13:35:00 +0000
committerHenri Sara <henri.sara@itmill.com>2011-03-04 13:35:00 +0000
commite2e3217ffa68806d69e180fa9e9c0ea04979400d (patch)
treed7bd21b49284c11696441d86ab232a6a9858a05d /src/com/vaadin
parentf8ea9850c9f7ee921e38314adb36b53a02c87097 (diff)
downloadvaadin-framework-e2e3217ffa68806d69e180fa9e9c0ea04979400d.tar.gz
vaadin-framework-e2e3217ffa68806d69e180fa9e9c0ea04979400d.zip
#6527 Container refactoring: initial in-memory ItemFilter interface to isolate future #6286 filtering API impact on in-memory containers
svn changeset:17615/svn branch:6.6
Diffstat (limited to 'src/com/vaadin')
-rw-r--r--src/com/vaadin/data/util/AbstractBeanContainer.java12
-rw-r--r--src/com/vaadin/data/util/AbstractInMemoryContainer.java66
-rw-r--r--src/com/vaadin/data/util/Filter.java13
-rw-r--r--src/com/vaadin/data/util/IndexedContainer.java2
4 files changed, 65 insertions, 28 deletions
diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java
index 103e754ada..197e844dde 100644
--- a/src/com/vaadin/data/util/AbstractBeanContainer.java
+++ b/src/com/vaadin/data/util/AbstractBeanContainer.java
@@ -368,7 +368,7 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
* .Object)
*/
public void removeContainerFilters(Object propertyId) {
- Collection<Filter> removedFilters = super.removeFilters(propertyId);
+ Collection<ItemFilter> removedFilters = super.removeFilters(propertyId);
if (!removedFilters.isEmpty()) {
// stop listening to change events for the property
for (Item item : itemIdToItem.values()) {
@@ -486,9 +486,13 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
// add listeners to be able to update filtering on property
// changes
- for (Filter filter : getFilters()) {
- // addValueChangeListener avoids adding duplicates
- addValueChangeListener(item, filter.propertyId);
+ for (ItemFilter filter : getFilters()) {
+ for (String propertyId : getContainerPropertyIds()) {
+ if (filter.appliesToProperty(propertyId)) {
+ // addValueChangeListener avoids adding duplicates
+ addValueChangeListener(item, propertyId);
+ }
+ }
}
}
diff --git a/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/src/com/vaadin/data/util/AbstractInMemoryContainer.java
index 6f96877e6b..2ac1052afb 100644
--- a/src/com/vaadin/data/util/AbstractInMemoryContainer.java
+++ b/src/com/vaadin/data/util/AbstractInMemoryContainer.java
@@ -1,5 +1,6 @@
package com.vaadin.data.util;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -45,6 +46,38 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
Container.Indexed {
/**
+ * Filter interface for item filtering in in-memory containers, including
+ * for implementing {@link Filterable}.
+ *
+ * An ItemFilter must implement {@link #equals(Object)} and
+ * {@link #hashCode()} correctly to avoid duplicate filter registrations
+ * etc.
+ *
+ * TODO this may change for 6.6 with the new filtering API
+ *
+ * @since 6.6
+ */
+ public interface ItemFilter extends Serializable {
+ /**
+ * Check if an item passes the filter.
+ *
+ * @param item
+ * @return true if the item is accepted by this filter
+ */
+ public boolean passesFilter(Item item);
+
+ /**
+ * Check if a change in the value of a property can affect the filtering
+ * result. May always return true, at the cost of performance.
+ *
+ * @param propertyId
+ * @return true if the filtering result may/does change based on changes
+ * to the property identified by propertyId
+ */
+ public boolean appliesToProperty(Object propertyId);
+ }
+
+ /**
* An ordered {@link List} of all item identifiers in the container,
* including those that have been filtered out.
*
@@ -67,7 +100,7 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
* Filters that are applied to the container to limit the items visible in
* it
*/
- private Set<Filter> filters = new HashSet<Filter>();
+ private Set<ItemFilter> filters = new HashSet<ItemFilter>();
/**
* The item sorter which is used for sorting the container.
@@ -269,9 +302,9 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
if (getFilters().isEmpty()) {
return true;
}
- final Iterator<Filter> i = getFilters().iterator();
+ final Iterator<ItemFilter> i = getFilters().iterator();
while (i.hasNext()) {
- final Filter f = i.next();
+ final ItemFilter f = i.next();
if (!f.passesFilter(item)) {
return false;
}
@@ -285,7 +318,7 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
* This can be used to implement
* {@link Filterable#addContainerFilter(Object, String, boolean, boolean)}.
*/
- protected void addFilter(Filter filter) {
+ protected void addFilter(ItemFilter filter) {
getFilters().add(filter);
filterAll();
}
@@ -314,10 +347,10 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
if (getFilters().isEmpty() || propertyId == null) {
return false;
}
- final Iterator<Filter> i = getFilters().iterator();
+ final Iterator<ItemFilter> i = getFilters().iterator();
while (i.hasNext()) {
- final Filter f = i.next();
- if (propertyId.equals(f.propertyId)) {
+ final ItemFilter f = i.next();
+ if (f.appliesToProperty(propertyId)) {
return true;
}
}
@@ -326,7 +359,8 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
/**
* Remove all container filters for a given property identifier and
- * re-filter the view.
+ * re-filter the view. This also removes filters applying to multiple
+ * properties including the one identified by propertyId.
*
* This can be used to implement
* {@link Filterable#removeContainerFilters(Object)}.
@@ -334,15 +368,15 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
* @param propertyId
* @return Collection<Filter> removed filters
*/
- protected Collection<Filter> removeFilters(Object propertyId) {
+ protected Collection<ItemFilter> removeFilters(Object propertyId) {
if (getFilters().isEmpty() || propertyId == null) {
return Collections.emptyList();
}
- List<Filter> removedFilters = new LinkedList<Filter>();
- for (Iterator<Filter> iterator = getFilters().iterator(); iterator
+ List<ItemFilter> removedFilters = new LinkedList<ItemFilter>();
+ for (Iterator<ItemFilter> iterator = getFilters().iterator(); iterator
.hasNext();) {
- Filter f = iterator.next();
- if (f.propertyId.equals(propertyId)) {
+ ItemFilter f = iterator.next();
+ if (f.appliesToProperty(propertyId)) {
removedFilters.add(f);
iterator.remove();
}
@@ -734,7 +768,7 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
*
* @param filters
*/
- protected void setFilters(Set<Filter> filters) {
+ protected void setFilters(Set<ItemFilter> filters) {
this.filters = filters;
}
@@ -742,9 +776,9 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
* TODO Temporary internal helper method to get the internal list of
* filters.
*
- * @return Set<Filter>
+ * @return Set<ItemFilter>
*/
- protected Set<Filter> getFilters() {
+ protected Set<ItemFilter> getFilters() {
return filters;
}
diff --git a/src/com/vaadin/data/util/Filter.java b/src/com/vaadin/data/util/Filter.java
index 433fce5ea9..f6f6638250 100644
--- a/src/com/vaadin/data/util/Filter.java
+++ b/src/com/vaadin/data/util/Filter.java
@@ -15,7 +15,8 @@ import com.vaadin.data.Property;
* @since 5.4
*/
@SuppressWarnings("serial")
-public class Filter implements Serializable {
+public class Filter implements AbstractInMemoryContainer.ItemFilter,
+ Serializable {
final Object propertyId;
final String filterString;
final boolean ignoreCase;
@@ -31,12 +32,6 @@ public class Filter implements Serializable {
this.onlyMatchPrefix = onlyMatchPrefix;
}
- /**
- * Check if an item passes the filter.
- *
- * @param item
- * @return true if the item is accepted by this filter
- */
public boolean passesFilter(Item item) {
final Property p = item.getItemProperty(propertyId);
if (p == null || p.toString() == null) {
@@ -56,6 +51,10 @@ public class Filter implements Serializable {
return true;
}
+ public boolean appliesToProperty(Object propertyId) {
+ return this.propertyId.equals(propertyId);
+ }
+
@Override
public boolean equals(Object obj) {
diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java
index c7c7acd1d6..4326eef758 100644
--- a/src/com/vaadin/data/util/IndexedContainer.java
+++ b/src/com/vaadin/data/util/IndexedContainer.java
@@ -1019,7 +1019,7 @@ public class IndexedContainer extends
nc.types = types != null ? (Hashtable<Object, Class<?>>) types.clone()
: null;
- nc.setFilters((HashSet<Filter>) ((HashSet<Filter>) getFilters())
+ nc.setFilters((HashSet<ItemFilter>) ((HashSet<ItemFilter>) getFilters())
.clone());
nc.setFilteredItemIds(getFilteredItemIds() == null ? null