Browse Source

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: Iaf2547df1e6e61a1cb25b74172ea0fb095068375
tags/8.0.0.alpha1
Henri Sara 8 years ago
parent
commit
0b4dba5214

+ 47
- 48
client/src/main/java/com/vaadin/client/ui/VFilterSelect.java View File

@@ -302,7 +302,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,

// "Scroll" if change exceeds item height
while (Math.abs(deltaSum) >= SCROLL_UNIT_PX) {
if (!filterSelect.waitingForFilteringResponse) {
if (!filterSelect.dataReceivedHandler
.isWaitingForFilteringResponse()) {
// Move selection if page flip is not in progress
if (deltaSum < 0) {
filterSelect.suggestionPopup.selectPrevItem();
@@ -609,7 +610,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
@@ -1151,20 +1152,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();
}

/**
@@ -1417,6 +1405,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
@@ -1426,7 +1416,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
suggestionPopup.showSuggestions(currentSuggestions, currentPage,
totalMatches);

setWaitingForFilteringResponse(false);
waitingForFilteringResponse = false;

if (!popupOpenerClicked) {
navigateItemAfterPageChange();
@@ -1505,8 +1495,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;
}

/**
@@ -1516,6 +1509,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
@@ -1596,9 +1620,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
/** For internal use only. May be removed or replaced in the future. */
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;

@@ -1844,7 +1865,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
}

setWaitingForFilteringResponse(true);
dataReceivedHandler.startWaitingForFilteringResponse();
connector.requestPage(filter, page);

lastFilter = filter;
@@ -1943,7 +1964,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;
@@ -2073,7 +2094,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
@@ -2675,7 +2696,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,

@Override
public boolean isWorkPending() {
return isWaitingForFilteringResponse()
return dataReceivedHandler.isWaitingForFilteringResponse()
|| suggestionPopup.lazyPageScroller.isRunning();
}

@@ -2704,28 +2725,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
return explicitSelectedCaption;
}

/**
* 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.

+ 16
- 11
client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java View File

@@ -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;
@@ -157,7 +158,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
@@ -202,7 +203,8 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
// it as well and clear selected caption
getWidget().setSelectedCaption(null);

} else if (!getWidget().isWaitingForFilteringResponse()
} else if (!getDataReceivedHandler()
.isWaitingForFilteringResponse()
&& uidl.hasAttribute("selectedCaption")) {
// scrolling to correct page is disabled, caption is passed as a
// special parameter
@@ -214,10 +216,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
@@ -240,7 +242,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) {
@@ -250,9 +252,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())
@@ -281,8 +282,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) {
/*
@@ -325,6 +326,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();
@@ -457,7 +462,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();
}

}

Loading…
Cancel
Save