From: Henri Sara Date: Mon, 21 Mar 2011 09:29:35 +0000 (+0000) Subject: #6286 Container filtering improvements: Filterable does not inherit SimpleFilterable X-Git-Tag: 6.7.0.beta1~382 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7fb7a95497838fc0b512f3e14ac51c4af11aac44;p=vaadin-framework.git #6286 Container filtering improvements: Filterable does not inherit SimpleFilterable svn changeset:17854/svn branch:6.6 --- diff --git a/src/com/vaadin/data/Container.java b/src/com/vaadin/data/Container.java index 3e409c8485..6e9903d597 100644 --- a/src/com/vaadin/data/Container.java +++ b/src/com/vaadin/data/Container.java @@ -7,6 +7,7 @@ package com.vaadin.data; import java.io.Serializable; import java.util.Collection; +import com.vaadin.data.util.filter.SimpleStringFilter; import com.vaadin.data.util.filter.UnsupportedFilterException; /** @@ -691,7 +692,11 @@ public interface Container extends Serializable { /** * Interface that is implemented by containers which allow reducing their - * visible contents based on a set of filters. + * visible contents based on a set of filters. This interface has been + * renamed from {@link Filterable}, and implementing the new + * {@link Filterable} instead of or in addition to {@link SimpleFilterable} + * is recommended. This interface might be removed in future Vaadin + * versions. *

