aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-09-15 09:02:56 +0300
committerDenis Anisimov <denis@vaadin.com>2016-09-20 13:17:13 +0300
commit8939d3257f2f48ce5525b908c3d3450cee837aaf (patch)
tree92bec14e4b81506067e46ab89b35c0fe79032fb8 /server
parentc6e195aa63d1dfd4568453bcb33b40c332f1b953 (diff)
downloadvaadin-framework-8939d3257f2f48ce5525b908c3d3450cee837aaf.tar.gz
vaadin-framework-8939d3257f2f48ce5525b908c3d3450cee837aaf.zip
Move ItemCaptionProvider out of ComboBox (#184).
Change-Id: I7dc98de04127c7495aed81b9e0cd2be8cb12b10c
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java46
-rw-r--r--server/src/main/java/com/vaadin/ui/ItemCaptionGenerator.java44
2 files changed, 61 insertions, 29 deletions
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java
index 0b1b4923f8..d39d8a7c4e 100644
--- a/server/src/main/java/com/vaadin/ui/ComboBox.java
+++ b/server/src/main/java/com/vaadin/ui/ComboBox.java
@@ -67,7 +67,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
String selectedCaption = null;
T value = getDataCommunicator().getKeyMapper().get(key);
if (value != null) {
- selectedCaption = getItemCaptionProvider().apply(value);
+ selectedCaption = getItemCaptionGenerator().apply(value);
}
getState().selectedItemCaption = selectedCaption;
}
@@ -83,19 +83,6 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
}
/**
- * ItemCaptionProvider can be used to customize the string shown to the user
- * for an item.
- *
- * @see ComboBox#setItemCaptionProvider(ItemCaptionProvider)
- * @param <T>
- * item type in the combo box
- */
- @FunctionalInterface
- public interface ItemCaptionProvider<T>
- extends Function<T, String>, Serializable {
- }
-
- /**
* ItemIconProvider can be used to add custom icons to combo box items shown
* in the popup.
*
@@ -160,7 +147,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
*/
private NewItemHandler newItemHandler;
- private ItemCaptionProvider<T> itemCaptionProvider = String::valueOf;
+ private ItemCaptionGenerator<T> itemCaptionGenerator = String::valueOf;
private StyleGenerator<T> itemStyleGenerator = item -> null;
private ItemIconProvider<T> itemIconProvider = item -> null;
@@ -169,7 +156,8 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
if (filterText == null) {
return true;
} else {
- return getItemCaptionProvider().apply(item).toLowerCase(getLocale())
+ return getItemCaptionGenerator().apply(item)
+ .toLowerCase(getLocale())
.contains(filterText.toLowerCase(getLocale()));
}
};
@@ -248,7 +236,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
addDataGenerator((T data, JsonObject jsonObject) -> {
jsonObject.put(DataCommunicatorConstants.NAME,
- getItemCaptionProvider().apply(data));
+ getItemCaptionGenerator().apply(data));
String style = itemStyleGenerator.apply(data);
if (style != null) {
jsonObject.put(ComboBoxConstants.STYLE, style);
@@ -429,28 +417,28 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
}
/**
- * Gets the item caption provider that is used to produce the strings shown
+ * Gets the item caption generator that is used to produce the strings shown
* in the combo box for each item.
*
- * @return the item caption provider used, not null
+ * @return the item caption generator used, not null
*/
- public ItemCaptionProvider<T> getItemCaptionProvider() {
- return itemCaptionProvider;
+ public ItemCaptionGenerator<T> getItemCaptionGenerator() {
+ return itemCaptionGenerator;
}
/**
- * Sets the item caption provider that is used to produce the strings shown
+ * Sets the item caption generator that is used to produce the strings shown
* in the combo box for each item. By default,
* {@link String#valueOf(Object)} is used.
*
- * @param itemCaptionProvider
+ * @param itemCaptionGenerator
* the item caption provider to use, not null
*/
- public void setItemCaptionProvider(
- ItemCaptionProvider<T> itemCaptionProvider) {
- Objects.requireNonNull(itemCaptionProvider,
- "Item caption providers must not be null");
- this.itemCaptionProvider = itemCaptionProvider;
+ public void setItemCaptionGenerator(
+ ItemCaptionGenerator<T> itemCaptionGenerator) {
+ Objects.requireNonNull(itemCaptionGenerator,
+ "Item caption generators must not be null");
+ this.itemCaptionGenerator = itemCaptionGenerator;
getDataCommunicator().reset();
}
@@ -580,7 +568,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
HasValue.ValueChangeListener<? super T> listener) {
return addSelectionListener(event -> {
((ValueChangeListener<T>) listener)
- .accept(new ValueChange<T>(event.getConnector(),
+ .accept(new ValueChange<>(event.getConnector(),
event.getValue(), event.isUserOriginated()));
});
}
diff --git a/server/src/main/java/com/vaadin/ui/ItemCaptionGenerator.java b/server/src/main/java/com/vaadin/ui/ItemCaptionGenerator.java
new file mode 100644
index 0000000000..dc699c077b
--- /dev/null
+++ b/server/src/main/java/com/vaadin/ui/ItemCaptionGenerator.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.ui;
+
+import java.io.Serializable;
+import java.util.function.Function;
+
+/**
+ * {@link ItemCaptionGenerator} can be used to customize the string shown to the
+ * user for an item.
+ *
+ * @see ComboBox#setItemCaptionGenerator(ItemCaptionProvider)
+ * @param <T>
+ * item type
+ * @since 8.0
+ * @author Vaadin Ltd
+ */
+@FunctionalInterface
+public interface ItemCaptionGenerator<T>
+ extends Function<T, String>, Serializable {
+
+ /**
+ * Gets a caption for the {@code item}.
+ *
+ * @param item
+ * the item to get caption for
+ * @return the caption of the item
+ */
+ @Override
+ String apply(T item);
+}