From 3229847265dc30cced90e6718bd477cf4e9fbdf4 Mon Sep 17 00:00:00 2001 From: Tapio Aali Date: Tue, 16 Jul 2013 16:15:01 +0300 Subject: [PATCH] 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 --- .../com/vaadin/client/ui/VScrollTable.java | 4 +- .../client/ui/table/TableConnector.java | 18 +++++- .../table/TableFocusOnRefreshRowCache.html | 61 +++++++++++++++++++ .../table/TableFocusOnRefreshRowCache.java | 37 +++++++++++ .../table/MultiSelectWithRemovedRow.html | 2 +- 5 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.html create mode 100644 tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.java 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(); + } } } diff --git a/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.html b/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.html new file mode 100644 index 0000000000..b5f4d9b418 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.html @@ -0,0 +1,61 @@ + + + + + + +TableFocusOnRefreshRowCache + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TableFocusOnRefreshRowCache
open/run/com.vaadin.tests.components.table.TableFocusOnRefreshRowCache?restartApplication
scrollvaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]3161
pause500
mouseClickvaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[42]/domChild[0]/domChild[0]186,-3151
assertNotCSSClassvaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[23]v-table-focus
+ + diff --git a/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.java b/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.java new file mode 100644 index 0000000000..a4bd11cf9c --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.event.ItemClickEvent; +import com.vaadin.event.ItemClickEvent.ItemClickListener; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Table; + +public class TableFocusOnRefreshRowCache extends TestBase { + + @Override + protected void setup() { + final Table table = new Table(); + table.setSizeFull(); + table.addContainerProperty("Name", String.class, null); + for (int i = 0; i < 200; i++) { + table.addItem(new Object[] { "Item " + i }, i); + } + + table.setSelectable(true); + table.addListener(new ItemClickListener() { + public void itemClick(ItemClickEvent event) { + table.refreshRowCache(); + } + }); + addComponent(table); + } + + @Override + protected String getDescription() { + return "Calling Table#refreshRowCache() loses cell focus"; + } + + @Override + protected Integer getTicketNumber() { + return 11797; + } +} diff --git a/uitest/src/com/vaadin/tests/components/table/MultiSelectWithRemovedRow.html b/uitest/src/com/vaadin/tests/components/table/MultiSelectWithRemovedRow.html index c41f3fbfdd..670736127b 100644 --- a/uitest/src/com/vaadin/tests/components/table/MultiSelectWithRemovedRow.html +++ b/uitest/src/com/vaadin/tests/components/table/MultiSelectWithRemovedRow.html @@ -91,7 +91,7 @@ assertText vaadin=runcomvaadintestscomponentstableMultiSelectWithRemovedRow::PID_SLog_row_0 - 4. Selection: [William, Averell, Bob, Grat] + 4. Selection: [Averell, Bob, Grat] -- 2.39.5