diff options
author | Henri Sara <hesara@vaadin.com> | 2016-09-13 13:29:00 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2016-09-14 14:12:28 +0300 |
commit | 4aac5294bba6eff216cddaa826b7739494376ff7 (patch) | |
tree | b72849b9c6085a0fe914031ff22ea7f368269d8f /client/src | |
parent | 17f6c77a03130c715843ec2324eb03ffc104e079 (diff) | |
download | vaadin-framework-4aac5294bba6eff216cddaa826b7739494376ff7.tar.gz vaadin-framework-4aac5294bba6eff216cddaa826b7739494376ff7.zip |
Use state for ComboBox selection
Change-Id: I612376b4030a750c987ba2d8016a4dc44bc02d41
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java | 31 |
1 files changed, 16 insertions, 15 deletions
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 56db5b56cb..7cc1ea7322 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,7 +16,7 @@ package com.vaadin.client.ui.combobox; import com.vaadin.client.Profiler; -import com.vaadin.client.communication.RpcProxy; +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; @@ -30,8 +30,8 @@ import com.vaadin.shared.Registration; import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; import com.vaadin.shared.data.DataCommunicatorConstants; import com.vaadin.shared.data.selection.SelectionModel; +import com.vaadin.shared.data.selection.SelectionServerRpc; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.combobox.ComboBoxClientRpc; import com.vaadin.shared.ui.combobox.ComboBoxConstants; import com.vaadin.shared.ui.combobox.ComboBoxServerRpc; import com.vaadin.shared.ui.combobox.ComboBoxState; @@ -44,11 +44,12 @@ public class ComboBoxConnector extends AbstractListingConnector<SelectionModel.Single<?>> implements HasDataSource, SimpleManagedLayout, HasErrorIndicator { - protected ComboBoxServerRpc rpc = RpcProxy.create(ComboBoxServerRpc.class, - this); + private ComboBoxServerRpc rpc = getRpcProxy(ComboBoxServerRpc.class); + private SelectionServerRpc selectionRpc = getRpcProxy( + SelectionServerRpc.class); - protected FocusAndBlurServerRpc focusAndBlurRpc = RpcProxy - .create(FocusAndBlurServerRpc.class, this); + private FocusAndBlurServerRpc focusAndBlurRpc = getRpcProxy( + FocusAndBlurServerRpc.class); private Registration dataChangeHandlerRegistration; @@ -56,14 +57,6 @@ public class ComboBoxConnector protected void init() { super.init(); getWidget().connector = this; - registerRpc(ComboBoxClientRpc.class, new ComboBoxClientRpc() { - @Override - public void setSelectedItem(String selectedKey, - String selectedCaption) { - getDataReceivedHandler().updateSelectionFromServer(selectedKey, - selectedCaption); - } - }); } @Override @@ -94,6 +87,12 @@ public class ComboBoxConnector Profiler.leave("ComboBoxConnector.onStateChanged update content"); } + @OnStateChange({ "selectedItemKey", "selectedItemCaption" }) + private void onSelectionChange() { + getDataReceivedHandler().updateSelectionFromServer( + getState().selectedItemKey, getState().selectedItemCaption); + } + @Override public VComboBox getWidget() { return (VComboBox) super.getWidget(); @@ -202,7 +201,9 @@ public class ComboBoxConnector * the current selected item key */ public void sendSelection(String selectionKey) { - rpc.setSelectedItem(selectionKey); + // map also the special empty string option key (from data change + // handler below) to null + selectionRpc.select("".equals(selectionKey) ? null : selectionKey); getDataReceivedHandler().clearPendingNavigation(); } |