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 /uitest | |
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
Diffstat (limited to 'uitest')
20 files changed, 98 insertions, 73 deletions
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; + } } |