diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-11-02 14:16:53 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-11-04 12:02:50 +0000 |
commit | b6960abff449a5cf6cb858f3102bc37dfab3fcc2 (patch) | |
tree | 5d6817b78db68ec377278126c5c205cc00cf3f44 /uitest/src | |
parent | 9e10d5d29cc091f7bab62091ebf955891ec28188 (diff) | |
download | vaadin-framework-b6960abff449a5cf6cb858f3102bc37dfab3fcc2.tar.gz vaadin-framework-b6960abff449a5cf6cb858f3102bc37dfab3fcc2.zip |
Create MultiSelect interface to replace Multi selection model.
Fixes vaadin/framework8-issues#423
Change-Id: Ifd252b8feed323708a7ae73af2b836832570d192
Diffstat (limited to 'uitest/src')
10 files changed, 67 insertions, 99 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 f953c3acac..0d5ed54180 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java @@ -21,7 +21,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import com.googlecode.gentyref.GenericTypeReflector; -import com.vaadin.data.SelectionModel; import com.vaadin.event.FieldEvents.BlurNotifier; import com.vaadin.event.FieldEvents.FocusNotifier; import com.vaadin.server.VaadinRequest; @@ -31,7 +30,7 @@ import com.vaadin.ui.AbstractListing; * @author Vaadin Ltd * */ -public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Integer, S> & FocusNotifier & BlurNotifier, S extends SelectionModel<Integer>> +public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Integer> & FocusNotifier & BlurNotifier> extends AbstractTestUIWithLog { @Override @@ -45,7 +44,7 @@ public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Int if (valueType instanceof Class<?>) { Class<?> clazz = (Class<?>) valueType; try { - AbstractListing<Integer, ?> select = (AbstractListing<Integer, ?>) clazz + AbstractListing<Integer> select = (AbstractListing<Integer>) clazz .newInstance(); select.setItems( IntStream.range(1, 10).mapToObj(Integer::valueOf) 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 875c7d886f..126eb4bf33 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 @@ -8,7 +8,7 @@ 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>> 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 ae69cbb6ff..89f9f9e0ea 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,7 +5,6 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; -import com.vaadin.data.SelectionModel.Multi; import com.vaadin.ui.AbstractMultiSelect; import com.vaadin.ui.ItemCaptionGenerator; @@ -38,10 +37,8 @@ public abstract class AbstractMultiSelectTestUI<MULTISELECT extends AbstractMult } protected void createSelectionMenu() { - createClickAction( - "Clear selection", selectionCategory, (component, item, - data) -> component.getSelectionModel().deselectAll(), - ""); + createClickAction("Clear selection", selectionCategory, + (component, item, data) -> component.deselectAll(), ""); Command<MULTISELECT, String> toggleSelection = (component, item, data) -> toggleSelection(item); @@ -59,20 +56,18 @@ public abstract class AbstractMultiSelectTestUI<MULTISELECT extends AbstractMult } private void toggleSelection(String item) { - Multi<Object> selectionModel = getComponent().getSelectionModel(); - if (selectionModel.isSelected(item)) { - selectionModel.deselect(item); + if (getComponent().isSelected(item)) { + getComponent().deselect(item); } else { - selectionModel.select(item); + getComponent().select(item); } } private void toggleMultiSelection(boolean add, List<String> items) { - Multi<Object> selectionModel = getComponent().getSelectionModel(); if (add) { - selectionModel.selectItems(items.toArray()); + getComponent().select(items.toArray()); } else { - selectionModel.deselectItems(items.toArray()); + getComponent().deselect(items.toArray()); } } 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 f9529ff2e3..a3c43adc1f 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 @@ -45,11 +45,12 @@ public abstract class AbstractSingleSelectTestUI<T extends AbstractSingleSelect< options.put("Item 100", "Item 100"); createSelectAction("Select", "Selection", options, "None", - (c, selected, data) -> { + (component, selected, data) -> { if (selected != null) { - c.select(selected); + component.select(selected); } else { - c.getSelectedItems().forEach(c::deselect); + component.getSelectedItem() + .ifPresent(component::deselect); } }); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java index b92132d9f7..d6d288b77d 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java +++ b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java @@ -15,7 +15,6 @@ */ package com.vaadin.tests.components.checkboxgroup; -import com.vaadin.data.SelectionModel.Multi; import com.vaadin.tests.components.AbstractListingFocusBlurTest; import com.vaadin.ui.CheckBoxGroup; @@ -28,7 +27,7 @@ import com.vaadin.ui.CheckBoxGroup; * @author Vaadin Ltd * */ -public class CheckBoxGroupFocusBlur extends - AbstractListingFocusBlurTest<CheckBoxGroup<Integer>, Multi<Integer>> { +public class CheckBoxGroupFocusBlur + extends AbstractListingFocusBlurTest<CheckBoxGroup<Integer>> { } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java index 4e9b154628..96a2f313b9 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java @@ -233,11 +233,9 @@ public class GridBasics extends AbstractTestUIWithLog { MenuItem headerTypeMenu = columnMenu.addItem("Header Type", null); headerTypeMenu.addItem("Text Header", selectedItem -> grid .getDefaultHeaderRow().getCell(col).setText("Text Header")); - headerTypeMenu - .addItem("HTML Header", - selectedItem -> grid.getDefaultHeaderRow() - .getCell(col) - .setHtml("<b>HTML Header</b>")); + headerTypeMenu.addItem("HTML Header", + selectedItem -> grid.getDefaultHeaderRow().getCell(col) + .setHtml("<b>HTML Header</b>")); headerTypeMenu.addItem("Widget Header", selectedItem -> { final Button button = new Button("Button Header"); button.addClickListener(clickEvent -> log("Button clicked!")); @@ -293,15 +291,12 @@ public class GridBasics extends AbstractTestUIWithLog { : null)) .setCheckable(true); stateMenu - .addItem("Cell description generator", - item -> grid.getColumns().stream().findFirst() - .ifPresent( - c -> c.setDescriptionGenerator( - item.isChecked() - ? t -> "Cell tooltip for row " - + t.getRowNumber() - + ", Column 0" - : null))) + .addItem("Cell description generator", item -> grid.getColumns() + .stream().findFirst() + .ifPresent(c -> c.setDescriptionGenerator( + item.isChecked() ? t -> "Cell tooltip for row " + + t.getRowNumber() + ", Column 0" + : null))) .setCheckable(true); stateMenu.addItem("Item click listener", new Command() { @@ -393,10 +388,10 @@ public class GridBasics extends AbstractTestUIWithLog { private void createBodyMenu(MenuItem rowMenu) { rowMenu.addItem("Toggle first row selection", menuItem -> { DataObject item = data.get(0); - if (grid.isSelected(item)) { - grid.deselect(item); + if (grid.getSelectionModel().isSelected(item)) { + grid.getSelectionModel().deselect(item); } else { - grid.select(item); + grid.getSelectionModel().select(item); } }); } @@ -432,10 +427,9 @@ public class GridBasics extends AbstractTestUIWithLog { private void createFooterMenu(MenuItem footerMenu) { footerMenu.addItem("Add default footer row", menuItem -> { FooterRow defaultFooter = grid.appendFooterRow(); - grid.getColumns() - .forEach(column -> defaultFooter.getCell(column) - .setText(grid.getDefaultHeaderRow().getCell(column) - .getText())); + grid.getColumns().forEach( + column -> defaultFooter.getCell(column).setText(grid + .getDefaultHeaderRow().getCell(column).getText())); footerMenu.removeChild(menuItem); }); footerMenu.addItem("Append footer row", menuItem -> { diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java index b2664f892b..d0996612ec 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java +++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java @@ -16,7 +16,6 @@ package com.vaadin.tests.components.nativeselect; import com.vaadin.tests.components.AbstractListingFocusBlurTest; -import com.vaadin.ui.AbstractSingleSelect; import com.vaadin.ui.NativeSelect; /** @@ -28,7 +27,7 @@ import com.vaadin.ui.NativeSelect; * @author Vaadin Ltd * */ -public class NativeSelectFocusBlur extends - AbstractListingFocusBlurTest<NativeSelect<Integer>, AbstractSingleSelect<Integer>.AbstractSingleSelection> { +public class NativeSelectFocusBlur + extends AbstractListingFocusBlurTest<NativeSelect<Integer>> { } diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java index 3d8802c5ed..7230eb9017 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java @@ -15,15 +15,14 @@ */ package com.vaadin.tests.components.radiobutton; -import com.vaadin.data.SelectionModel; +import java.util.LinkedHashMap; +import java.util.stream.IntStream; + import com.vaadin.server.FontAwesome; import com.vaadin.tests.components.abstractlisting.AbstractListingTestUI; import com.vaadin.ui.ItemCaptionGenerator; import com.vaadin.ui.RadioButtonGroup; -import java.util.LinkedHashMap; -import java.util.stream.IntStream; - /** * Test UI for RadioButtonGroup component * @@ -50,9 +49,9 @@ public class RadioButtonGroupTestUI } protected void createSelectionMenu() { - createClickAction( - "Clear selection", selectionCategory, (component, item, - data) -> component.getSelectionModel().deselectAll(), + createClickAction("Clear selection", selectionCategory, + (component, item, data) -> component.getSelectedItem() + .ifPresent(component::deselect), ""); Command<RadioButtonGroup<Object>, String> toggleSelection = (component, @@ -62,13 +61,14 @@ public class RadioButtonGroupTestUI .forEach(item -> createClickAction("Toggle " + item, selectionCategory, toggleSelection, item)); } + private void createItemIconGeneratorMenu() { - createBooleanAction("Use Item Icon Generator", "Item Icon Generator", false, - this::useItemIconGenerator); + createBooleanAction("Use Item Icon Generator", "Item Icon Generator", + false, this::useItemIconGenerator); } private void useItemIconGenerator(RadioButtonGroup<Object> group, - boolean activate, Object data) { + boolean activate, Object data) { if (activate) { group.setItemIconGenerator( item -> FontAwesome.values()[getIndex(item) + 1]); @@ -85,20 +85,18 @@ public class RadioButtonGroupTestUI options.put("Custom Caption Generator", item -> item.toString() + " Caption"); - createSelectAction("Item Caption Generator", "Item Caption Generator", options, - "None", (radioButtonGroup, captionGenerator, data) -> { + createSelectAction("Item Caption Generator", "Item Caption Generator", + options, "None", (radioButtonGroup, captionGenerator, data) -> { radioButtonGroup.setItemCaptionGenerator(captionGenerator); radioButtonGroup.getDataSource().refreshAll(); }, true); } private void toggleSelection(String item) { - SelectionModel.Single<Object> selectionModel = getComponent() - .getSelectionModel(); - if (selectionModel.isSelected(item)) { - selectionModel.deselect(item); + if (getComponent().isSelected(item)) { + getComponent().deselect(item); } else { - selectionModel.select(item); + getComponent().select(item); } } @@ -108,7 +106,6 @@ public class RadioButtonGroupTestUI e -> log("Selected: " + e.getSelectedItem()))); } - private int getIndex(Object item) { int index = item.toString().indexOf(' '); if (index < 0) { diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java index 02238e5ef4..1977ed5665 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java +++ b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java @@ -16,7 +16,6 @@ package com.vaadin.tests.components.radiobuttongroup; import com.vaadin.tests.components.AbstractListingFocusBlurTest; -import com.vaadin.ui.AbstractSingleSelect; import com.vaadin.ui.RadioButtonGroup; /** @@ -28,7 +27,7 @@ import com.vaadin.ui.RadioButtonGroup; * @author Vaadin Ltd * */ -public class RadioButtonGroupFocusBlur extends - AbstractListingFocusBlurTest<RadioButtonGroup<Integer>, AbstractSingleSelect<Integer>.AbstractSingleSelection> { +public class RadioButtonGroupFocusBlur + extends AbstractListingFocusBlurTest<RadioButtonGroup<Integer>> { } 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 d0ba74a942..7157a205f4 100644 --- a/uitest/src/main/java/com/vaadin/tests/data/DummyData.java +++ b/uitest/src/main/java/com/vaadin/tests/data/DummyData.java @@ -4,19 +4,17 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Set; +import java.util.Optional; import java.util.stream.Stream; import com.vaadin.annotations.Widgetset; -import com.vaadin.data.SelectionModel; import com.vaadin.server.VaadinRequest; -import com.vaadin.server.data.DataCommunicator; import com.vaadin.server.data.ListDataSource; import com.vaadin.server.data.Query; import com.vaadin.shared.data.DataCommunicatorConstants; import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.ui.AbstractListing; +import com.vaadin.ui.AbstractSingleSelect; import com.vaadin.ui.Button; import com.vaadin.ui.HorizontalLayout; @@ -44,26 +42,32 @@ public class DummyData extends AbstractTestUIWithLog { * Simplified server only selection model. Selection state passed in data, * shown as bold text. */ - private static class DummySelectionModel implements SelectionModel<String> { + public static class DummyComponent extends AbstractSingleSelect<String> { + private String selected; - private DataCommunicator<String> communicator; + + private DummyComponent() { + addDataGenerator((str, json) -> { + json.put(DataCommunicatorConstants.DATA, str); + if (isSelected(str)) { + json.put(DataCommunicatorConstants.SELECTED, true); + } + }); + } @Override - public Set<String> getSelectedItems() { - if (selected != null) { - return Collections.singleton(selected); - } - return Collections.emptySet(); + public Optional<String> getSelectedItem() { + return Optional.ofNullable(selected); } @Override public void select(String item) { if (selected != null) { - communicator.refresh(selected); + getDataCommunicator().refresh(selected); } selected = item; if (selected != null) { - communicator.refresh(selected); + getDataCommunicator().refresh(selected); } } @@ -73,25 +77,6 @@ public class DummyData extends AbstractTestUIWithLog { select(null); } } - - private void setCommunicator(DataCommunicator<String> dataComm) { - communicator = dataComm; - } - } - - public static class DummyComponent - extends AbstractListing<String, DummySelectionModel> { - - private DummyComponent() { - setSelectionModel(new DummySelectionModel()); - addDataGenerator((str, json) -> { - json.put(DataCommunicatorConstants.DATA, str); - if (isSelected(str)) { - json.put(DataCommunicatorConstants.SELECTED, true); - } - }); - getSelectionModel().setCommunicator(getDataCommunicator()); - } } @Override |