aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2017-02-16 10:14:38 +0200
committerHenri Sara <henri.sara@gmail.com>2017-02-16 12:38:08 +0200
commit30a1416da4fdbc13cde6662498690792808a87b7 (patch)
tree5bc666e9786eb4ac3d09641e8e363b03d9ac57da /server
parent77ebc459d2ecb29dd8a85d386bfb35a40c263f1e (diff)
downloadvaadin-framework-30a1416da4fdbc13cde6662498690792808a87b7.tar.gz
vaadin-framework-30a1416da4fdbc13cde6662498690792808a87b7.zip
Reduce ComboBox initial requests (#8571)
* Reduce ComboBox initial requests Use initial fetched data on client side, do not request data from server side for each time popup is opened. Fixed initial filter being null for ComboBox on DataProvider, causing unnecessary size & fetch for not-changed filter. Fixed ComboBox sending default filter unnecessarily to server. Fixed wrong page indexing in VComboBox -> ComboBoxConnector. Fixes #8496 Fixes vaadin/framework8-issues#488 * Fix last item missing When pageLength was 0 and nullSelectionAllowed, the last item was not shown. Tried to sensify the API for total suggestions versus total suggestions + null selection item. * Fix ComboBox selected item updates Handles changing of ItemCaptionGenerator or ItemIconGenerator, need to update the selected item caption and icon separately. Previously it worked because all data was sent all the time to client. Doesn't fix the issue, when selected item is updated with refreshItem(), and it is not on the active range that will be sent to client. For that, ComboBox would need a separate notification about item update. * Updated screenshots
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java35
1 files changed, 31 insertions, 4 deletions
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java
index a2db94a8c6..ed1e9d8beb 100644
--- a/server/src/main/java/com/vaadin/ui/ComboBox.java
+++ b/server/src/main/java/com/vaadin/ui/ComboBox.java
@@ -575,6 +575,9 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
public void setItemCaptionGenerator(
ItemCaptionGenerator<T> itemCaptionGenerator) {
super.setItemCaptionGenerator(itemCaptionGenerator);
+ if (getSelectedItem().isPresent()) {
+ updateSelectedItemCaption();
+ }
}
/**
@@ -614,6 +617,10 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
@Override
public void setItemIconGenerator(IconGenerator<T> itemIconGenerator) {
super.setItemIconGenerator(itemIconGenerator);
+
+ if (getSelectedItem().isPresent()) {
+ updateSelectedItemIcon();
+ }
}
@Override
@@ -631,7 +638,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
*/
public void setNewItemHandler(NewItemHandler newItemHandler) {
this.newItemHandler = newItemHandler;
- getState().allowNewItems = (newItemHandler != null);
+ getState().allowNewItems = newItemHandler != null;
markAsDirty();
}
@@ -670,14 +677,32 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
protected void doSetSelectedKey(String key) {
super.doSetSelectedKey(key);
+ updateSelectedItemCaption();
+ updateSelectedItemIcon();
+ }
+
+ private void updateSelectedItemCaption() {
String selectedCaption = null;
- T value = getDataCommunicator().getKeyMapper().get(key);
+ T value = getDataCommunicator().getKeyMapper().get(getSelectedKey());
if (value != null) {
selectedCaption = getItemCaptionGenerator().apply(value);
}
getState().selectedItemCaption = selectedCaption;
}
+ private void updateSelectedItemIcon() {
+ String selectedItemIcon = null;
+ T value = getDataCommunicator().getKeyMapper().get(getSelectedKey());
+ if (value != null) {
+ Resource icon = getItemIconGenerator().apply(value);
+ if (icon != null) {
+ selectedItemIcon = ResourceReference
+ .create(icon, ComboBox.this, null).getURL();
+ }
+ }
+ getState().selectedItemIcon = selectedItemIcon;
+ }
+
@Override
protected Element writeItem(Element design, T item, DesignContext context) {
Element element = design.appendElement("option");
@@ -748,7 +773,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
"filterConverter cannot be null");
SerializableFunction<String, C> convertOrNull = filterText -> {
- if (filterText == null) {
+ if (filterText == null || filterText.isEmpty()) {
return null;
}
@@ -814,10 +839,12 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
extends SerializableBiPredicate<String, String> {
/**
- * Check item caption against entered text
+ * Check item caption against entered text.
*
* @param itemCaption
+ * the caption of the item to filter, not {@code null}
* @param filterText
+ * user entered filter, not {@code null}
* @return {@code true} if item passes the filter and should be listed,
* {@code false} otherwise
*/