summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2016-09-13 13:29:00 +0300
committerHenri Sara <hesara@vaadin.com>2016-09-14 14:12:28 +0300
commit4aac5294bba6eff216cddaa826b7739494376ff7 (patch)
treeb72849b9c6085a0fe914031ff22ea7f368269d8f
parent17f6c77a03130c715843ec2324eb03ffc104e079 (diff)
downloadvaadin-framework-4aac5294bba6eff216cddaa826b7739494376ff7.tar.gz
vaadin-framework-4aac5294bba6eff216cddaa826b7739494376ff7.zip
Use state for ComboBox selection
Change-Id: I612376b4030a750c987ba2d8016a4dc44bc02d41
-rw-r--r--client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java31
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java15
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxClientRpc.java36
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java8
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java6
5 files changed, 23 insertions, 73 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();
}
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java
index 39c2bad8ba..8fdc8452ed 100644
--- a/server/src/main/java/com/vaadin/ui/ComboBox.java
+++ b/server/src/main/java/com/vaadin/ui/ComboBox.java
@@ -38,7 +38,6 @@ import com.vaadin.server.data.DataKeyMapper;
import com.vaadin.server.data.DataSource;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.DataCommunicatorConstants;
-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;
@@ -70,9 +69,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
if (value != null) {
selectedCaption = getItemCaptionProvider().apply(value);
}
- // FIXME now overlap between state and RPC
- getRpcProxy(ComboBoxClientRpc.class).setSelectedItem(key,
- selectedCaption);
+ getState().selectedItemCaption = selectedCaption;
}
}
@@ -151,16 +148,6 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
}
@Override
- public void setSelectedItem(String key) {
- // it seems both of these happen, and mean empty selection...
- if (key == null || "".equals(key)) {
- getSelectionModel().setSelectedFromClient(null);
- } else {
- getSelectionModel().setSelectedFromClient(key);
- }
- }
-
- @Override
public void setFilter(String filterText) {
filterstring = filterText;
if (filterText != null) {
diff --git a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxClientRpc.java b/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxClientRpc.java
deleted file mode 100644
index 1e8273c05e..0000000000
--- a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxClientRpc.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.shared.ui.combobox;
-
-import com.vaadin.shared.communication.ClientRpc;
-
-/**
- * Server to client RPC interface for ComboBox.
- *
- * @since
- */
-public interface ComboBoxClientRpc extends ClientRpc {
- /**
- * Set the current selection.
- *
- * @param selectedKey
- * the id of a single item or null to deselect the current value
- * @param selectedCaption
- * the caption of the selected item (used in case selection is
- * outside the lazy loaded range)
- */
- public void setSelectedItem(String selectedKey, String selectedCaption);
-}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java b/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java
index 9d6ba6d8a4..16b33b2cd4 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java
@@ -33,14 +33,6 @@ public interface ComboBoxServerRpc extends ServerRpc {
public void createNewItem(String itemValue);
/**
- * Set the current selection.
- *
- * @param item
- * the id of a single item or null to deselect the current value
- */
- public void setSelectedItem(String item);
-
- /**
* Sets the filter to use.
*
* @param filter
diff --git a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java b/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java
index e68d606e67..feb77722b7 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java
@@ -82,4 +82,10 @@ public class ComboBoxState extends AbstractSingleSelectState {
*/
public boolean scrollToSelectedItem = false;
+ /**
+ * The caption of the currently selected item or {@code null} if no item is
+ * selected.
+ */
+ public String selectedItemCaption;
+
}