summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-12-11 11:39:16 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-12-14 08:51:14 +0000
commit38a4ae4130b0e82292bf92d055d0d9784b7de029 (patch)
tree2f2e95634ce726aaf1c32ad4e7c421746e111b82 /client
parent4e0bfcdd1f49050911029383f59ff2f94e82650e (diff)
downloadvaadin-framework-38a4ae4130b0e82292bf92d055d0d9784b7de029.tar.gz
vaadin-framework-38a4ae4130b0e82292bf92d055d0d9784b7de029.zip
Fix selecting a row that was deselected on the server (#19360)
Client-side connector of the SingleSelectionModel attempts to keep track of currently selected row. This tracking gets lost when the row get deselected on the server-side. Special case is now correctly handled. Change-Id: I1c45548bd11536bc85cddbc2ba8b6225965c1194
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/connectors/SingleSelectionModelConnector.java42
1 files changed, 32 insertions, 10 deletions
diff --git a/client/src/com/vaadin/client/connectors/SingleSelectionModelConnector.java b/client/src/com/vaadin/client/connectors/SingleSelectionModelConnector.java
index b963014256..f8c2854815 100644
--- a/client/src/com/vaadin/client/connectors/SingleSelectionModelConnector.java
+++ b/client/src/com/vaadin/client/connectors/SingleSelectionModelConnector.java
@@ -92,21 +92,29 @@ public class SingleSelectionModelConnector extends
@Override
public boolean select(JsonObject row) {
boolean changed = false;
- if ((row == null && isDeselectAllowed())
- || (row != null && !getRowHandle(row).equals(selectedRow))) {
+
+ if (row == null && !isDeselectAllowed()) {
+ // Attempting to deselect, even though it's not allowed.
+ } else {
if (selectedRow != null) {
- selectedRow.getRow().remove(GridState.JSONKEY_SELECTED);
- selectedRow.updateRow();
- selectedRow.unpin();
- selectedRow = null;
+ // Check if currently re-selected row was deselected from
+ // the server.
+ if (row != null && getRowHandle(row).equals(selectedRow)) {
+ if (selectedRow.getRow().hasKey(
+ GridState.JSONKEY_SELECTED)) {
+ // Everything is OK, no need to do anything.
+ return false;
+ }
+ }
+
+ // Remove old selected row
+ clearSelectedRow();
changed = true;
}
if (row != null) {
- selectedRow = getRowHandle(row);
- selectedRow.pin();
- selectedRow.getRow().put(GridState.JSONKEY_SELECTED, true);
- selectedRow.updateRow();
+ // Select the new row.
+ setSelectedRow(row);
changed = true;
}
}
@@ -119,6 +127,20 @@ public class SingleSelectionModelConnector extends
return changed;
}
+ private void setSelectedRow(JsonObject row) {
+ selectedRow = getRowHandle(row);
+ selectedRow.pin();
+ selectedRow.getRow().put(GridState.JSONKEY_SELECTED, true);
+ selectedRow.updateRow();
+ }
+
+ private void clearSelectedRow() {
+ selectedRow.getRow().remove(GridState.JSONKEY_SELECTED);
+ selectedRow.updateRow();
+ selectedRow.unpin();
+ selectedRow = null;
+ }
+
@Override
public boolean deselect(JsonObject row) {
if (getRowHandle(row).equals(selectedRow)) {