* When a set of filters are set, only items that match all the filters are * included in the visible contents of the container. Still new items that @@ -717,16 +722,22 @@ public interface Container extends Serializable { * 0, at index {@link com.vaadin.data.Container#size()} or at an undefined * position is up to the implementation. *

+ *

+ * SimpleFilterable can be implemented using the {@link Filterable} API and + * {@link SimpleStringFilter}. + *

* * @since 5.0 - * @deprecated use {@link Filterable} */ - @Deprecated public interface SimpleFilterable extends Container, Serializable { /** * Add a filter for given property. * + * The API {@link Filterable#addContainerFilter(Filter)} is recommended + * instead of this method. A {@link SimpleStringFilter} can be used with + * the new API to implement the old string filtering functionality. + * * Only items where given property for which toString() contains or * starts with given filterString are visible in the container. * @@ -742,10 +753,7 @@ public interface Container extends Serializable { * strings. * @param onlyMatchPrefix * Only match prefixes; no other matches are included. - * - * @deprecated use {@link Filterable#addContainerFilter(Filter)} */ - @Deprecated public void addContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix); @@ -754,10 +762,7 @@ public interface Container extends Serializable { /** * Remove all filters from given property. - * - * @deprecated use {@link Filterable#removeContainerFilter(Filter)} */ - @Deprecated public void removeContainerFilters(Object propertyId); } @@ -849,15 +854,12 @@ public interface Container extends Serializable { * *

* This API replaces the old Filterable interface, renamed to - * {@link SimpleFilterable} in Vaadin 6.6. Currently this interface extends - * {@link SimpleFilterable} for backwards compatibility, but might not do so - * in future versions. removeAllContainerFilters() will remain - * a part of the API. + * {@link SimpleFilterable} in Vaadin 6.6. *

* * @since 6.6 */ - public interface Filterable extends SimpleFilterable, Serializable { + public interface Filterable extends Container, Serializable { /** * Adds a filter for the container. * @@ -878,6 +880,11 @@ public interface Container extends Serializable { */ public void removeContainerFilter(Filter filter); + /** + * Remove all active filters from the container. + */ + public void removeAllContainerFilters(); + } /** diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java index f5bd836485..fab61786d1 100644 --- a/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -14,6 +14,7 @@ import java.util.LinkedHashMap; import java.util.Map; import com.vaadin.data.Container.Filterable; +import com.vaadin.data.Container.SimpleFilterable; import com.vaadin.data.Container.Sortable; import com.vaadin.data.Item; import com.vaadin.data.Property; @@ -53,7 +54,7 @@ import com.vaadin.data.util.filter.UnsupportedFilterException; */ public abstract class AbstractBeanContainer extends AbstractInMemoryContainer> implements - Filterable, Sortable, ValueChangeListener { + Filterable, SimpleFilterable, Sortable, ValueChangeListener { /** * Resolver that maps beans to their (item) identifiers, removing the need @@ -290,6 +291,7 @@ public abstract class AbstractBeanContainer extends */ @Override public boolean removeItem(Object itemId) { + // TODO should also remove items that are filtered out int origSize = size(); Item item = getItem(itemId); int position = indexOfId(itemId); diff --git a/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/src/com/vaadin/data/util/AbstractInMemoryContainer.java index 548f30f984..79803ed7b7 100644 --- a/src/com/vaadin/data/util/AbstractInMemoryContainer.java +++ b/src/com/vaadin/data/util/AbstractInMemoryContainer.java @@ -37,8 +37,8 @@ import com.vaadin.data.util.filter.UnsupportedFilterException; *
    *
  • {@link Container.Ordered} *
  • {@link Container.Indexed} - *
  • {@link Filterable} (internal implementation, does not implement the - * interface directly) + *
  • {@link Filterable} and {@link SimpleFilterable} (internal implementation, + * does not implement the interface directly) *
  • {@link Sortable} (internal implementation, does not implement the * interface directly) *
@@ -48,11 +48,20 @@ import com.vaadin.data.util.filter.UnsupportedFilterException; * {@link #sortContainer(Object[], boolean[])} in the method * sort(Object[], boolean[]). * - * To implement Filterable, subclasses need to implement the methods - * addContainerFilter() (calling {@link #addFilter(Filter)}), - * removeAllContainerFilters() (calling {@link #removeAllFilters()} - * ) and removeContainerFilters(Object) (calling - * {@link #removeFilters(Object)}). + * To implement {@link Filterable}, subclasses need to implement the methods + * {@link Filterable#addContainerFilter(com.vaadin.data.Container.Filter)} + * (calling {@link #addFilter(Filter)}), + * {@link Filterable#removeAllContainerFilters()} (calling + * {@link #removeAllFilters()}) and + * {@link Filterable#removeContainerFilter(com.vaadin.data.Container.Filter)} + * (calling {@link #removeFilter(com.vaadin.data.Container.Filter)}). + * + * To implement {@link SimpleFilterable}, subclasses also need to implement the + * methods + * {@link SimpleFilterable#addContainerFilter(Object, String, boolean, boolean)} + * and {@link SimpleFilterable#removeContainerFilters(Object)} calling + * {@link #addFilter(com.vaadin.data.Container.Filter)} and + * {@link #removeFilters(Object)} respectively. * * @param * the class of item identifiers in the container, use Object if can diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java index 78df8b2cc2..11e4c702ed 100644 --- a/src/com/vaadin/data/util/IndexedContainer.java +++ b/src/com/vaadin/data/util/IndexedContainer.java @@ -52,7 +52,8 @@ import com.vaadin.data.util.filter.UnsupportedFilterException; public class IndexedContainer extends AbstractInMemoryContainer implements Container.PropertySetChangeNotifier, Property.ValueChangeNotifier, - Container.Sortable, Cloneable, Container.Filterable { + Container.Sortable, Cloneable, Container.Filterable, + Container.SimpleFilterable { /* Internal structure */ diff --git a/tests/src/com/vaadin/tests/server/container/AbstractContainerTest.java b/tests/src/com/vaadin/tests/server/container/AbstractContainerTest.java index dd34681c00..a83fcfc0f7 100644 --- a/tests/src/com/vaadin/tests/server/container/AbstractContainerTest.java +++ b/tests/src/com/vaadin/tests/server/container/AbstractContainerTest.java @@ -12,6 +12,7 @@ import com.vaadin.data.Container.ItemSetChangeEvent; import com.vaadin.data.Container.ItemSetChangeListener; import com.vaadin.data.Container.Sortable; import com.vaadin.data.Item; +import com.vaadin.data.util.filter.SimpleStringFilter; public abstract class AbstractContainerTest extends TestCase { @@ -312,7 +313,8 @@ public abstract class AbstractContainerTest extends TestCase { initializeContainer(container); // Filter by "contains ab" - container.addContainerFilter(FULLY_QUALIFIED_NAME, "ab", false, false); + container.addContainerFilter(new SimpleStringFilter( + FULLY_QUALIFIED_NAME, "ab", false, false)); validateContainer(container, "com.vaadin.data.BufferedValidatable", "com.vaadin.ui.TabSheet", @@ -321,8 +323,8 @@ public abstract class AbstractContainerTest extends TestCase { // Filter by "contains da" (reversed as ad here) container.removeAllContainerFilters(); - container.addContainerFilter(REVERSE_FULLY_QUALIFIED_NAME, "ad", false, - false); + container.addContainerFilter(new SimpleStringFilter( + REVERSE_FULLY_QUALIFIED_NAME, "ad", false, false)); validateContainer(container, "com.vaadin.data.Buffered", "com.vaadin.terminal.gwt.server.ComponentSizeValidator", @@ -347,7 +349,8 @@ public abstract class AbstractContainerTest extends TestCase { initializeContainer(sortable); // Filter by "contains ab" - filterable.addContainerFilter(FULLY_QUALIFIED_NAME, "ab", false, false); + filterable.addContainerFilter(new SimpleStringFilter( + FULLY_QUALIFIED_NAME, "ab", false, false)); // Must be able to sort based on PROP1 for this test assertTrue(sortable.getSortableContainerPropertyIds().contains( diff --git a/tests/src/com/vaadin/tests/tickets/Ticket1995.java b/tests/src/com/vaadin/tests/tickets/Ticket1995.java index 93f16ca527..c681cb5bd0 100644 --- a/tests/src/com/vaadin/tests/tickets/Ticket1995.java +++ b/tests/src/com/vaadin/tests/tickets/Ticket1995.java @@ -4,6 +4,7 @@ import com.vaadin.Application; import com.vaadin.data.Container; import com.vaadin.data.Container.Filterable; import com.vaadin.data.Item; +import com.vaadin.data.util.filter.SimpleStringFilter; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Table; @@ -30,7 +31,8 @@ public class Ticket1995 extends Application { Filterable filterable = (Container.Filterable) table .getContainerDataSource(); - filterable.addContainerFilter(PROPERTY_1, "Row", true, false); + filterable.addContainerFilter(new SimpleStringFilter(PROPERTY_1, "Row", + true, false)); table.setColumnHeader(PROPERTY_1, "Test (filter: Row)"); @@ -58,7 +60,8 @@ public class Ticket1995 extends Application { getMainWindow().showNotification("Tried to add item 'abc', " + res); - filterable.addContainerFilter(PROPERTY_1, "Row", true, false); + filterable.addContainerFilter(new SimpleStringFilter(PROPERTY_1, "Row", + true, false)); } }