From 3229847265dc30cced90e6718bd477cf4e9fbdf4 Mon Sep 17 00:00:00 2001 From: Tapio Aali Date: Tue, 16 Jul 2013 16:15:01 +0300 Subject: Fix lost focus in Table when refreshing row cache (#12231) svn changeset:25991/svn branch:6.8 svn changeset:26075/svn branch:6.8 svn changeset:26091/svn branch:6.8 Change-Id: Ia4a6ab4cc6ff98795a6d1f9b1701a345dc3f4dc4 --- client/src/com/vaadin/client/ui/VScrollTable.java | 4 ++-- .../src/com/vaadin/client/ui/table/TableConnector.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index e2e82a1959..2d177f29b5 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -194,7 +194,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, private SelectMode selectMode = SelectMode.NONE; - private final HashSet selectedRowKeys = new HashSet(); + public final HashSet selectedRowKeys = new HashSet(); /* * When scrolling and selecting at the same time, the selections are not in @@ -568,7 +568,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, this.rowKey = rowKey; this.left = left; this.top = top; - this.closeRegistration = menu.addCloseHandler(this); + closeRegistration = menu.addCloseHandler(this); } @Override diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index 36587ffe4d..47229dc9c7 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -266,7 +266,23 @@ public class TableConnector extends AbstractHasComponentsConnector implements if (!getWidget().focusedRow.isAttached() && !getWidget().rowRequestHandler.isRunning()) { // focused row has been orphaned, can't focus - getWidget().focusRowFromBody(); + if (getWidget().selectedRowKeys.contains(getWidget().focusedRow + .getKey())) { + // if row cache was refreshed, focused row should be + // in selection and exists with same index + getWidget().setRowFocus( + getWidget().getRenderedRowByKey( + getWidget().focusedRow.getKey())); + } else if (getWidget().selectedRowKeys.size() > 0) { + // try to focus any row in selection + getWidget().setRowFocus( + getWidget().getRenderedRowByKey( + getWidget().selectedRowKeys.iterator() + .next())); + } else { + // try to focus any row + getWidget().focusRowFromBody(); + } } } -- cgit v1.2.3