From 98a4ab006bd67c63ce73e22fedeaf8bb892005c1 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 14 Apr 2011 12:45:52 +0000 Subject: [PATCH] focus now stays put when context menu or column selector is used svn changeset:18292/svn branch:6.5 --- .../terminal/gwt/client/ui/VScrollTable.java | 63 +++++++++++++------ 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index f964e1d462..b29118e244 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -1043,23 +1043,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, if (!focusedRow.isAttached()) { // focused row has been orphaned, can't focus focusedRow = null; - if (SELECT_MODE_SINGLE == selectMode - && selectedRowKeys.size() > 0) { - // try to focus a row currently selected and in viewport - String selectedRowKey = selectedRowKeys.iterator().next(); - if (selectedRowKey != null) { - VScrollTableRow renderedRow = getRenderedRowByKey(selectedRowKey); - if (renderedRow == null) { - setRowFocus(scrollBody - .getRowByRowIndex(firstRowInViewPort)); - } else { - setRowFocus(renderedRow); - } - } - } else { - // multiselect mode - setRowFocus(scrollBody.getRowByRowIndex(firstRowInViewPort)); - } + focusRowFromBody(); } } @@ -1082,6 +1066,24 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, headerChangedDuringUpdate = false; } + private void focusRowFromBody() { + if (selectedRowKeys.size() == 1) { + // try to focus a row currently selected and in viewport + String selectedRowKey = selectedRowKeys.iterator().next(); + if (selectedRowKey != null) { + VScrollTableRow renderedRow = getRenderedRowByKey(selectedRowKey); + if (renderedRow == null) { + setRowFocus(scrollBody.getRowByRowIndex(firstRowInViewPort)); + } else { + setRowFocus(renderedRow); + } + } + } else { + // multiselect mode + setRowFocus(scrollBody.getRowByRowIndex(firstRowInViewPort)); + } + } + protected VScrollTableBody createScrollBody() { return new VScrollTableBody(); } @@ -2707,11 +2709,13 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, String colKey; private boolean collapsed; + private VScrollTableRow currentlyFocusedRow; public VisibleColumnAction(String colKey) { super(VScrollTable.TableHead.this); this.colKey = colKey; caption = tHead.getHeaderCell(colKey).getCaption(); + currentlyFocusedRow = focusedRow; } @Override @@ -2732,6 +2736,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, .size()]), false); // let rowRequestHandler determine proper rows rowRequestHandler.refreshContent(); + lazyRevertFocusToRow(currentlyFocusedRow); } public void setCollapsed(boolean b) { @@ -4525,7 +4530,13 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, for (int i = 0; i < actions.length; i++) { final String actionKey = actionKeys[i]; final TreeAction a = new TreeAction(this, - String.valueOf(rowKey), actionKey); + String.valueOf(rowKey), actionKey) { + @Override + public void execute() { + super.execute(); + lazyRevertFocusToRow(VScrollTableRow.this); + } + }; a.setCaption(getActionCaption(actionKey)); a.setIconUrl(getActionIcon(actionKey)); actions[i] = a; @@ -5592,7 +5603,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, // Focus a row if no row is in focus if (focusedRow == null) { - setRowFocus(scrollBody.getRowByRowIndex(firstRowInViewPort)); + focusRowFromBody(); } else { setRowFocus(focusedRow); } @@ -5741,4 +5752,18 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, || keyCode == getNavigationEndKey() || keyCode == getNavigationStartKey(); } + + public void lazyRevertFocusToRow(final VScrollTableRow currentlyFocusedRow) { + Scheduler.get().scheduleFinally(new ScheduledCommand() { + public void execute() { + if (currentlyFocusedRow != null) { + setRowFocus(currentlyFocusedRow); + } else { + VConsole.log("no row?"); + focusRowFromBody(); + } + scrollBody.ensureFocus(); + } + }); + } } -- 2.39.5