diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-11-25 13:56:36 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-11-28 11:31:40 +0000 |
commit | 411b8dedb02be7ed1a9332fc1f965e583bd313cc (patch) | |
tree | 1de234c9343b5bd5ac524ee465b69669024f79de | |
parent | 24c541c32ce83aff9c4217f5dd9fff1fa816c13e (diff) | |
download | vaadin-framework-411b8dedb02be7ed1a9332fc1f965e583bd313cc.tar.gz vaadin-framework-411b8dedb02be7ed1a9332fc1f965e583bd313cc.zip |
Type Listing for DataProvider to allow custom filter types
Listing has been moved from AbstractListing to each individual Component.
ComboBox is now typed to String filter.
Fixes issues with declarative read of items.
Change-Id: I6918f9f8c426dcbd81546150c2cf9ed49a02bf50
41 files changed, 342 insertions, 165 deletions
diff --git a/server/src/main/java/com/vaadin/data/Listing.java b/server/src/main/java/com/vaadin/data/Listing.java index 8f94296057..527c913912 100644 --- a/server/src/main/java/com/vaadin/data/Listing.java +++ b/server/src/main/java/com/vaadin/data/Listing.java @@ -27,16 +27,19 @@ import com.vaadin.server.data.DataProvider; * * @param <T> * the item data type + * @param <D> + * the data provider type; used to provide constraints on the data + * provider and filter * @since 8.0 */ -public interface Listing<T> extends Serializable { +public interface Listing<T, D extends DataProvider<T, ?>> extends Serializable { /** * Returns the source of data items used by this listing. * * @return the data provider, not null */ - DataProvider<T, ?> getDataProvider(); + D getDataProvider(); /** * Sets the data provider for this listing. The data provider is queried for @@ -45,27 +48,39 @@ public interface Listing<T> extends Serializable { * @param dataProvider * the data provider, not null */ - void setDataProvider(DataProvider<T, ?> dataProvider); + void setDataProvider(D dataProvider); /** * Sets the collection of data items of this listing. + * <p> + * <strong>Note for component developers: </strong> If the component + * implementing this interface uses a custom data provider and/or filter + * types, this method should be overridden to provide the same functionality + * with the correct data provider type. This might require filter conversion + * or a completely custom implementation. * * @param items * the data items to display, not null * */ default void setItems(Collection<T> items) { - setDataProvider(DataProvider.create(items)); + setDataProvider((D) DataProvider.create(items)); } /** * Sets the data items of this listing. + * <p> + * <strong>Note for component developers: </strong> If the component + * implementing this interface uses a custom data provider and/or filter + * types, this method should be overridden to provide the same functionality + * with the correct data provider type. This might require filter conversion + * or a completely custom implementation. * * @param items * the data items to display */ default void setItems(@SuppressWarnings("unchecked") T... items) { - setDataProvider(DataProvider.create(items)); + setDataProvider((D) DataProvider.create(items)); } } diff --git a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java index fbafff6845..88624cee22 100644 --- a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java +++ b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java @@ -47,6 +47,9 @@ import elemental.json.JsonObject; * {@link JsonObject}s representing each data object to be sent to the * client-side. * + * @param <T> + * the bean type + * * @since 8.0 */ public class DataCommunicator<T> extends AbstractExtension { @@ -179,7 +182,9 @@ public class DataCommunicator<T> extends AbstractExtension { private final Collection<DataGenerator<T>> generators = new LinkedHashSet<>(); private final ActiveDataHandler handler = new ActiveDataHandler(); - private DataProvider<T, ?> dataProvider = DataProvider.create(); + /** Empty default data provider */ + private DataProvider<T, ?> dataProvider = new BackEndDataProvider<>( + q -> Stream.of(), q -> 0); private final DataKeyMapper<T> keyMapper; private boolean reset = false; @@ -506,7 +511,7 @@ public class DataCommunicator<T> extends AbstractExtension { * When component is disabled then client cannot communicate to the server * side (by design, because of security reasons). It means that client will * get <b>only</b> initial chunk of data whose size is set here. - * + * * @param size * the size of initial data to send to the client */ @@ -520,9 +525,9 @@ public class DataCommunicator<T> extends AbstractExtension { /** * Get minimum size of data which will be sent to the client when data * source is set. - * + * * @see #setMinPushSize(int) - * + * * @return current minimum push size of initial data chunk which is sent to * the client when data source is set */ diff --git a/server/src/main/java/com/vaadin/ui/AbstractListing.java b/server/src/main/java/com/vaadin/ui/AbstractListing.java index ce44bb8352..8578b18673 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractListing.java +++ b/server/src/main/java/com/vaadin/ui/AbstractListing.java @@ -15,7 +15,6 @@ */ package com.vaadin.ui; -import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -38,16 +37,19 @@ import com.vaadin.ui.declarative.DesignFormatter; /** * A base class for listing components. Provides common handling for fetching * backend data items, selection logic, and server-client communication. + * <p> + * <strong>Note: </strong> concrete component implementations should implement + * the {@link Listing} interface. * * @author Vaadin Ltd. + * @since 8.0 * * @param <T> * the item data type * - * @since 8.0 + * @see Listing */ -public abstract class AbstractListing<T> extends AbstractComponent - implements Listing<T> { +public abstract class AbstractListing<T> extends AbstractComponent { /** * The item icon caption provider. */ @@ -153,13 +155,11 @@ public abstract class AbstractListing<T> extends AbstractComponent addExtension(dataCommunicator); } - @Override - public void setDataProvider(DataProvider<T, ?> dataProvider) { + protected void internalSetDataProvider(DataProvider<T, ?> dataProvider) { getDataCommunicator().setDataProvider(dataProvider); } - @Override - public DataProvider<T, ?> getDataProvider() { + protected DataProvider<T, ?> internalGetDataProvider() { return getDataCommunicator().getDataProvider(); } @@ -277,7 +277,7 @@ public abstract class AbstractListing<T> extends AbstractComponent * the DesignContext instance used in writing */ protected void writeItems(Element design, DesignContext context) { - getDataProvider().fetch(new Query<>()) + internalGetDataProvider().fetch(new Query<>()) .forEach(item -> writeItem(design, item, context)); } @@ -321,21 +321,27 @@ public abstract class AbstractListing<T> extends AbstractComponent setReadOnly(DesignAttributeHandler.readAttribute("readonly", attr, Boolean.class)); } - readItems(design, context); + + setItemCaptionGenerator(new DeclarativeCaptionGenerator<>()); + setItemIconGenerator(new DeclarativeIconGenerator<>()); + + List<T> readItems = readItems(design, context); + if (!readItems.isEmpty() && this instanceof Listing) { + ((Listing<T, ?>) this).setItems(readItems); + } } /** * Reads the data source items from the {@code design}. - * + * * @param design * The element to obtain the state from * @param context * The DesignContext instance used for parsing the design + * + * @return the items read from the design */ - protected void readItems(Element design, DesignContext context) { - setItemCaptionGenerator(new DeclarativeCaptionGenerator<>()); - setItemIconGenerator(new DeclarativeIconGenerator<>()); - } + protected abstract List<T> readItems(Element design, DesignContext context); /** * Reads an Item from a design and inserts it into the data source. @@ -361,13 +367,11 @@ public abstract class AbstractListing<T> extends AbstractComponent String serializedItem = ""; String caption = DesignFormatter.decodeFromTextNode(child.html()); - List<T> items = new ArrayList<>(); if (child.hasAttr("item")) { serializedItem = child.attr("item"); } T item = deserializeDeclarativeRepresentation(serializedItem); - items.add(item); ItemCaptionGenerator<T> captionGenerator = getItemCaptionGenerator(); if (captionGenerator instanceof DeclarativeCaptionGenerator) { @@ -403,9 +407,9 @@ public abstract class AbstractListing<T> extends AbstractComponent * Default implementation is able to handle only {@link String} as an item * type. There will be a {@link ClassCastException} if {@code T } is not a * {@link String}. - * + * * @see #serializeDeclarativeRepresentation(Object) - * + * * @param item * string to deserialize * @throws ClassCastException @@ -420,9 +424,9 @@ public abstract class AbstractListing<T> extends AbstractComponent * Serializes an {@code item} to a string for saving declarative format. * <p> * Default implementation delegates a call to {@code item.toString()}. - * + * * @see #serializeDeclarativeRepresentation(Object) - * + * * @param item * a data item * @return string representation of the {@code item}. diff --git a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java index 5ae0ee4ebd..4bf1ce72e1 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java +++ b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -429,13 +430,14 @@ public abstract class AbstractMultiSelect<T> extends AbstractListing<T> } @Override - protected void readItems(Element design, DesignContext context) { - super.readItems(design, context); + protected List<T> readItems(Element design, DesignContext context) { Set<T> selected = new HashSet<>(); - design.children().stream() - .forEach(child -> readItem(child, selected, context)); + List<T> items = design.children().stream() + .map(child -> readItem(child, selected, context)) + .collect(Collectors.toList()); deselectAll(); selected.forEach(this::select); + return items; } /** diff --git a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java index d2602746fe..0f2d6c81bc 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java +++ b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java @@ -18,9 +18,11 @@ package com.vaadin.ui; import java.lang.reflect.Method; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.jsoup.nodes.Element; @@ -326,12 +328,13 @@ public abstract class AbstractSingleSelect<T> extends AbstractListing<T> } @Override - protected void readItems(Element design, DesignContext context) { - super.readItems(design, context); + protected List<T> readItems(Element design, DesignContext context) { Set<T> selected = new HashSet<>(); - design.children().stream() - .forEach(child -> readItem(child, selected, context)); + List<T> items = design.children().stream() + .map(child -> readItem(child, selected, context)) + .collect(Collectors.toList()); selected.forEach(this::setValue); + return items; } /** diff --git a/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java b/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java index 5098cca628..016b5ca392 100644 --- a/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java +++ b/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java @@ -17,6 +17,7 @@ package com.vaadin.ui; import java.util.Collection; +import java.util.List; import java.util.Set; import org.jsoup.nodes.Element; @@ -46,7 +47,7 @@ import com.vaadin.ui.declarative.DesignFormatter; * @since 8.0 */ public class CheckBoxGroup<T> extends AbstractMultiSelect<T> - implements FocusNotifier, BlurNotifier { + implements FocusNotifier, BlurNotifier, Listing<T, DataProvider<T, ?>> { /** * Constructs a new CheckBoxGroup with caption. @@ -178,9 +179,9 @@ public class CheckBoxGroup<T> extends AbstractMultiSelect<T> } @Override - protected void readItems(Element design, DesignContext context) { + protected List<T> readItems(Element design, DesignContext context) { setItemEnabledProvider(new DeclarativeItemEnabledProvider<>()); - super.readItems(design, context); + return super.readItems(design, context); } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -222,4 +223,14 @@ public class CheckBoxGroup<T> extends AbstractMultiSelect<T> return elem; } + + @Override + public DataProvider<T, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, ?> dataProvider) { + internalSetDataProvider(dataProvider); + } } diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index a932d60423..b9630766cb 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -19,6 +19,7 @@ package com.vaadin.ui; import java.io.Serializable; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -28,6 +29,7 @@ import java.util.function.Consumer; import org.jsoup.nodes.Element; import com.vaadin.data.HasValue; +import com.vaadin.data.Listing; import com.vaadin.event.FieldEvents; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; @@ -60,8 +62,9 @@ import elemental.json.JsonObject; * @author Vaadin Ltd */ @SuppressWarnings("serial") -public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>, - FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { +public class ComboBox<T> extends AbstractSingleSelect<T> + implements HasValue<T>, FieldEvents.BlurNotifier, + FieldEvents.FocusNotifier, Listing<T, DataProvider<T, String>> { /** * Handler that adds a new item based on user input when the new items @@ -90,7 +93,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>, /** * Sets a {@code style} for the {@code item}. - * + * * @param item * a data item * @param style @@ -203,21 +206,9 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>, * collection of options, not null */ public ComboBox(String caption, Collection<T> options) { - this(caption, DataProvider.create(options)); - } - - /** - * Constructs a combo box with the given data provider. - * - * @param caption - * the caption to show in the containing layout, null for no - * caption - * @param dataProvider - * the data provider to use, not null - */ - public ComboBox(String caption, DataProvider<T, ?> dataProvider) { this(caption); - setDataProvider(dataProvider); + + setItems(options); } /** @@ -244,6 +235,22 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>, }); } + @Override + public void setItems(Collection<T> items) { + DataProvider<T, String> provider = DataProvider.create(items) + .convertFilter(filterText -> item -> getFilter() + .apply(filterText, item)); + setDataProvider(provider); + } + + @Override + public void setItems(@SuppressWarnings("unchecked") T... items) { + DataProvider<T, String> provider = DataProvider.create(items) + .convertFilter(filterText -> item -> getFilter() + .apply(filterText, item)); + setDataProvider(provider); + } + /** * Gets the current placeholder text shown when the combo box would be * empty. @@ -577,9 +584,9 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>, } @Override - protected void readItems(Element design, DesignContext context) { + protected List<T> readItems(Element design, DesignContext context) { setStyleGenerator(new DeclarativeStyleGenerator<>()); - super.readItems(design, context); + return super.readItems(design, context); } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -603,4 +610,14 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>, return item; } + @Override + public DataProvider<T, String> getDataProvider() { + return (DataProvider<T, String>) internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, String> dataProvider) { + internalSetDataProvider(dataProvider); + } + } diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 53e22a53d4..e6830f3b95 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -41,6 +41,7 @@ import org.jsoup.nodes.Element; import com.vaadin.data.Binder; import com.vaadin.data.BinderValidationStatus; +import com.vaadin.data.Listing; import com.vaadin.data.SelectionModel; import com.vaadin.event.ConnectorEvent; import com.vaadin.event.ContextClickEvent; @@ -51,6 +52,7 @@ import com.vaadin.server.JsonCodec; import com.vaadin.server.SerializableComparator; import com.vaadin.server.SerializableFunction; import com.vaadin.server.data.DataCommunicator; +import com.vaadin.server.data.DataProvider; import com.vaadin.server.data.SortOrder; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.Registration; @@ -90,7 +92,8 @@ import elemental.json.JsonValue; * @param <T> * the grid bean type */ -public class Grid<T> extends AbstractListing<T> implements HasComponents { +public class Grid<T> extends AbstractListing<T> + implements HasComponents, Listing<T, DataProvider<T, ?>> { @Deprecated private static final Method COLUMN_REORDER_METHOD = ReflectTools.findMethod( @@ -2976,8 +2979,19 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents { } @Override - protected void readItems(Element design, DesignContext context) { + protected List<T> readItems(Element design, DesignContext context) { // TODO see vaadin/framework8-issues#390 + return Collections.emptyList(); + } + + @Override + public DataProvider<T, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, ?> dataProvider) { + internalSetDataProvider(dataProvider); } } diff --git a/server/src/main/java/com/vaadin/ui/ListSelect.java b/server/src/main/java/com/vaadin/ui/ListSelect.java index 00e0d9912d..8716bc4d05 100644 --- a/server/src/main/java/com/vaadin/ui/ListSelect.java +++ b/server/src/main/java/com/vaadin/ui/ListSelect.java @@ -17,6 +17,7 @@ package com.vaadin.ui; import java.util.Collection; +import com.vaadin.data.Listing; import com.vaadin.server.data.DataProvider; import com.vaadin.shared.ui.listselect.ListSelectState; @@ -29,7 +30,8 @@ import com.vaadin.shared.ui.listselect.ListSelectState; * @param <T> * item type */ -public class ListSelect<T> extends AbstractMultiSelect<T> { +public class ListSelect<T> extends AbstractMultiSelect<T> + implements Listing<T, DataProvider<T, ?>> { /** Default number of rows visible for select. */ // protected to allow javadoc linking @@ -121,4 +123,14 @@ public class ListSelect<T> extends AbstractMultiSelect<T> { protected ListSelectState getState(boolean markAsDirty) { return (ListSelectState) super.getState(markAsDirty); } + + @Override + public DataProvider<T, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, ?> dataProvider) { + internalSetDataProvider(dataProvider); + } } diff --git a/server/src/main/java/com/vaadin/ui/NativeSelect.java b/server/src/main/java/com/vaadin/ui/NativeSelect.java index b68ea6c14d..e68dd4fad7 100644 --- a/server/src/main/java/com/vaadin/ui/NativeSelect.java +++ b/server/src/main/java/com/vaadin/ui/NativeSelect.java @@ -18,6 +18,7 @@ package com.vaadin.ui; import java.util.Collection; +import com.vaadin.data.Listing; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; import com.vaadin.event.FieldEvents.BlurNotifier; @@ -43,7 +44,7 @@ import com.vaadin.shared.ui.nativeselect.NativeSelectState; * @see com.vaadin.ui.ComboBox */ public class NativeSelect<T> extends AbstractSingleSelect<T> - implements FocusNotifier, BlurNotifier { + implements FocusNotifier, BlurNotifier, Listing<T, DataProvider<T, ?>> { /** * Creates a new {@code NativeSelect} with an empty caption and no items. @@ -126,4 +127,14 @@ public class NativeSelect<T> extends AbstractSingleSelect<T> protected NativeSelectState getState(boolean markAsDirty) { return (NativeSelectState) super.getState(markAsDirty); } + + @Override + public DataProvider<T, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, ?> dataProvider) { + internalSetDataProvider(dataProvider); + } } diff --git a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java index 5ee3a7b807..325efd0457 100644 --- a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java +++ b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java @@ -17,6 +17,7 @@ package com.vaadin.ui; import java.util.Collection; +import java.util.List; import java.util.Objects; import java.util.Set; @@ -53,7 +54,7 @@ import elemental.json.JsonObject; * @since 8.0 */ public class RadioButtonGroup<T> extends AbstractSingleSelect<T> - implements FocusNotifier, BlurNotifier { + implements FocusNotifier, BlurNotifier, Listing<T, DataProvider<T, ?>> { private SerializablePredicate<T> itemEnabledProvider = item -> true; @@ -247,9 +248,9 @@ public class RadioButtonGroup<T> extends AbstractSingleSelect<T> } @Override - protected void readItems(Element design, DesignContext context) { + protected List<T> readItems(Element design, DesignContext context) { setItemEnabledProvider(new DeclarativeItemEnabledProvider<>()); - super.readItems(design, context); + return super.readItems(design, context); } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -291,4 +292,14 @@ public class RadioButtonGroup<T> extends AbstractSingleSelect<T> return elem; } + + @Override + public DataProvider<T, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, ?> dataProvider) { + internalSetDataProvider(dataProvider); + } } diff --git a/server/src/main/java/com/vaadin/ui/TwinColSelect.java b/server/src/main/java/com/vaadin/ui/TwinColSelect.java index 2d6b97a99a..37b79a6bac 100644 --- a/server/src/main/java/com/vaadin/ui/TwinColSelect.java +++ b/server/src/main/java/com/vaadin/ui/TwinColSelect.java @@ -18,6 +18,7 @@ package com.vaadin.ui; import java.util.Collection; +import com.vaadin.data.Listing; import com.vaadin.server.data.DataProvider; import com.vaadin.shared.ui.twincolselect.TwinColSelectState; @@ -30,7 +31,8 @@ import com.vaadin.shared.ui.twincolselect.TwinColSelectState; * @param <T> * item type */ -public class TwinColSelect<T> extends AbstractMultiSelect<T> { +public class TwinColSelect<T> extends AbstractMultiSelect<T> + implements Listing<T, DataProvider<T, ?>> { /** * Constructs a new TwinColSelect. @@ -156,4 +158,14 @@ public class TwinColSelect<T> extends AbstractMultiSelect<T> { return (TwinColSelectState) super.getState(markAsDirty); } + @Override + public DataProvider<T, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, ?> dataProvider) { + internalSetDataProvider(dataProvider); + } + } diff --git a/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java b/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java index 161d053cca..5d91415193 100644 --- a/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java +++ b/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java @@ -102,11 +102,11 @@ public abstract class DeclarativeTestBaseBase<T extends Component> { protected void assertEquals(String message, Object o1, Object o2) { if (o1 == null) { - Assert.assertEquals(message, null, o2); + Assert.assertNull(message, o2); return; } if (o2 == null) { - Assert.assertEquals(message, null, o1); + Assert.assertNull(message, o1); return; } diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java index c056836dc0..590d7ec8ea 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java @@ -23,6 +23,7 @@ import java.util.List; import org.junit.Test; +import com.vaadin.data.Listing; import com.vaadin.server.ExternalResource; import com.vaadin.server.FileResource; import com.vaadin.server.Resource; @@ -45,9 +46,9 @@ import com.vaadin.ui.ItemCaptionGenerator; * <p> * Common {@link AbstractComponent} properties are tested in * {@link AbstractComponentDeclarativeTestBase} - * + * * @see AbstractComponentDeclarativeTestBase - * + * * @author Vaadin Ltd * * @@ -55,7 +56,7 @@ import com.vaadin.ui.ItemCaptionGenerator; * a component type */ @SuppressWarnings({ "unchecked", "rawtypes" }) -public abstract class AbstractListingDeclarativeTest<T extends AbstractListing> +public abstract class AbstractListingDeclarativeTest<T extends AbstractListing & Listing> extends AbstractComponentDeclarativeTestBase<T> { private static final String EXTERNAL_URL = "http://example.com/example.gif"; diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java index da8127ea8d..53d826592b 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java @@ -22,6 +22,7 @@ import java.util.List; import org.junit.Test; +import com.vaadin.data.Listing; import com.vaadin.tests.server.component.abstractlisting.AbstractListingDeclarativeTest; import com.vaadin.ui.AbstractMultiSelect; @@ -30,17 +31,17 @@ import com.vaadin.ui.AbstractMultiSelect; * <p> * Test inherits test methods from a {@link AbstractListingDeclarativeTest} * class providing here only common cases for {@link AbstractMultiSelect}s. - * + * * @see AbstractListingDeclarativeTest - * + * * @author Vaadin Ltd * * * @param <T> * a component type */ -@SuppressWarnings({ "unchecked", "rawtypes" }) -public abstract class AbstractMultiSelectDeclarativeTest<T extends AbstractMultiSelect> +@SuppressWarnings({ "rawtypes", "unchecked" }) +public abstract class AbstractMultiSelectDeclarativeTest<T extends AbstractMultiSelect & Listing> extends AbstractListingDeclarativeTest<T> { @Override diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java index 48b71ffcf1..1ef1f7addf 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java @@ -22,6 +22,7 @@ import java.util.List; import org.junit.Test; +import com.vaadin.data.Listing; import com.vaadin.tests.server.component.abstractlisting.AbstractListingDeclarativeTest; import com.vaadin.ui.AbstractSingleSelect; import com.vaadin.ui.ItemCaptionGenerator; @@ -31,7 +32,7 @@ import com.vaadin.ui.ItemCaptionGenerator; * <p> * Test inherits test methods from a {@link AbstractListingDeclarativeTest} * class providing here only common cases for {@link AbstractSingleSelect}s. - * + * * @author Vaadin Ltd * * @@ -39,7 +40,7 @@ import com.vaadin.ui.ItemCaptionGenerator; * a component type */ @SuppressWarnings({ "unchecked", "rawtypes" }) -public abstract class AbstractSingleSelectDeclarativeTest<T extends AbstractSingleSelect> +public abstract class AbstractSingleSelectDeclarativeTest<T extends AbstractSingleSelect & Listing> extends AbstractListingDeclarativeTest<T> { @Override diff --git a/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java index c28776f0dc..f94938b765 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java @@ -29,9 +29,9 @@ import com.vaadin.ui.CheckBoxGroup; * Only {@link CheckBoxGroup#setHtmlContentAllowed(boolean)} is tested here * explicitly. All other tests are in the super class ( * {@link AbstractMultiSelectDeclarativeTest}). - * + * * @see AbstractMultiSelectDeclarativeTest - * + * * @author Vaadin Ltd * */ diff --git a/server/src/test/java/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java index d0ec56e0a7..c35af4a6a2 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java @@ -31,9 +31,9 @@ import com.vaadin.ui.StyleGenerator; * <p> * There are only ComboBox specific properties explicit tests. All other tests * are in the super class ( {@link AbstractSingleSelectDeclarativeTest}). - * + * * @see AbstractSingleSelectDeclarativeTest - * + * * @author Vaadin Ltd * */ diff --git a/server/src/test/java/com/vaadin/ui/AbstractListingTest.java b/server/src/test/java/com/vaadin/ui/AbstractListingTest.java index b2f303ae24..369efd6e89 100644 --- a/server/src/test/java/com/vaadin/ui/AbstractListingTest.java +++ b/server/src/test/java/com/vaadin/ui/AbstractListingTest.java @@ -11,6 +11,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.vaadin.data.Listing; import com.vaadin.server.data.BackEndDataProvider; import com.vaadin.server.data.DataProvider; import com.vaadin.server.data.ListDataProvider; @@ -22,7 +23,8 @@ import elemental.json.JsonObject; public class AbstractListingTest { - private final class TestListing extends AbstractSingleSelect<String> { + private final class TestListing extends AbstractSingleSelect<String> + implements Listing<String, DataProvider<String, ?>> { /** * Used to execute data generation @@ -38,7 +40,19 @@ public class AbstractListingTest { } @Override - protected void readItems(Element design, DesignContext context) { + protected List<String> readItems(Element design, + DesignContext context) { + return null; + } + + @Override + public DataProvider<String, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<String, ?> dataProvider) { + internalSetDataProvider(dataProvider); } } diff --git a/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java b/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java index e31e6e28db..ff8d1fcead 100644 --- a/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java +++ b/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java @@ -26,7 +26,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import java.util.stream.Stream; -import com.vaadin.server.data.DataProvider; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -38,22 +37,24 @@ import org.junit.runners.Parameterized.Parameters; import org.mockito.Mockito; import com.vaadin.data.HasValue.ValueChangeEvent; +import com.vaadin.data.Listing; import com.vaadin.event.selection.MultiSelectionEvent; import com.vaadin.event.selection.MultiSelectionListener; +import com.vaadin.server.data.DataProvider; import com.vaadin.shared.Registration; import com.vaadin.shared.data.selection.MultiSelectServerRpc; @RunWith(Parameterized.class) -public class AbstractMultiSelectTest { +public class AbstractMultiSelectTest<S extends AbstractMultiSelect<String> & Listing<String, DataProvider<String, ?>>> { @Parameters(name = "{0}") - public static Iterable<AbstractMultiSelect<String>> multiSelects() { + public static Iterable<?> multiSelects() { return Arrays.asList(new CheckBoxGroup<>(), new TwinColSelect<>(), new ListSelect<>()); } @Parameter - public AbstractMultiSelect<String> selectToTest; + public S selectToTest; private MultiSelectServerRpc rpc; diff --git a/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java b/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java index 4ea3fdcfa0..ee129d0e0a 100644 --- a/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java +++ b/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java @@ -32,8 +32,10 @@ import org.junit.Test; import org.mockito.Mockito; import com.vaadin.data.HasValue.ValueChangeEvent; +import com.vaadin.data.Listing; import com.vaadin.event.selection.SingleSelectionEvent; import com.vaadin.event.selection.SingleSelectionListener; +import com.vaadin.server.data.DataProvider; import com.vaadin.server.data.provider.bov.Person; import com.vaadin.shared.Registration; import com.vaadin.shared.data.DataCommunicatorClientRpc; @@ -48,7 +50,8 @@ public class AbstractSingleSelectTest { private List<Person> selectionChanges; - private static class PersonListing extends AbstractSingleSelect<Person> { + private static class PersonListing extends AbstractSingleSelect<Person> + implements Listing<Person, DataProvider<Person, ?>> { @Override protected Element writeItem(Element design, Person item, @@ -57,7 +60,19 @@ public class AbstractSingleSelectTest { } @Override - protected void readItems(Element design, DesignContext context) { + protected List<Person> readItems(Element design, + DesignContext context) { + return null; + } + + @Override + public DataProvider<Person, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<Person, ?> dataProvider) { + internalSetDataProvider(dataProvider); } } @@ -240,7 +255,9 @@ public class AbstractSingleSelectTest { } @Override - protected void readItems(Element design, DesignContext context) { + protected List<String> readItems(Element design, + DesignContext context) { + return null; } }; diff --git a/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java b/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java index 0d5ed54180..7e35bbb386 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java @@ -21,6 +21,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import com.googlecode.gentyref.GenericTypeReflector; +import com.vaadin.data.Listing; import com.vaadin.event.FieldEvents.BlurNotifier; import com.vaadin.event.FieldEvents.FocusNotifier; import com.vaadin.server.VaadinRequest; @@ -30,7 +31,7 @@ import com.vaadin.ui.AbstractListing; * @author Vaadin Ltd * */ -public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Integer> & FocusNotifier & BlurNotifier> +public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Integer> & FocusNotifier & BlurNotifier & Listing<Integer, ?>> extends AbstractTestUIWithLog { @Override @@ -42,19 +43,16 @@ public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Int valueType = ((ParameterizedType) valueType).getRawType(); } if (valueType instanceof Class<?>) { - Class<?> clazz = (Class<?>) valueType; + Class<T> clazz = (Class<T>) valueType; try { - AbstractListing<Integer> select = (AbstractListing<Integer>) clazz - .newInstance(); + T select = clazz.newInstance(); select.setItems( IntStream.range(1, 10).mapToObj(Integer::valueOf) .collect(Collectors.toList())); addComponent(select); - ((FocusNotifier) select) - .addFocusListener(event -> log("Focus Event")); - ((BlurNotifier) select) - .addBlurListener(event -> log("Blur Event")); + select.addFocusListener(event -> log("Focus Event")); + select.addBlurListener(event -> log("Blur Event")); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractListingTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractListingTestUI.java index 9d2ca4f6ea..8a46738e5d 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractListingTestUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractListingTestUI.java @@ -4,11 +4,12 @@ import java.util.LinkedHashMap; import java.util.stream.IntStream; import com.vaadin.annotations.Widgetset; +import com.vaadin.data.Listing; import com.vaadin.tests.components.AbstractComponentTest; import com.vaadin.ui.AbstractListing; @Widgetset("com.vaadin.DefaultWidgetSet") -public abstract class AbstractListingTestUI<T extends AbstractListing<Object>> +public abstract class AbstractListingTestUI<T extends AbstractListing<Object> & Listing<Object, ?>> extends AbstractComponentTest<T> { @Override diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractMultiSelectTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractMultiSelectTestUI.java index 0037f0f2d1..2417bdfcde 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractMultiSelectTestUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractMultiSelectTestUI.java @@ -5,10 +5,11 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; +import com.vaadin.data.Listing; import com.vaadin.ui.AbstractMultiSelect; import com.vaadin.ui.ItemCaptionGenerator; -public abstract class AbstractMultiSelectTestUI<MULTISELECT extends AbstractMultiSelect<Object>> +public abstract class AbstractMultiSelectTestUI<MULTISELECT extends AbstractMultiSelect<Object> & Listing<Object, ?>> extends AbstractListingTestUI<MULTISELECT> { protected final String selectionCategory = "Selection"; diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractSingleSelectTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractSingleSelectTestUI.java index 2fa6abced8..544cc73dc7 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractSingleSelectTestUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractSingleSelectTestUI.java @@ -17,9 +17,10 @@ package com.vaadin.tests.components.abstractlisting; import java.util.LinkedHashMap; +import com.vaadin.data.Listing; import com.vaadin.ui.AbstractSingleSelect; -public abstract class AbstractSingleSelectTestUI<T extends AbstractSingleSelect<Object>> +public abstract class AbstractSingleSelectTestUI<T extends AbstractSingleSelect<Object> & Listing<Object, ?>> extends AbstractListingTestUI<T> { @Override @@ -31,8 +32,9 @@ public abstract class AbstractSingleSelectTestUI<T extends AbstractSingleSelect< } protected void createListenerMenu() { - createListenerAction("Selection listener", "Listeners", c -> c - .addSelectionChangeListener(e -> log("Selected: " + e.getValue()))); + createListenerAction("Selection listener", "Listeners", + c -> c.addSelectionChangeListener( + e -> log("Selected: " + e.getValue()))); } protected void createSelectionMenu() { diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxClickIcon.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxClickIcon.java index d6d0c78ea6..fe1d4c4670 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxClickIcon.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxClickIcon.java @@ -17,7 +17,6 @@ package com.vaadin.tests.components.combobox; import com.vaadin.server.FontAwesome; import com.vaadin.server.VaadinRequest; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.AbstractReindeerTestUI; import com.vaadin.ui.ComboBox; @@ -30,8 +29,8 @@ public class ComboBoxClickIcon extends AbstractReindeerTestUI { @Override protected void setup(VaadinRequest request) { - final ComboBox<String> combo = new ComboBox<>(null, - DataProvider.create("A", "B", "C")); + final ComboBox<String> combo = new ComboBox<>(); + combo.setItems("A", "B", "C"); combo.setItemIconGenerator(item -> FontAwesome.ALIGN_CENTER); combo.setTextInputAllowed(false); addComponent(combo); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java index 90d6ad74a1..e027c01416 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java @@ -1,15 +1,15 @@ package com.vaadin.tests.components.combobox; import com.vaadin.server.VaadinRequest; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.AbstractReindeerTestUI; import com.vaadin.ui.ComboBox; -public class ComboBoxEmptyItemsKeyboardNavigation extends AbstractReindeerTestUI { +public class ComboBoxEmptyItemsKeyboardNavigation + extends AbstractReindeerTestUI { @Override protected void setup(VaadinRequest request) { - ComboBox<String> comboBox = new ComboBox<>(null, - DataProvider.create("foo", "bar")); + ComboBox<String> comboBox = new ComboBox<>(); + comboBox.setItems("foo", "bar"); addComponent(comboBox); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java index c6ff7496af..b0c4a375f7 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java @@ -10,11 +10,11 @@ public class ComboBoxEnablesComboBox extends TestBase { @Override protected void setup() { - ComboBox<String> cb = new ComboBox<>("Always enabled", - new ItemDataProvider(10)); + ComboBox<String> cb = new ComboBox<>("Always enabled"); + cb.setDataProvider(new ItemDataProvider(10)); cb.addValueChangeListener(event -> cb2.setEnabled(true)); - cb2 = new ComboBox<String>("Initially disabled", - new ItemDataProvider(10)); + cb2 = new ComboBox<String>("Initially disabled"); + cb.setDataProvider(new ItemDataProvider(10)); cb2.setEnabled(false); addComponent(cb); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInPopup.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInPopup.java index fdb97f3402..e2f79e6a6c 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInPopup.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInPopup.java @@ -1,7 +1,6 @@ package com.vaadin.tests.components.combobox; import com.vaadin.event.ShortcutAction.KeyCode; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -35,8 +34,9 @@ public class ComboBoxInPopup extends TestBase { } private Component createComboBox() { - return new ComboBox<String>("A combo box", - DataProvider.create("Yes", "No", "Maybe")); + ComboBox<String> comboBox = new ComboBox<String>("A combo box"); + comboBox.setItems("Yes", "No", "Maybe"); + return comboBox; } @Override diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInvalidNullSelection.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInvalidNullSelection.java index 669311149c..9a71cfb046 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInvalidNullSelection.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxInvalidNullSelection.java @@ -1,6 +1,5 @@ package com.vaadin.tests.components.combobox; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; @@ -8,28 +7,25 @@ import com.vaadin.ui.ComboBox; public class ComboBoxInvalidNullSelection extends TestBase { - private DataProvider<String, ?> ds1; - private DataProvider<String, ?> ds2; + private boolean biggerData = true; private ComboBox<String> combo; private Log log = new Log(5); @Override protected void setup() { - createDataProviders(); - Button b = new Button("Swap data provider"); b.addClickListener(event -> { - if (combo.getDataProvider() == ds1) { - combo.setDataProvider(ds2); + if (biggerData) { + combo.setItems("Item 3"); } else { - combo.setDataProvider(ds1); + combo.setItems("Item 1", "Item 2", "Item 3", "Item 4"); } - combo.setValue("Item 3"); + biggerData = !biggerData; }); combo = new ComboBox<>(); - combo.setDataProvider(ds1); + combo.setItems("Item 1", "Item 2", "Item 3", "Item 4"); combo.addValueChangeListener( event -> log.log("Value is now: " + combo.getValue())); addComponent(log); @@ -38,13 +34,6 @@ public class ComboBoxInvalidNullSelection extends TestBase { addComponent(new Button("Dummy for TestBench")); } - private void createDataProviders() { - ds1 = DataProvider.create("Item 1", "Item 2", "Item 3", "Item 4"); - - ds2 = DataProvider.create("Item 3"); - - } - @Override protected String getDescription() { return "Select \"Item 3\" in the ComboBox, change the data provider, focus and blur the ComboBox. The value should temporarily change to null when changing data provider but not when focusing and blurring the ComboBox"; diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxLargeIcons.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxLargeIcons.java index 1909a90c92..6da366ac1a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxLargeIcons.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxLargeIcons.java @@ -3,7 +3,6 @@ package com.vaadin.tests.components.combobox; import java.util.Date; import com.vaadin.server.ThemeResource; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.ComboBox; @@ -21,12 +20,12 @@ public class ComboBoxLargeIcons extends TestBase { @Override protected void setup() { - ComboBox<String> cb = new ComboBox<String>(null, - DataProvider.create("folder-add", "folder-delete", "arrow-down", - "arrow-left", "arrow-right", "arrow-up", "document-add", - "document-delete", "document-doc", "document-edit", - "document-image", "document-pdf", "document-ppt", - "document-txt", "document-web", "document")); + ComboBox<String> cb = new ComboBox<String>(); + cb.setItems("folder-add", "folder-delete", "arrow-down", "arrow-left", + "arrow-right", "arrow-up", "document-add", "document-delete", + "document-doc", "document-edit", "document-image", + "document-pdf", "document-ppt", "document-txt", "document-web", + "document"); getLayout().addComponent(cb); // FIXME cb.setNullSelectionAllowed(false); cb.setItemIconGenerator(icon -> new ThemeResource( diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java index f77de3650c..f3217858a8 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java @@ -37,7 +37,8 @@ public class ComboBoxMousewheel extends AbstractReindeerTestUI { } private ComboBox<String> createComboBox(String caption) { - ComboBox<String> cb = new ComboBox<>(caption, new ItemDataProvider(100)); + ComboBox<String> cb = new ComboBox<>(caption); + cb.setDataProvider(new ItemDataProvider(100)); cb.setId(caption); return cb; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java index bc5144a7bf..8eef1cafc0 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java @@ -18,7 +18,8 @@ public class ComboBoxNavigation extends TestBase { @Override protected void setup() { - ComboBox<String> cb = new ComboBox<>(null, new ItemDataProvider(100)); + ComboBox<String> cb = new ComboBox<>(); + cb.setDataProvider(new ItemDataProvider(100)); addComponent(cb); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java index 04636a3f4f..893ee75d9b 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java @@ -29,7 +29,8 @@ public class ComboBoxPopupWhenBodyScrolls extends AbstractReindeerTestUI { .add("body.v-generated-body { overflow: auto;height:auto;}"); getPage().getStyles().add( "body.v-generated-body .v-ui.v-scrollable{ overflow: visible;height:auto !important;}"); - ComboBox<String> cb = new ComboBox<>(null, new ItemDataProvider(10)); + ComboBox<String> cb = new ComboBox<>(); + cb.setDataProvider(new ItemDataProvider(10)); Label spacer = new Label("foo"); spacer.setHeight("2000px"); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java index 10ec271745..b3b50c9b27 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java @@ -8,7 +8,8 @@ import com.vaadin.ui.ComboBox; public class ComboBoxUndefinedWidthAndIcon extends TestBase { @Override protected void setup() { - ComboBox<String> cb = new ComboBox<>(null, new ItemDataProvider(200)); + ComboBox<String> cb = new ComboBox<>(); + cb.setDataProvider(new ItemDataProvider(200)); cb.setItemIconGenerator( item -> new ThemeResource("../runo/icons/16/users.png")); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java index 9ab060e702..8679ed7785 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java @@ -15,8 +15,8 @@ public class ComboFocusBlurEvents extends TestBase { @Override protected void setup() { - ComboBox<String> cb = new ComboBox<>("Combobox", - new ItemDataProvider(100)); + ComboBox<String> cb = new ComboBox<>("Combobox"); + cb.setDataProvider(new ItemDataProvider(100)); cb.setPlaceholder("Enter text"); cb.setDescription("Some Combobox"); addComponent(cb); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxMenuBarAutoopen.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxMenuBarAutoopen.java index 3d5a2ad3c9..0d2d8535dd 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxMenuBarAutoopen.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxMenuBarAutoopen.java @@ -17,7 +17,6 @@ package com.vaadin.tests.components.combobox; import com.vaadin.server.Page; import com.vaadin.server.VaadinRequest; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.AbstractReindeerTestUI; import com.vaadin.ui.ComboBox; import com.vaadin.ui.HorizontalLayout; @@ -37,8 +36,8 @@ public class ComboboxMenuBarAutoopen extends AbstractReindeerTestUI { protected void setup(VaadinRequest request) { HorizontalLayout layout = new HorizontalLayout(); layout.setSpacing(true); - ComboBox<String> combo = new ComboBox<>(null, - DataProvider.create("1", "2", "3")); + ComboBox<String> combo = new ComboBox<>(); + combo.setItems("1", "2", "3"); layout.addComponent(combo); MenuBar menubar = getMenubar(); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxPrimaryStyleNames.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxPrimaryStyleNames.java index 7e78036d56..a8090502c7 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxPrimaryStyleNames.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxPrimaryStyleNames.java @@ -1,6 +1,5 @@ package com.vaadin.tests.components.combobox; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; @@ -9,8 +8,8 @@ public class ComboboxPrimaryStyleNames extends TestBase { @Override protected void setup() { - final ComboBox<String> box = new ComboBox(null, - DataProvider.create("Value 1", "Value 2", "Value 3", "Value 4")); + final ComboBox<String> box = new ComboBox(); + box.setItems("Value 1", "Value 2", "Value 3", "Value 4"); box.setPrimaryStyleName("my-combobox"); addComponent(box); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxStyleChangeWidth.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxStyleChangeWidth.java index 6d5f02be48..b3703f6cc4 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxStyleChangeWidth.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxStyleChangeWidth.java @@ -16,7 +16,6 @@ package com.vaadin.tests.components.combobox; import com.vaadin.server.VaadinRequest; -import com.vaadin.server.data.DataProvider; import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; @@ -30,8 +29,9 @@ public class ComboboxStyleChangeWidth extends AbstractTestUIWithLog { @Override protected void setup(VaadinRequest request) { - final ComboBox<String> cbFoo = new ComboBox<>(null, DataProvider.create( - "A really long string that causes an inline width to be set")); + final ComboBox<String> cbFoo = new ComboBox<>(); + cbFoo.setItems( + "A really long string that causes an inline width to be set"); cbFoo.setSizeUndefined(); Button btn = new Button("Click to break CB", diff --git a/uitest/src/main/java/com/vaadin/tests/data/DummyData.java b/uitest/src/main/java/com/vaadin/tests/data/DummyData.java index fdf8a710d0..f973fde0b9 100644 --- a/uitest/src/main/java/com/vaadin/tests/data/DummyData.java +++ b/uitest/src/main/java/com/vaadin/tests/data/DummyData.java @@ -8,7 +8,9 @@ import java.util.Optional; import java.util.stream.Stream; import com.vaadin.annotations.Widgetset; +import com.vaadin.data.Listing; import com.vaadin.server.VaadinRequest; +import com.vaadin.server.data.DataProvider; import com.vaadin.server.data.ListDataProvider; import com.vaadin.server.data.Query; import com.vaadin.shared.data.DataCommunicatorConstants; @@ -42,7 +44,8 @@ public class DummyData extends AbstractTestUIWithLog { * Simplified server only selection model. Selection state passed in data, * shown as bold text. */ - public static class DummyComponent extends AbstractSingleSelect<String> { + public static class DummyComponent extends AbstractSingleSelect<String> + implements Listing<String, DataProvider<String, ?>> { private String selected; @@ -71,6 +74,16 @@ public class DummyData extends AbstractTestUIWithLog { } } + @Override + public DataProvider<String, ?> getDataProvider() { + return internalGetDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<String, ?> dataProvider) { + internalSetDataProvider(dataProvider); + } + } @Override @@ -92,7 +105,8 @@ public class DummyData extends AbstractTestUIWithLog { dummy.setDataProvider(new LoggingDataProvider(items)); })); controls.addComponent(new Button("Remove all data", e -> { - dummy.setDataProvider(new LoggingDataProvider(Collections.emptyList())); + dummy.setDataProvider( + new LoggingDataProvider(Collections.emptyList())); })); addComponent(dummy); } diff --git a/uitest/src/main/java/com/vaadin/tests/util/ItemDataProvider.java b/uitest/src/main/java/com/vaadin/tests/util/ItemDataProvider.java index 8b77f4cd2a..f050d1f454 100644 --- a/uitest/src/main/java/com/vaadin/tests/util/ItemDataProvider.java +++ b/uitest/src/main/java/com/vaadin/tests/util/ItemDataProvider.java @@ -1,21 +1,41 @@ package com.vaadin.tests.util; +import java.util.Locale; import java.util.stream.IntStream; +import java.util.stream.Stream; import com.vaadin.server.data.BackEndDataProvider; +import com.vaadin.server.data.Query; /** * A data provider for tests that creates "Item n" strings on the fly. * * @author Vaadin Ltd */ -public class ItemDataProvider extends BackEndDataProvider<String, Object> { +public class ItemDataProvider extends BackEndDataProvider<String, String> { public ItemDataProvider(int size) { - super(q -> IntStream - .range(q.getOffset(), - Math.max(q.getOffset() + q.getLimit() + 1, size)) - .mapToObj(i -> "Item " + i), q -> size); + super(q -> itemStream(q, size).skip(q.getOffset()).limit(q.getLimit()), + q -> size(q, size)); } + private static Stream<String> itemStream(Query<String> q, int size) { + Stream<String> stream = IntStream.range(0, size) + .mapToObj(i -> "Item " + i); + String filterText = q.getFilter().orElse("").toLowerCase(Locale.US); + + if (filterText.isEmpty()) { + return stream; + } + + return stream.filter( + text -> text.toLowerCase(Locale.US).contains(filterText)); + } + + private static int size(Query<String> q, int size) { + if (!q.getFilter().orElse("").isEmpty()) { + return (int) itemStream(q, size).count(); + } + return size; + } } |