aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2015-11-05 12:49:44 +0200
committerHenri Sara <hesara@vaadin.com>2016-01-15 14:42:56 +0200
commit40e237abf0fb89a42dc5e0b6be673b84e6bea062 (patch)
tree5e90124f75096e6304c63d8f17f90d0e934d0979
parent675684c2c28a138b22f39f1cb17a69640c22bfdc (diff)
downloadvaadin-framework-40e237abf0fb89a42dc5e0b6be673b84e6bea062.tar.gz
vaadin-framework-40e237abf0fb89a42dc5e0b6be673b84e6bea062.zip
Move ComboBox communication to connector (#19929)
This change extracts the client to server communication methods of VFilterSelect and moves them to the connector. Change-Id: I07f61abeda503de5d63e332d8ead10cf312115ba
-rw-r--r--client/src/com/vaadin/client/ui/VFilterSelect.java37
-rw-r--r--client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java82
2 files changed, 94 insertions, 25 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java
index 9459cc14a6..98950db746 100644
--- a/client/src/com/vaadin/client/ui/VFilterSelect.java
+++ b/client/src/com/vaadin/client/ui/VFilterSelect.java
@@ -64,9 +64,7 @@ import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.BrowserInfo;
-import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ComputedStyle;
-import com.vaadin.client.ConnectorMap;
import com.vaadin.client.DeferredWorker;
import com.vaadin.client.Focusable;
import com.vaadin.client.UIDL;
@@ -76,6 +74,7 @@ import com.vaadin.client.ui.aria.AriaHelper;
import com.vaadin.client.ui.aria.HandlesAriaCaption;
import com.vaadin.client.ui.aria.HandlesAriaInvalid;
import com.vaadin.client.ui.aria.HandlesAriaRequired;
+import com.vaadin.client.ui.combobox.ComboBoxConnector;
import com.vaadin.client.ui.menubar.MenuBar;
import com.vaadin.client.ui.menubar.MenuItem;
import com.vaadin.shared.AbstractComponentState;
@@ -130,6 +129,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
@Override
public String getDisplayString() {
final StringBuffer sb = new StringBuffer();
+ ApplicationConnection client = connector.getConnection();
final Icon icon = client.getIcon(client
.translateVaadinUri(untranslatedIconUri));
if (icon != null) {
@@ -171,6 +171,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* @return
*/
public String getIconUri() {
+ ApplicationConnection client = connector.getConnection();
return client.translateVaadinUri(untranslatedIconUri);
}
@@ -938,10 +939,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
// null is not visible on pages != 0, and not visible when
// filtering: handle separately
- client.updateVariable(paintableId, "filter", "", false);
- client.updateVariable(paintableId, "page", 0, false);
- client.updateVariable(paintableId, "selected", new String[] {},
- immediate);
+ connector.requestFirstPage();
afterUpdateClientVariables();
suggestionPopup.hide();
@@ -990,8 +988,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* Store last sent new item string to avoid double sends
*/
lastNewItemString = enteredItemValue;
- client.updateVariable(paintableId, "newitem",
- enteredItemValue, immediate);
+ connector.sendNewItem(enteredItemValue);
afterUpdateClientVariables();
}
} else if (item != null
@@ -1229,7 +1226,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
private IconWidget selectedItemIcon;
/** For internal use only. May be removed or replaced in the future. */
- public ApplicationConnection client;
+ public ComboBoxConnector connector;
/** For internal use only. May be removed or replaced in the future. */
public String paintableId;
@@ -1246,9 +1243,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
public final List<FilterSelectSuggestion> currentSuggestions = new ArrayList<FilterSelectSuggestion>();
/** For internal use only. May be removed or replaced in the future. */
- public boolean immediate;
-
- /** 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. */
@@ -1516,8 +1510,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
waitingForFilteringResponse = true;
- client.updateVariable(paintableId, "filter", filter, false);
- client.updateVariable(paintableId, "page", page, immediate);
+ connector.requestPage(filter, page);
afterUpdateClientVariables();
lastFilter = filter;
@@ -1638,8 +1631,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
if (!(newKey.equals(selectedOptionKey) || ("".equals(newKey) && selectedOptionKey == null))) {
selectedOptionKey = newKey;
- client.updateVariable(paintableId, "selected",
- new String[] { selectedOptionKey }, immediate);
+ connector.sendSelection(new String[] { selectedOptionKey });
afterUpdateClientVariables();
// currentPage = -1; // forget the page
@@ -1666,7 +1658,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
if (selectedItemIcon != null) {
panel.remove(selectedItemIcon);
}
- selectedItemIcon = new IconWidget(client.getIcon(iconUri));
+ selectedItemIcon = new IconWidget(connector.getConnection()
+ .getIcon(iconUri));
// Older IE versions don't scale icon correctly if DOM
// contains height and width attributes.
selectedItemIcon.getElement().removeAttribute("height");
@@ -1986,6 +1979,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
// If a focus event is not going to be sent, send the options
// request immediately; otherwise queue in the same burst as the
// focus event. Fixes #8321.
+ ApplicationConnection client = connector.getConnection();
boolean immediate = focused
|| !client.hasEventListeners(this, EventId.FOCUS);
filterOptions(-1, "", immediate);
@@ -2082,13 +2076,12 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
addStyleDependentName("focus");
+ ApplicationConnection client = connector.getConnection();
if (client.hasEventListeners(this, EventId.FOCUS)) {
client.updateVariable(paintableId, EventId.FOCUS, "", true);
afterUpdateClientVariables();
}
- ComponentConnector connector = ConnectorMap.get(client).getConnector(
- this);
client.getVTooltip().showAssistive(
connector.getTooltipInfo(getElement()));
}
@@ -2146,6 +2139,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
removeStyleDependentName("focus");
+ ApplicationConnection client = connector.getConnection();
if (client.hasEventListeners(this, EventId.BLUR)) {
client.updateVariable(paintableId, EventId.BLUR, "", true);
afterUpdateClientVariables();
@@ -2175,10 +2169,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* For internal use only. May be removed or replaced in the future.
*/
public void updateRootWidth() {
- ComponentConnector paintable = ConnectorMap.get(client).getConnector(
- this);
-
- if (paintable.isUndefinedWidth()) {
+ if (connector.isUndefinedWidth()) {
/*
* When the select has a undefined with we need to check that we are
diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
index 4dbaf6e004..449e519855 100644
--- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
+++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
@@ -48,6 +48,14 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
// update textbox text by a changed item caption.
private boolean oldSuggestionTextMatchTheOldSelection;
+ private boolean immediate;
+
+ @Override
+ protected void init() {
+ super.init();
+ getWidget().connector = this;
+ }
+
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
@@ -57,7 +65,7 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
getWidget().readonly = isReadOnly();
getWidget().updateReadOnly();
- getWidget().immediate = getState().immediate;
+ immediate = getState().immediate;
getWidget().setTextInputEnabled(getState().textInputAllowed);
@@ -79,7 +87,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Save details
- getWidget().client = client;
getWidget().paintableId = uidl.getId();
if (!isRealUpdate(uidl)) {
@@ -355,4 +362,75 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
getWidget().tb.setEnabled(widgetEnabled);
}
+ /*
+ * These methods exist to move communications out of VFilterSelect, and may
+ * be refactored/removed in the future
+ */
+
+ /**
+ * Send a message about a newly created item to the server.
+ *
+ * This method is for internal use only and may be removed in future
+ * versions.
+ *
+ * @since
+ * @param itemValue
+ * user entered string value for the new item
+ */
+ public void sendNewItem(String itemValue) {
+ getConnection().updateVariable(getConnectorId(), "newitem", itemValue,
+ immediate);
+ }
+
+ /**
+ * Send a message to the server to request the first page of items without
+ * filtering or selection.
+ *
+ * This method is for internal use only and may be removed in future
+ * versions.
+ *
+ * @since
+ */
+ public void requestFirstPage() {
+ getConnection().updateVariable(getConnectorId(), "filter", "", false);
+ getConnection().updateVariable(getConnectorId(), "page", 0, false);
+ getConnection().updateVariable(getConnectorId(), "selected",
+ new String[] {}, immediate);
+ }
+
+ /**
+ * Send a message to the server to request a page of items with a given
+ * filter.
+ *
+ * This method is for internal use only and may be removed in future
+ * versions.
+ *
+ * @since
+ * @param filter
+ * the current filter string
+ * @param page
+ * the page number to get
+ */
+ public void requestPage(String filter, int page) {
+ getConnection().updateVariable(getConnectorId(), "filter", filter,
+ false);
+ getConnection().updateVariable(getConnectorId(), "page", page,
+ immediate);
+ }
+
+ /**
+ * Send a message to the server updating the current selection.
+ *
+ * This method is for internal use only and may be removed in future
+ * versions.
+ *
+ * @since
+ * @param selection
+ * the current selection
+ */
+ public void sendSelection(String[] selection) {
+ getConnection().updateVariable(getConnectorId(), "selected", selection,
+ immediate);
+ }
+
}