Fixes Issue #534.
Changes the keyboard navigation on the tree to be more efficient and
more intuitive. The left arrow now expands the current node and
selects the first child if there is one. The right arrow now selects
the parent and collapses the current node and all its siblings. Also
includes many whitespace fixes.
Patch by: bobv
Review by: knorton
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@959 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/Tree.java b/user/src/com/google/gwt/user/client/ui/Tree.java
index dda3d4a..56149a0 100644
--- a/user/src/com/google/gwt/user/client/ui/Tree.java
+++ b/user/src/com/google/gwt/user/client/ui/Tree.java
@@ -1,12 +1,12 @@
/*
- * Copyright 2006 Google Inc.
- *
+ * Copyright 2007 Google Inc.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -117,7 +117,7 @@
/**
* Adds the widget as a root tree item.
- *
+ *
* @see com.google.gwt.user.client.ui.HasWidgets#add(com.google.gwt.user.client.ui.Widget)
* @param widget widget to add.
*/
@@ -134,7 +134,7 @@
/**
* Adds a simple tree item containing the specified text.
- *
+ *
* @param itemText the text of the item to be added
* @return the item that was added
*/
@@ -147,7 +147,7 @@
/**
* Adds an item to the root level of this tree.
- *
+ *
* @param item the item to be added
*/
public void addItem(TreeItem item) {
@@ -157,7 +157,7 @@
/**
* Adds a new tree item containing the specified widget.
- *
+ *
* @param widget the widget to be added
*/
public TreeItem addItem(Widget widget) {
@@ -215,7 +215,7 @@
/**
* Gets this tree's default image package.
- *
+ *
* @return the tree's image package
* @see #setImageBase
*/
@@ -225,7 +225,7 @@
/**
* Gets the top-level tree item at the specified index.
- *
+ *
* @param index the index to be retrieved
* @return the item at that index
*/
@@ -235,7 +235,7 @@
/**
* Gets the number of items contained at the root of this tree.
- *
+ *
* @return this tree's item count
*/
public int getItemCount() {
@@ -244,7 +244,7 @@
/**
* Gets the currently selected item.
- *
+ *
* @return the selected item
*/
public TreeItem getSelectedItem() {
@@ -362,6 +362,12 @@
case KeyboardListener.KEY_LEFT: {
if (curSelection.getState()) {
curSelection.setState(false);
+ } else {
+ TreeItem parent = curSelection.getParentItem();
+ if (parent != null) {
+ parent.setState(false);
+ setSelectedItem(parent);
+ }
}
DOM.eventPreventDefault(event);
break;
@@ -369,6 +375,9 @@
case KeyboardListener.KEY_RIGHT: {
if (!curSelection.getState()) {
curSelection.setState(true);
+ if (curSelection.getChildCount() > 0) {
+ setSelectedItem(curSelection.getChild(0));
+ }
}
DOM.eventPreventDefault(event);
break;
@@ -417,7 +426,7 @@
/**
* Removes an item from the root level of this tree.
- *
+ *
* @param item the item to be removed
*/
public void removeItem(TreeItem item) {
@@ -470,7 +479,7 @@
/**
* Selects a specified item.
- *
+ *
* @param item the item to be selected, or <code>null</code> to deselect all
* items
*/
@@ -480,7 +489,7 @@
/**
* Selects a specified item.
- *
+ *
* @param item the item to be selected, or <code>null</code> to deselect all
* items
* @param fireEvents <code>true</code> to allow selection events to be fired
@@ -554,7 +563,7 @@
/**
* Get the Set of child widgets. Exposed only to allow unit tests to validate
* tree.
- *
+ *
* @return the children
*/
Set getChildWidgets() {
@@ -620,7 +629,7 @@
/**
* Move the tree focus to the specified selected item.
- *
+ *
* @param selection
*/
private void moveFocus(TreeItem selection) {
@@ -726,8 +735,8 @@
private native boolean shouldTreeDelegateFocusToElement(Element elem) /*-{
var name = elem.nodeName;
- return ((name == "SELECT") ||
- (name == "INPUT") ||
+ return ((name == "SELECT") ||
+ (name == "INPUT") ||
(name == "TEXTAREA") ||
(name == "OPTION") ||
(name == "BUTTON") ||