}
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();) {
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()));
childNodeContainer.add(childTree);
}
if (!i.hasNext()) {
- childTree.addStyleDependentName(childTree.isLeaf()
- ? "leaf-last" : "last");
+ childTree
+ .addStyleDependentName(childTree.isLeaf() ? "leaf-last"
+ : "last");
childTree.childNodeContainer.addStyleDependentName("last");
}
}
*/
protected boolean handleKeyNavigation(int keycode, boolean ctrl,
boolean shift) {
-
// Navigate down
if (keycode == getNavigationDownKey()) {
TreeNode node = null;
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>TreeKeyboardNavigationValidators</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.tree.TreeKeyboardNavigationValidators?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[0]</td>
+ <td>7,10</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>right</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>right</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>right</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>5-2-sel</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
--- /dev/null
+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;
+ }
+
+}