aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/ui/ComboBox.java
diff options
context:
space:
mode:
authorLeif Åstrand <legioth@gmail.com>2017-01-22 21:50:46 +0200
committerGitHub <noreply@github.com>2017-01-22 21:50:46 +0200
commit5447e7e05392483455f7df4bf2af5d5d74e5a2ae (patch)
tree5028592fea2d9f1dda0c23d1448b92b8a35dc6fd /server/src/main/java/com/vaadin/ui/ComboBox.java
parent19427ba7c7a51d3af61c170a7ba54137eb629ac8 (diff)
downloadvaadin-framework-5447e7e05392483455f7df4bf2af5d5d74e5a2ae.tar.gz
vaadin-framework-5447e7e05392483455f7df4bf2af5d5d74e5a2ae.zip
Add ListDataProvider shorthands for filter conversion (#8279)
Also updates ComboBox.setItems to use these new shorthands This is one of many steps towards #8245
Diffstat (limited to 'server/src/main/java/com/vaadin/ui/ComboBox.java')
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java
index a789e2990c..20cc14b2da 100644
--- a/server/src/main/java/com/vaadin/ui/ComboBox.java
+++ b/server/src/main/java/com/vaadin/ui/ComboBox.java
@@ -134,11 +134,6 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
private StyleGenerator<T> itemStyleGenerator = item -> null;
- private final SerializableBiPredicate<String, T> defaultFilterMethod = (
- text, item) -> getItemCaptionGenerator().apply(item)
- .toLowerCase(getLocale())
- .contains(text.toLowerCase(getLocale()));
-
/**
* Constructs an empty combo box without a caption. The content of the combo
* box can be set with {@link #setDataProvider(DataProvider)} or
@@ -216,10 +211,13 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
@Override
public void setItems(Collection<T> items) {
- DataProvider<T, String> provider = DataProvider.create(items)
- .convertFilter(filterText -> item -> defaultFilterMethod
- .test(filterText, item));
- setDataProvider(provider);
+ // Cannot use the case insensitive contains shorthand from
+ // ListDataProvider since it wouldn't react to locale changes
+ CaptionFilter defaultCaptionFilter = (itemText, filterText) -> itemText
+ .toLowerCase(getLocale())
+ .contains(filterText.toLowerCase(getLocale()));
+
+ setItems(defaultCaptionFilter, items);
}
/**
@@ -236,9 +234,11 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
* the data items to display
*/
public void setItems(CaptionFilter captionFilter, Collection<T> items) {
+ // Must do getItemCaptionGenerator() for each operation since it might
+ // not be the same as when this method was invoked
DataProvider<T, String> provider = DataProvider.create(items)
- .convertFilter(filterText -> item -> captionFilter.test(
- getItemCaptionGenerator().apply(item), filterText));
+ .filteringBy(item -> getItemCaptionGenerator().apply(item),
+ captionFilter);
setDataProvider(provider);
}
@@ -300,8 +300,8 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
/**
* Returns true if the user can enter text into the field to either filter
- * the selections or enter a new value if new item handler is set
- * (see {@link #setNewItemHandler(NewItemHandler)}. If text input is disabled,
+ * the selections or enter a new value if new item handler is set (see
+ * {@link #setNewItemHandler(NewItemHandler)}. If text input is disabled,
* the comboBox will work in the same way as a {@link NativeSelect}
*
* @return true if text input is allowed