From df63707e7b0c79875b7e25b942108038586a4a98 Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Tue, 6 Sep 2011 08:40:15 +0000 Subject: [PATCH] Fix for #7057 svn changeset:20874/svn branch:6.7 --- .../vaadin/terminal/gwt/client/ui/VTree.java | 19 +++- .../tree/TreeKeyboardNavigationValidators | 97 +++++++++++++++++++ .../TreeKeyboardNavigationValidators.java | 54 +++++++++++ 3 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators create mode 100644 tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index d63ddc5e02..6a1c131944 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -265,6 +265,8 @@ public class VTree extends FocusElementPanel implements Paintable, } body.clear(); + // clear out any references to nodes that no longer are attached + keyToNode.clear(); TreeNode childTree = null; UIDL childUidl = null; for (final Iterator i = uidl.getChildIterator(); i.hasNext();) { @@ -302,6 +304,17 @@ public class VTree extends FocusElementPanel implements Paintable, selectedIds = uidl.getStringArrayVariableAsSet("selected"); + // Update lastSelection and focusedNode to point to *actual* nodes again + // after the old ones have been cleared from the body. This fixes focus + // and keyboard navigation issues as described in #7057 and other + // tickets. + if (lastSelection != null) { + lastSelection = keyToNode.get(lastSelection.key); + } + if (focusedNode != null) { + setFocusedNode(keyToNode.get(focusedNode.key)); + } + if (lastSelection == null && focusedNode == null && !selectedIds.isEmpty()) { setFocusedNode(keyToNode.get(selectedIds.iterator().next())); @@ -1092,8 +1105,9 @@ public class VTree extends FocusElementPanel implements Paintable, childNodeContainer.add(childTree); } if (!i.hasNext()) { - childTree.addStyleDependentName(childTree.isLeaf() - ? "leaf-last" : "last"); + childTree + .addStyleDependentName(childTree.isLeaf() ? "leaf-last" + : "last"); childTree.childNodeContainer.addStyleDependentName("last"); } } @@ -1794,7 +1808,6 @@ public class VTree extends FocusElementPanel implements Paintable, */ protected boolean handleKeyNavigation(int keycode, boolean ctrl, boolean shift) { - // Navigate down if (keycode == getNavigationDownKey()) { TreeNode node = null; diff --git a/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators b/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators new file mode 100644 index 0000000000..8b9722df94 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators @@ -0,0 +1,97 @@ + + + + + + +TreeKeyboardNavigationValidators + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.tree.TreeKeyboardNavigationValidators?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[0]7,10
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]right
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]right
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]right
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
pressSpecialKeyvaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]down
screenCapture5-2-sel
+ + diff --git a/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java b/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java new file mode 100644 index 0000000000..2a545065c4 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java @@ -0,0 +1,54 @@ +package com.vaadin.tests.components.tree; + +import com.vaadin.data.Container; +import com.vaadin.data.util.HierarchicalContainer; +import com.vaadin.data.validator.AbstractValidator; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Tree; + +public class TreeKeyboardNavigationValidators extends TestBase { + + @Override + protected void setup() { + addComponent(getTree()); + } + + private Tree getTree() { + Tree tree = new Tree(); + tree.setSizeFull(); + tree.setContainerDataSource(generateHierarchicalContainer()); + tree.setImmediate(true); + tree.addValidator(new AbstractValidator("failed") { + public boolean isValid(Object value) { + return false; + } + + }); + return tree; + } + + private Container generateHierarchicalContainer() { + HierarchicalContainer cont = new HierarchicalContainer(); + for (int i = 1; i < 6; i++) { + cont.addItem(i); + for (int j = 1; j < 3; j++) { + String id = i + " -> " + j; + cont.addItem(id); + cont.setChildrenAllowed(id, false); + cont.setParent(id, i); + } + } + return cont; + } + + @Override + protected String getDescription() { + return "Keyboard navigation should still work in a tree with validators."; + } + + @Override + protected Integer getTicketNumber() { + return 7057; + } + +} -- 2.39.5