diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2017-02-16 10:14:38 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-02-16 10:14:38 +0200 |
commit | 1891ffa6e1c4db8bc0d0f60eca255895a6448bdd (patch) | |
tree | e93a79a4be27fdecaadab7effc002d2f5492f9f2 /client | |
parent | 20947e0e0893c955ec6e42579a29a913c3c74883 (diff) | |
download | vaadin-framework-1891ffa6e1c4db8bc0d0f60eca255895a6448bdd.tar.gz vaadin-framework-1891ffa6e1c4db8bc0d0f60eca255895a6448bdd.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 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VComboBox.java | 208 | ||||
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java | 113 |
2 files changed, 218 insertions, 103 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index 6ecea2d116..77e1108417 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -208,12 +208,12 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, return false; } ComboBoxSuggestion other = (ComboBoxSuggestion) obj; - if ((key == null && other.key != null) - || (key != null && !key.equals(other.key))) { + if (key == null && other.key != null + || key != null && !key.equals(other.key)) { return false; } - if ((caption == null && other.caption != null) - || (caption != null && !caption.equals(other.caption))) { + if (caption == null && other.caption != null + || caption != null && !caption.equals(other.caption)) { return false; } if (!SharedUtil.equals(untranslatedIconUri, @@ -241,12 +241,12 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, return $entry(function(e) { var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX; var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY; - + // IE8 has only delta y if (isNaN(deltaY)) { deltaY = -0.5*e.wheelDelta; } - + @com.vaadin.client.ui.VComboBox.JsniUtil::moveScrollFromEvent(*)(widget, deltaX, deltaY, e, e.deltaMode); }); }-*/; @@ -398,14 +398,11 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, * * @param currentPage * The current page number - * @param totalSuggestions - * The total amount of suggestions */ - public void showSuggestions(final int currentPage, - final int totalSuggestions) { + public void showSuggestions(final int currentPage) { debug("VComboBox.SP: showSuggestions(" + currentPage + ", " - + totalSuggestions + ")"); + + getTotalSuggestions() + ")"); final SuggestionPopup popup = this; // Add TT anchor point @@ -418,14 +415,13 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, setPopupPosition(x, topPosition); - int nullOffset = (nullSelectionAllowed && "".equals(lastFilter) ? 1 - : 0); - boolean firstPage = (currentPage == 0); + int nullOffset = getNullSelectionItemShouldBeVisible() ? 1 : 0; + boolean firstPage = currentPage == 0; final int first = currentPage * pageLength + 1 - (firstPage ? 0 : nullOffset); final int last = first + currentSuggestions.size() - 1 - (firstPage && "".equals(lastFilter) ? nullOffset : 0); - final int matches = totalSuggestions - nullOffset; + final int matches = getTotalSuggestions(); if (last > 0) { // nullsel not counted, as requested by user status.setInnerText((matches == 0 ? 0 : first) + "-" + last @@ -435,7 +431,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, } // We don't need to show arrows or statusbar if there is // only one page - if (totalSuggestions <= pageLength || pageLength == 0) { + if (getTotalSuggestionsIncludingNullSelectionItem() <= pageLength + || pageLength == 0) { setPagingEnabled(false); } else { setPagingEnabled(true); @@ -609,8 +606,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, public void scrollDown() { debug("VComboBox.SP.LPS: scrollDown()"); if (pageLength > 0 - && totalMatches > (currentPage + pagesToScroll + 1) - * pageLength) { + && getTotalSuggestionsIncludingNullSelectionItem() > (currentPage + + pagesToScroll + 1) * pageLength) { pagesToScroll++; cancel(); schedule(200); @@ -860,7 +857,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, if (suggestionPopupWidth == null) { if (naturalMenuWidth < desiredWidth) { naturalMenuWidth = desiredWidth - popupOuterPadding; - width = (desiredWidth - popupOuterPadding) + "px"; + width = desiredWidth - popupOuterPadding + "px"; } } else if (isrelativeUnits(suggestionPopupWidth)) { float mainComponentWidth = desiredWidth - popupOuterPadding; @@ -904,8 +901,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, */ public boolean isJustClosed() { debug("VComboBox.SP: justClosed()"); - final long now = (new Date()).getTime(); - return (lastAutoClosed > 0 && (now - lastAutoClosed) < 200); + final long now = new Date().getTime(); + return lastAutoClosed > 0 && now - lastAutoClosed < 200; } /* @@ -922,7 +919,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, debug("VComboBox.SP: onClose(" + event.isAutoClosed() + ")"); } if (event.isAutoClosed()) { - lastAutoClosed = (new Date()).getTime(); + lastAutoClosed = new Date().getTime(); } } @@ -999,8 +996,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, */ String getPreferredHeight(int pageItemsCount) { if (currentSuggestions.size() > 0) { - final int pixels = (getPreferredHeight() - / currentSuggestions.size()) * pageItemsCount; + final int pixels = getPreferredHeight() + / currentSuggestions.size() * pageItemsCount; return pixels + "px"; } else { return ""; @@ -1022,9 +1019,10 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, final Iterator<ComboBoxSuggestion> it = suggestions.iterator(); boolean isFirstIteration = true; while (it.hasNext()) { - final ComboBoxSuggestion s = it.next(); - final MenuItem mi = new MenuItem(s.getDisplayString(), true, s); - String style = s.getStyle(); + final ComboBoxSuggestion suggestion = it.next(); + final MenuItem mi = new MenuItem(suggestion.getDisplayString(), + true, suggestion); + String style = suggestion.getStyle(); if (style != null) { mi.addStyleName("v-filterselect-item-" + style); } @@ -1040,20 +1038,23 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, selectItem(mi); } - if (currentSuggestion != null && s.getOptionKey() + if (currentSuggestion != null && suggestion.getOptionKey() .equals(currentSuggestion.getOptionKey())) { - // refresh also selected caption and icon in case they have - // been updated on the server + // Refresh also selected caption and icon in case they have + // been updated on the server, e.g. just the item has been + // updated, but selection (from state) has stayed the same. + // FIXME need to update selected item caption separately, if + // the selected item is not in "active data range" that is + // being sent to the client. Then this can be removed. if (currentSuggestion.getReplacementString() .equals(tb.getText())) { - currentSuggestion = s; + currentSuggestion = suggestion; selectItem(mi); setSelectedCaption( currentSuggestion.getReplacementString()); setSelectedItemIcon(currentSuggestion.getIconUri()); } } - isFirstIteration = false; } } @@ -1080,8 +1081,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, // do not send a value change event if null was and // stays selected if (!"".equals(enteredItemValue) - || (selectedOptionKey != null - && !"".equals(selectedOptionKey))) { + || selectedOptionKey != null + && !"".equals(selectedOptionKey)) { doItemAction(potentialExactMatch, true); } suggestionPopup.hide(); @@ -1099,8 +1100,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, // TODO try to select the new value if it matches what was // sent for V7 compatibility } - } else if (item != null && !"".equals(lastFilter) && (item.getText() - .toLowerCase().contains(lastFilter.toLowerCase()))) { + } else if (item != null && !"".equals(lastFilter) && item.getText() + .toLowerCase().contains(lastFilter.toLowerCase())) { doItemAction(item, true); } else { // currentSuggestion has key="" for nullselection @@ -1367,7 +1368,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, showPopup = true; } if (showPopup) { - suggestionPopup.showSuggestions(currentPage, totalMatches); + suggestionPopup.showSuggestions(currentPage); } waitingForFilteringResponse = false; @@ -1523,9 +1524,12 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, * new selected item caption if sent by the server or null - * this is used when the selected item is not on the current * page + * @param selectedIconUri + * new selected item icon if sent by the server or {@ code + * null} to clear */ public void updateSelectionFromServer(String selectedKey, - String selectedCaption) { + String selectedCaption, String selectedIconUri) { boolean oldSuggestionTextMatchTheOldSelection = currentSuggestion != null && currentSuggestion.getReplacementString() .equals(tb.getText()); @@ -1538,10 +1542,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, cancelPendingPostFiltering(); setSelectedCaption(selectedCaption); - if (currentSuggestion != null && serverSelectedKey - .equals(currentSuggestion.getOptionKey())) { - setSelectedItemIcon(currentSuggestion.getIconUri()); - } + + setSelectedItemIcon(selectedIconUri); } } @@ -1617,8 +1619,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, /** For internal use only. May be removed or replaced in the future. */ public boolean allowNewItems; - /** For internal use only. May be removed or replaced in the future. */ - public int totalMatches; + /** Total number of suggestions, excluding null selection item. */ + private int totalSuggestions; /** For internal use only. May be removed or replaced in the future. */ public boolean nullSelectionAllowed; @@ -1765,8 +1767,9 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, * last page */ public boolean hasNextPage() { - return (pageLength > 0 - && totalMatches > (currentPage + 1) * pageLength); + return pageLength > 0 + && getTotalSuggestionsIncludingNullSelectionItem() > (currentPage + + 1) * pageLength; } /** @@ -1793,16 +1796,13 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, public void filterOptions(int page, String filter) { debug("VComboBox: filterOptions(" + page + ", " + filter + ")"); - if (filter.equals(lastFilter) && currentPage == page) { - if (!suggestionPopup.isAttached()) { - dataReceivedHandler.startWaitingForFilteringResponse(); - connector.requestPage(currentPage); - } else { - // already have the page - dataReceivedHandler.dataReceived(); - } + if (filter.equals(lastFilter) && currentPage == page + && suggestionPopup.isAttached()) { + // already have the page + dataReceivedHandler.dataReceived(); return; } + if (!filter.equals(lastFilter)) { // when filtering, let the server decide the page unless we've // set the filter to empty and explicitly said that we want to see @@ -1816,11 +1816,15 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, } dataReceivedHandler.startWaitingForFilteringResponse(); - connector.setFilter(filter); - connector.requestPage(currentPage); + connector.requestPage(page, filter); lastFilter = filter; - currentPage = page; + + // If the data was updated from cache, the page has been updated too, if + // not, update + if (dataReceivedHandler.isWaitingForFilteringResponse()) { + currentPage = page; + } } /** For internal use only. May be removed or replaced in the future. */ @@ -1914,7 +1918,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, setText(text); setSelectedItemIcon(suggestion.getIconUri()); - if (!(newKey.equals(selectedOptionKey))) { + if (!newKey.equals(selectedOptionKey)) { selectedOptionKey = newKey; connector.sendSelection(selectedOptionKey); setSelectedCaption(text); @@ -1932,23 +1936,19 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, if (enableDebug) { debug("VComboBox: onNullSelected()"); } - // TODO do we need this feature? - if (nullSelectItem) { - reset(); - return; - } dataReceivedHandler.cancelPendingPostFiltering(); currentSuggestion = null; setText(""); setSelectedItemIcon(null); - if (!"".equals(selectedOptionKey) || (selectedOptionKey != null)) { + if (!"".equals(selectedOptionKey) || selectedOptionKey != null) { selectedOptionKey = ""; setSelectedCaption(""); connector.sendSelection(null); // currentPage = 0; } + updatePlaceholder(); suggestionPopup.hide(); } @@ -1958,7 +1958,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, * side of the item caption text. Set the URI to null to remove the icon. * * @param iconUri - * The URI of the icon + * The URI of the icon, or null to remove icon */ public void setSelectedItemIcon(String iconUri) { @@ -2017,7 +2017,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, boolean updatePromptAndSelectionIfMatchFound) { if (selectedKey == null || "".equals(selectedKey)) { currentSuggestion = null; // #13217 - setSelectedItemIcon(null); selectedOptionKey = null; setText(""); } @@ -2042,7 +2041,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, } } currentSuggestion = suggestion; - setSelectedItemIcon(suggestion.getIconUri()); // only a single item can be selected break; } @@ -2294,19 +2292,21 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, */ private void reset() { debug("VComboBox: reset()"); - if (currentSuggestion != null) { - String text = currentSuggestion.getReplacementString(); - setText(text); - setSelectedItemIcon(currentSuggestion.getIconUri()); - - selectedOptionKey = currentSuggestion.key; - - } else { - setText(""); - setSelectedItemIcon(null); - updatePlaceholder(); + // just fetch selected information from state + String text = connector.getState().selectedItemCaption; + setText(text == null ? "" : text); + setSelectedItemIcon(connector.getState().selectedItemIcon); + selectedOptionKey = (connector.getState().selectedItemKey); + if (selectedOptionKey == null || "".equals(selectedOptionKey)) { + currentSuggestion = null; // #13217 selectedOptionKey = null; + updatePlaceholder(); + } else { + currentSuggestion = currentSuggestions.stream() + .filter(suggestion -> suggestion.getOptionKey() + .equals(selectedOptionKey)) + .findAny().orElse(null); } lastFilter = ""; @@ -2551,7 +2551,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, * popupopener */ - tb.setWidth((suggestionPopupMinWidth - iconWidth - buttonWidth) + tb.setWidth(suggestionPopupMinWidth - iconWidth - buttonWidth + "px"); } @@ -2563,7 +2563,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, if (!tb.getElement().getStyle().getWidth().endsWith("px")) { int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon.getOffsetWidth(); - tb.setWidth((tb.getOffsetWidth() - iconWidth) + "px"); + tb.setWidth(tb.getOffsetWidth() - iconWidth + "px"); } } } @@ -2763,4 +2763,52 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, this.allowNewItems = allowNewItems; } + /** + * Sets the total number of suggestions. + * <p> + * NOTE: this excluded the possible null selection item! + * <p> + * NOTE: this just updates the state, but doesn't update any UI. + * + * @since 8.0 + * @param totalSuggestions + * total number of suggestions + */ + public void setTotalSuggestions(int totalSuggestions) { + this.totalSuggestions = totalSuggestions; + } + + /** + * Gets the total number of suggestions, excluding the null selection item. + * + * @since 8.0 + * @return total number of suggestions + */ + public int getTotalSuggestions() { + return totalSuggestions; + } + + /** + * Gets the total number of suggestions, including the possible null + * selection item, if it should be visible. + * + * @return total number of suggestions with null selection items + */ + private int getTotalSuggestionsIncludingNullSelectionItem() { + return getTotalSuggestions() + + (getNullSelectionItemShouldBeVisible() ? 1 : 0); + } + + /** + * Returns null selection item should be visible or not. + * <p> + * NOTE: this checks for any entered filter value, and whether the feature + * is enabled + * + * @since 8.0 + * @return {@code true} if it should be visible, {@code} + */ + public boolean getNullSelectionItemShouldBeVisible() { + return nullSelectionAllowed && "".equals(lastFilter); + } } diff --git a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java index a4a9c17f4d..7fec2ae8e0 100644 --- a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -16,12 +16,15 @@ package com.vaadin.client.ui.combobox; import java.util.List; +import java.util.Objects; +import java.util.logging.Logger; import com.vaadin.client.Profiler; import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.connectors.AbstractListingConnector; import com.vaadin.client.connectors.data.HasDataSource; +import com.vaadin.client.data.DataChangeHandler; import com.vaadin.client.data.DataSource; import com.vaadin.client.ui.HasErrorIndicator; import com.vaadin.client.ui.HasRequiredIndicator; @@ -76,6 +79,8 @@ public class ComboBoxConnector extends AbstractListingConnector getWidget().suggestionPopup.updateStyleNames(getState()); + // TODO if the pop up is opened, the actual item should be removed from + // the popup (?) getWidget().nullSelectionAllowed = getState().emptySelectionAllowed; // TODO having this true would mean that the empty selection item comes // from the data source so none needs to be added - currently @@ -87,6 +92,9 @@ public class ComboBoxConnector extends AbstractListingConnector getDataReceivedHandler().serverReplyHandled(); + // all updates except options have been done + getWidget().initDone = true; + Profiler.leave("ComboBoxConnector.onStateChanged update content"); } @@ -99,10 +107,11 @@ public class ComboBoxConnector extends AbstractListingConnector } } - @OnStateChange({ "selectedItemKey", "selectedItemCaption" }) + @OnStateChange({ "selectedItemKey", "selectedItemCaption", "selectedItemIcon" }) private void onSelectionChange() { getDataReceivedHandler().updateSelectionFromServer( - getState().selectedItemKey, getState().selectedItemCaption); + getState().selectedItemKey, getState().selectedItemCaption, + getState().selectedItemIcon); } @Override @@ -164,11 +173,12 @@ public class ComboBoxConnector extends AbstractListingConnector * @param filter * the current filter string */ - public void setFilter(String filter) { - if (filter != getWidget().lastFilter) { + protected void setFilter(String filter) { + if (!Objects.equals(filter, getWidget().lastFilter)) { getDataReceivedHandler().clearPendingNavigation(); + + rpc.setFilter(filter); } - rpc.setFilter(filter); } /** @@ -183,22 +193,27 @@ public class ComboBoxConnector extends AbstractListingConnector * the page number to get or -1 to let the server/connector * decide based on current selection (possibly loading more data * from the server) + * @param filter + * the filter to apply, never {@code null} */ - public void requestPage(int page) { + public void requestPage(int page, String filter) { + setFilter(filter); + if (page < 0) { if (getState().scrollToSelectedItem) { - getDataSource().ensureAvailability(0, 10000); + // TODO this should be optimized not to try to fetch everything + getDataSource().ensureAvailability(0, getDataSource().size()); return; } else { page = 0; } } - int adjustment = getWidget().nullSelectionAllowed - && "".equals(getWidget().lastFilter) ? 1 : 0; + int adjustment = getWidget().nullSelectionAllowed && "".equals(filter) + ? 1 : 0; int startIndex = Math.max(0, page * getWidget().pageLength - adjustment); int pageLength = getWidget().pageLength > 0 ? getWidget().pageLength - : 10000; + : getDataSource().size(); getDataSource().ensureAvailability(startIndex, pageLength); } @@ -261,7 +276,7 @@ public class ComboBoxConnector extends AbstractListingConnector public void setDataSource(DataSource<JsonObject> dataSource) { super.setDataSource(dataSource); dataChangeHandlerRegistration = dataSource - .addDataChangeHandler(range -> refreshData()); + .addDataChangeHandler(new PagedDataChangeHandler(dataSource)); } @Override @@ -278,14 +293,13 @@ public class ComboBoxConnector extends AbstractListingConnector private void refreshData() { updateCurrentPage(); - getWidget().currentSuggestions.clear(); - int start = getWidget().currentPage * getWidget().pageLength; int end = getWidget().pageLength > 0 ? start + getWidget().pageLength : getDataSource().size(); - if (getWidget().nullSelectionAllowed - && "".equals(getWidget().lastFilter)) { + getWidget().currentSuggestions.clear(); + + if (getWidget().getNullSelectionItemShouldBeVisible()) { // add special null selection item... if (isFirstPage()) { addEmptySelectionItem(); @@ -294,13 +308,14 @@ public class ComboBoxConnector extends AbstractListingConnector start = start - 1; } // in either case, the last item to show is - // shifted by one - end = end - 1; + // shifted by one, unless no paging is used + if (getState().pageLength != 0) { + end = end - 1; + } } updateSuggestions(start, end); - getWidget().totalMatches = getDataSource().size() - + (getState().emptySelectionAllowed ? 1 : 0); + getWidget().setTotalSuggestions(getDataSource().size()); getDataReceivedHandler().dataReceived(); } @@ -308,16 +323,18 @@ public class ComboBoxConnector extends AbstractListingConnector private void updateSuggestions(int start, int end) { for (int i = start; i < end; ++i) { JsonObject row = getDataSource().getRow(i); - if (row != null) { String key = getRowKey(row); String caption = row.getString(DataCommunicatorConstants.NAME); String style = row.getString(ComboBoxConstants.STYLE); String untranslatedIconUri = row .getString(ComboBoxConstants.ICON); - getWidget().currentSuggestions - .add(getWidget().new ComboBoxSuggestion(key, caption, - style, untranslatedIconUri)); + ComboBoxSuggestion suggestion = getWidget().new ComboBoxSuggestion( + key, caption, style, untranslatedIconUri); + getWidget().currentSuggestions.add(suggestion); + } else { + // there is not enough options to fill the page + return; } } } @@ -360,4 +377,54 @@ public class ComboBoxConnector extends AbstractListingConnector getWidget().currentPage = 0; } } + + private static final Logger LOGGER = Logger + .getLogger(ComboBoxConnector.class.getName()); + + private class PagedDataChangeHandler implements DataChangeHandler { + + private final DataSource<?> dataSource; + + public PagedDataChangeHandler(DataSource<?> dataSource) { + this.dataSource = dataSource; + } + + @Override + public void dataUpdated(int firstRowIndex, int numberOfRows) { + // NOOP since dataAvailable is always triggered afterwards + } + + @Override + public void dataRemoved(int firstRowIndex, int numberOfRows) { + // NOOP since dataAvailable is always triggered afterwards + } + + @Override + public void dataAdded(int firstRowIndex, int numberOfRows) { + // NOOP since dataAvailable is always triggered afterwards + } + + @Override + public void dataAvailable(int firstRowIndex, int numberOfRows) { + refreshData(); + } + + @Override + public void resetDataAndSize(int estimatedNewDataSize) { + if (getState().pageLength == 0) { + if (getWidget().suggestionPopup.isShowing()) { + dataSource.ensureAvailability(0, estimatedNewDataSize); + } + // else lets just wait till the popup is opened before + // everything is fetched to it. this could be optimized later on + // to fetch everything if in-memory data is used. + } else { + // reset data: clear any current options, set page to 0 + getWidget().currentPage = 0; + getWidget().currentSuggestions.clear(); + dataSource.ensureAvailability(0, getState().pageLength); + } + } + + } } |