diff options
author | Henri Sara <hesara@vaadin.com> | 2015-11-11 11:17:57 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2016-01-15 14:42:58 +0200 |
commit | 50ae0f010a434dc963c326c8586f69ae09526ea5 (patch) | |
tree | 28a2e0f990a147215fe178fb33e4fff7ebca72f7 | |
parent | dbe6b5b266571f223bffd0354dbce651a5650411 (diff) | |
download | vaadin-framework-50ae0f010a434dc963c326c8586f69ae09526ea5.tar.gz vaadin-framework-50ae0f010a434dc963c326c8586f69ae09526ea5.zip |
Move more combo logic to handler (#19929)
- Move waitingForFilteringResponse etc. to the data received
handler.
- Change some setters to parameterless methods that trigger a
state transition.
Change-Id: Ifb92207853d4ec76db846945f69a426c885562ed
-rw-r--r-- | client/src/com/vaadin/client/ui/VFilterSelect.java | 92 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java | 27 |
2 files changed, 61 insertions, 58 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index 525e5b3432..d60464e8aa 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -557,7 +557,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, public void run() { debug("VFS.SP.LPS: run()"); if (pagesToScroll != 0) { - if (!isWaitingForFilteringResponse()) { + if (!dataReceivedHandler.isWaitingForFilteringResponse()) { /* * Avoid scrolling while we are waiting for a response * because otherwise the waiting flag will be reset in @@ -946,20 +946,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, return; } - doPostFilterWhenReady(); - } - - /** - * Perform the post-filter action either now (if not waiting for a - * server response) or when a response is received. - */ - private void doPostFilterWhenReady() { - if (isWaitingForFilteringResponse()) { - dataReceivedHandler.setUpdateOnDataReceived(true); - } else { - dataReceivedHandler.setUpdateOnDataReceived(false); - doPostFilterSelectedItemAction(); - } + dataReceivedHandler.doPostFilterWhenReady(); } /** @@ -1192,6 +1179,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, */ private boolean popupOpenerClicked = false; private boolean updateOnDataReceived = false; + /** For internal use only. May be removed or replaced in the future. */ + private boolean waitingForFilteringResponse = false; /** * Called by the connector when new data for the last requested filter @@ -1201,7 +1190,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, suggestionPopup.showSuggestions(currentSuggestions, currentPage, totalMatches); - setWaitingForFilteringResponse(false); + waitingForFilteringResponse = false; if (!popupOpenerClicked) { navigateItemAfterPageChange(); @@ -1280,8 +1269,11 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, return popupOpenerClicked; } - public void setUpdateOnDataReceived(boolean update) { - updateOnDataReceived = update; + /** + * Cancel a pending request to perform post-filtering actions. + */ + private void cancelPendingPostFiltering() { + updateOnDataReceived = false; } /** @@ -1291,6 +1283,37 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, public void serverReplyHandled() { popupOpenerClicked = false; } + + /** + * For internal use only - this method will be removed in the future. + * + * @return true if the combo box is waiting for a reply from the server + * with a new page of data, false otherwise + */ + public boolean isWaitingForFilteringResponse() { + return waitingForFilteringResponse; + } + + /** + * Set a flag that filtering of options is pending a response from the + * server. + */ + private void startWaitingForFilteringResponse() { + waitingForFilteringResponse = true; + } + + /** + * Perform the post-filter action either now (if not waiting for a + * server response) or when a response is received. + */ + private void doPostFilterWhenReady() { + if (isWaitingForFilteringResponse()) { + updateOnDataReceived = true; + } else { + updateOnDataReceived = false; + suggestionPopup.menu.doPostFilterSelectedItemAction(); + } + } } @Deprecated @@ -1372,9 +1395,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, public String selectedOptionKey; /** For internal use only. May be removed or replaced in the future. */ - private boolean waitingForFilteringResponse = false; - - /** For internal use only. May be removed or replaced in the future. */ public boolean initDone = false; /** For internal use only. May be removed or replaced in the future. */ @@ -1617,7 +1637,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, } } - setWaitingForFilteringResponse(true); + dataReceivedHandler.startWaitingForFilteringResponse(); connector.requestPage(filter, page); lastFilter = filter; @@ -1716,7 +1736,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, debug("VFS: onSuggestionSelected(" + suggestion.caption + ": " + suggestion.key + ")"); } - dataReceivedHandler.setUpdateOnDataReceived(false); + dataReceivedHandler.cancelPendingPostFiltering(); currentSuggestion = suggestion; String newKey; @@ -1836,7 +1856,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, if (enableDebug) { debug("VFS: key down: " + keyCode); } - if (isWaitingForFilteringResponse() + if (dataReceivedHandler.isWaitingForFilteringResponse() && navigationKeyCodes.contains(keyCode)) { /* * Keyboard navigation events should not be handled while we are @@ -2432,33 +2452,11 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, @Override public boolean isWorkPending() { - return isWaitingForFilteringResponse() + return dataReceivedHandler.isWaitingForFilteringResponse() || suggestionPopup.lazyPageScroller.isRunning(); } /** - * For internal use only - this method will be removed in the future. - * - * @return true if the combo box is waiting for a reply from the server with - * a new page of data, false otherwise - */ - public boolean isWaitingForFilteringResponse() { - return waitingForFilteringResponse; - } - - /** - * For internal use only - this method will be removed in the future. - * - * @param waitingForFilteringResponse - * true to indicate that the combo box is waiting for a new page - * of items from the server - */ - public void setWaitingForFilteringResponse( - boolean waitingForFilteringResponse) { - this.waitingForFilteringResponse = waitingForFilteringResponse; - } - - /** * Returns a handler receiving notifications from the connector about * communications. * diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java index e367834d1e..ef4a826f2b 100644 --- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -28,6 +28,7 @@ import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.VFilterSelect; +import com.vaadin.client.ui.VFilterSelect.DataReceivedHandler; import com.vaadin.client.ui.VFilterSelect.FilterSelectSuggestion; import com.vaadin.shared.EventId; import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; @@ -150,7 +151,7 @@ public class ComboBoxConnector extends AbstractFieldConnector implements oldSuggestionTextMatchTheOldSelection = isWidgetsCurrentSelectionTextInTextBox(); getWidget().currentSuggestions.clear(); - if (!getWidget().isWaitingForFilteringResponse()) { + if (!getDataReceivedHandler().isWaitingForFilteringResponse()) { /* * Clear the current suggestions as the server response always * includes the new ones. Exception is when filtering, then we @@ -191,7 +192,8 @@ public class ComboBoxConnector extends AbstractFieldConnector implements // started. if (selectedKeys.length > 0 && !selectedKeys[0].equals("")) { performSelection(selectedKeys[0]); - } else if (!getWidget().isWaitingForFilteringResponse() + } else if (!getDataReceivedHandler() + .isWaitingForFilteringResponse() && uidl.hasAttribute("selectedCaption")) { // scrolling to correct page is disabled, caption is passed as a // special parameter @@ -203,10 +205,10 @@ public class ComboBoxConnector extends AbstractFieldConnector implements } // TODO even this condition should probably be moved to the handler - if ((getWidget().isWaitingForFilteringResponse() && getWidget().lastFilter + if ((getDataReceivedHandler().isWaitingForFilteringResponse() && getWidget().lastFilter .toLowerCase().equals(uidl.getStringVariable("filter"))) || popupOpenAndCleared) { - getWidget().getDataReceivedHandler().dataReceived(); + getDataReceivedHandler().dataReceived(); } // Calculate minimum textarea width @@ -229,7 +231,7 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().initDone = true; // TODO this should perhaps be moved to be a part of dataReceived() - getWidget().getDataReceivedHandler().serverReplyHandled(); + getDataReceivedHandler().serverReplyHandled(); } private void performSelection(String selectedKey) { @@ -239,9 +241,8 @@ public class ComboBoxConnector extends AbstractFieldConnector implements if (!suggestionKey.equals(selectedKey)) { continue; } - if (!getWidget().isWaitingForFilteringResponse() - || getWidget().getDataReceivedHandler() - .isPopupOpenerClicked()) { + if (!getDataReceivedHandler().isWaitingForFilteringResponse() + || getDataReceivedHandler().isPopupOpenerClicked()) { if (!suggestionKey.equals(getWidget().selectedOptionKey) || suggestion.getReplacementString().equals( getWidget().tb.getText()) @@ -270,8 +271,8 @@ public class ComboBoxConnector extends AbstractFieldConnector implements } private void resetSelection() { - if (!getWidget().isWaitingForFilteringResponse() - || getWidget().getDataReceivedHandler().isPopupOpenerClicked()) { + if (!getDataReceivedHandler().isWaitingForFilteringResponse() + || getDataReceivedHandler().isPopupOpenerClicked()) { // select nulled if (!getWidget().focused) { /* @@ -304,6 +305,10 @@ public class ComboBoxConnector extends AbstractFieldConnector implements return (VFilterSelect) super.getWidget(); } + private DataReceivedHandler getDataReceivedHandler() { + return getWidget().getDataReceivedHandler(); + } + @Override public ComboBoxState getState() { return (ComboBoxState) super.getState(); @@ -436,7 +441,7 @@ public class ComboBoxConnector extends AbstractFieldConnector implements // We need this here to be consistent with the all the calls. // Then set your specific selection type only after // a server request method call. - getWidget().getDataReceivedHandler().anyRequestSentToServer(); + getDataReceivedHandler().anyRequestSentToServer(); } } |