java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Tree

Class Overview

A standard hierarchical tree widget. The tree contains a hierarchy of TreeItems that the user can open, close, and select.

CSS Style Rules

.gwt-Tree
the tree itself
.gwt-Tree .gwt-TreeItem
a tree item
.gwt-Tree .gwt-TreeItem-selected
a selected tree item

Example

{@example com.google.gwt.examples.TreeExample}

Summary

Nested Classes
interface Tree.Resources A ClientBundle that provides images for this widget. 
[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
Tree()
Constructs an empty tree.
Tree(Tree.Resources resources)
Constructs a tree that uses the specified ClientBundle for images.
Tree(Tree.Resources resources, boolean useLeafImages)
Constructs a tree that uses the specified ClientBundle for images.
Tree(TreeImages images)
This constructor is deprecated. replaced by Tree(Resources)
Tree(TreeImages images, boolean useLeafImages)
This constructor is deprecated. replaced by Tree(Resources, boolean)
Public Methods
void add(Widget widget)
Adds the widget as a root tree item.
HandlerRegistration addBlurHandler(BlurHandler handler)
Adds a BlurEvent handler.
HandlerRegistration addCloseHandler(CloseHandler<TreeItem> handler)
HandlerRegistration addFocusHandler(FocusHandler handler)
Adds a FocusEvent handler.
void addFocusListener(FocusListener listener)
This method is deprecated. Use addFocusHandler(FocusHandler) instead
TreeItem addItem(String itemHtml)
Adds a simple tree item containing the specified html.
void addItem(TreeItem item)
Adds an item to the root level of this tree.
void addItem(IsTreeItem isItem)
Adds an item to the root level of this tree.
TreeItem addItem(Widget widget)
Adds a new tree item containing the specified widget.
TreeItem addItem(SafeHtml itemHtml)
Adds a simple tree item containing the specified html.
HandlerRegistration addKeyDownHandler(KeyDownHandler handler)
Adds a KeyDownEvent handler.
HandlerRegistration addKeyPressHandler(KeyPressHandler handler)
Adds a KeyPressEvent handler.
HandlerRegistration addKeyUpHandler(KeyUpHandler handler)
Adds a KeyUpEvent handler.
void addKeyboardListener(KeyboardListener listener)
HandlerRegistration addMouseDownHandler(MouseDownHandler handler)
Adds a MouseDownEvent handler.
void addMouseListener(MouseListener listener)
HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)
Adds a MouseMoveEvent handler.
HandlerRegistration addMouseOutHandler(MouseOutHandler handler)
Adds a MouseOutEvent handler.
HandlerRegistration addMouseOverHandler(MouseOverHandler handler)
Adds a MouseOverEvent handler.
HandlerRegistration addMouseUpHandler(MouseUpHandler handler)
Adds a MouseUpEvent handler.
HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)
Adds a MouseWheelEvent handler.
final HandlerRegistration addOpenHandler(OpenHandler<TreeItem> handler)
HandlerRegistration addSelectionHandler(SelectionHandler<TreeItem> handler)
TreeItem addTextItem(String itemText)
Adds a simple tree item containing the specified text.
void addTreeListener(TreeListener listener)
void clear()
Clears all tree items from the current tree.
void ensureSelectedItemVisible()
Ensures that the currently-selected item is visible, opening its parents and scrolling the tree as necessary.
TreeItem getItem(int index)
Gets the top-level tree item at the specified index.
int getItemCount()
Gets the number of items contained at the root of this tree.
TreeItem getSelectedItem()
Gets the currently selected item.
int getTabIndex()
Gets the widget's position in the tab index.
TreeItem insertItem(int beforeIndex, Widget widget)
Inserts a child tree item at the specified index containing the specified widget.
void insertItem(int beforeIndex, TreeItem item)
Inserts an item into the root level of this tree.
TreeItem insertItem(int beforeIndex, SafeHtml itemHtml)
Inserts a child tree item at the specified index containing the specified html.
TreeItem insertItem(int beforeIndex, String itemText)
Inserts a child tree item at the specified index containing the specified text.
boolean isAnimationEnabled()
Returns true if animations are enabled, false if not.
Iterator<Widget> iterator()
Gets an iterator for the contained widgets.
void onBrowserEvent(Event event)
Fired whenever a browser event is received.
boolean remove(Widget w)
Removes a child widget.
void removeFocusListener(FocusListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by addFocusHandler(FocusHandler) instead
void removeItem(TreeItem item)
Removes an item from the root level of this tree.
void removeItem(IsTreeItem isItem)
Removes an item from the root level of this tree.
void removeItems()
Removes all items from the root level of this tree.
void removeKeyboardListener(KeyboardListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by an add*Handler method instead
void removeMouseListener(MouseListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by an add*Handler method instead
void removeTreeListener(TreeListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by an add*Handler method instead
void setAccessKey(char key)
Sets the widget's 'access key'.
void setAnimationEnabled(boolean enable)
Enable or disable animations.
void setFocus(boolean focus)
Explicitly focus/unfocus this widget.
void setSelectedItem(TreeItem item, boolean fireEvents)
Selects a specified item.
void setSelectedItem(TreeItem item)
Selects a specified item.
void setTabIndex(int index)
Sets the widget's position in the tab index.
Iterator<TreeItem> treeItemIterator()
Iterator of tree items.
Protected Methods
void doAttachChildren()
If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call onAttach() for each of its child widgets.
void doDetachChildren()
If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call onDetach() for each of its child widgets.
boolean isKeyboardNavigationEnabled(TreeItem currentItem)
Indicates if keyboard navigation is enabled for the Tree and for a given TreeItem.
void onEnsureDebugId(String baseID)
Affected Elements:
void onLoad()
This method is called immediately after a widget becomes attached to the browser's document.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.dom.client.HasBlurHandlers
From interface com.google.gwt.event.dom.client.HasFocusHandlers
From interface com.google.gwt.event.dom.client.HasKeyDownHandlers
From interface com.google.gwt.event.dom.client.HasKeyPressHandlers
From interface com.google.gwt.event.dom.client.HasKeyUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseDownHandlers
From interface com.google.gwt.event.dom.client.HasMouseMoveHandlers
From interface com.google.gwt.event.dom.client.HasMouseOutHandlers
From interface com.google.gwt.event.dom.client.HasMouseOverHandlers
From interface com.google.gwt.event.dom.client.HasMouseUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseWheelHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.logical.shared.HasCloseHandlers
From interface com.google.gwt.event.logical.shared.HasOpenHandlers
From interface com.google.gwt.event.logical.shared.HasSelectionHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.Focusable
From interface com.google.gwt.user.client.ui.HasAnimation
From interface com.google.gwt.user.client.ui.HasTreeItems
From interface com.google.gwt.user.client.ui.HasWidgets
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesFocusEvents
From interface com.google.gwt.user.client.ui.SourcesKeyboardEvents
From interface com.google.gwt.user.client.ui.SourcesMouseEvents
From interface com.google.gwt.user.client.ui.SourcesTreeEvents
From interface java.lang.Iterable

Public Constructors

public Tree ()

Constructs an empty tree.

public Tree (Tree.Resources resources)

Constructs a tree that uses the specified ClientBundle for images.

Parameters
resources a bundle that provides tree specific images

public Tree (Tree.Resources resources, boolean useLeafImages)

Constructs a tree that uses the specified ClientBundle for images. If this tree does not use leaf images, the width of the Resources's leaf image will control the leaf indent.

Parameters
resources a bundle that provides tree specific images
useLeafImages use leaf images from bundle

public Tree (TreeImages images)

This constructor is deprecated.
replaced by Tree(Resources)

Constructs a tree that uses the specified image bundle for images.

Parameters
images a bundle that provides tree specific images

public Tree (TreeImages images, boolean useLeafImages)

This constructor is deprecated.
replaced by Tree(Resources, boolean)

Constructs a tree that uses the specified image bundle for images. If this tree does not use leaf images, the width of the TreeImage's leaf image will control the leaf indent.

Parameters
images a bundle that provides tree specific images
useLeafImages use leaf images from bundle

Public Methods

public void add (Widget widget)

Adds the widget as a root tree item.

Parameters
widget widget to add.

public HandlerRegistration addBlurHandler (BlurHandler handler)

Adds a BlurEvent handler.

Parameters
handler the blur handler
Returns

public HandlerRegistration addCloseHandler (CloseHandler<TreeItem> handler)

public HandlerRegistration addFocusHandler (FocusHandler handler)

Adds a FocusEvent handler.

Parameters
handler the focus handler
Returns

public void addFocusListener (FocusListener listener)

This method is deprecated.
Use addFocusHandler(FocusHandler) instead

Adds a listener interface to receive focus events.

Parameters
listener the listener interface to add

public TreeItem addItem (String itemHtml)

Adds a simple tree item containing the specified html.

Parameters
itemHtml the text of the item to be added
Returns
  • the item that was added

public void addItem (TreeItem item)

Adds an item to the root level of this tree.

Parameters
item the item to be added

public void addItem (IsTreeItem isItem)

Adds an item to the root level of this tree.

Parameters
isItem the wrapper of item to be added

public TreeItem addItem (Widget widget)

Adds a new tree item containing the specified widget.

Parameters
widget the widget to be added
Returns
  • the new item

public TreeItem addItem (SafeHtml itemHtml)

Adds a simple tree item containing the specified html.

Parameters
itemHtml the html of the item to be added
Returns
  • the item that was added

public HandlerRegistration addKeyDownHandler (KeyDownHandler handler)

Adds a KeyDownEvent handler.

Parameters
handler the key down handler
Returns

public HandlerRegistration addKeyPressHandler (KeyPressHandler handler)

Adds a KeyPressEvent handler.

Parameters
handler the key press handler
Returns

public HandlerRegistration addKeyUpHandler (KeyUpHandler handler)

Adds a KeyUpEvent handler.

Parameters
handler the key up handler
Returns

public void addKeyboardListener (KeyboardListener listener)

This method is deprecated.
Use addKeyDownHandler(KeyDownHandler), addKeyUpHandler(KeyUpHandler) and addKeyPressHandler(KeyPressHandler) instead

Adds a listener interface to receive keyboard events.

Parameters
listener the listener interface to add

public HandlerRegistration addMouseDownHandler (MouseDownHandler handler)

Adds a MouseDownEvent handler.

Parameters
handler the mouse down handler
Returns

public void addMouseListener (MouseListener listener)

This method is deprecated.
Use addMouseOverHandler(MouseOverHandler) addMouseMoveHandler(MouseMoveHandler), addMouseDownHandler(MouseDownHandler), addMouseUpHandler(MouseUpHandler) and addMouseOutHandler(MouseOutHandler) instead

Adds a listener interface to receive mouse events.

Parameters
listener the listener interface to add

public HandlerRegistration addMouseMoveHandler (MouseMoveHandler handler)

Adds a MouseMoveEvent handler.

Parameters
handler the mouse move handler
Returns

public HandlerRegistration addMouseOutHandler (MouseOutHandler handler)

Adds a MouseOutEvent handler.

Parameters
handler the mouse out handler
Returns

public HandlerRegistration addMouseOverHandler (MouseOverHandler handler)

Adds a MouseOverEvent handler.

Parameters
handler the mouse over handler
Returns

public HandlerRegistration addMouseUpHandler (MouseUpHandler handler)

Adds a MouseUpEvent handler.

Parameters
handler the mouse up handler
Returns

public HandlerRegistration addMouseWheelHandler (MouseWheelHandler handler)

Adds a MouseWheelEvent handler.

Parameters
handler the mouse wheel handler
Returns

public final HandlerRegistration addOpenHandler (OpenHandler<TreeItem> handler)

public HandlerRegistration addSelectionHandler (SelectionHandler<TreeItem> handler)

public TreeItem addTextItem (String itemText)

Adds a simple tree item containing the specified text.

Parameters
itemText the text of the item to be added
Returns
  • the item that was added

public void addTreeListener (TreeListener listener)

This method is deprecated.
Use addSelectionHandler(SelectionHandler), addOpenHandler(OpenHandler), and addCloseHandler(CloseHandler) instead

Adds a listener interface to receive tree events.

Parameters
listener the listener interface to add

public void clear ()

Clears all tree items from the current tree.

public void ensureSelectedItemVisible ()

Ensures that the currently-selected item is visible, opening its parents and scrolling the tree as necessary.

public TreeItem getItem (int index)

Gets the top-level tree item at the specified index.

Parameters
index the index to be retrieved
Returns
  • the item at that index

public int getItemCount ()

Gets the number of items contained at the root of this tree.

Returns
  • this tree's item count

public TreeItem getSelectedItem ()

Gets the currently selected item.

Returns
  • the selected item

public int getTabIndex ()

Gets the widget's position in the tab index.

Returns
  • the widget's tab index

public TreeItem insertItem (int beforeIndex, Widget widget)

Inserts a child tree item at the specified index containing the specified widget.

Parameters
beforeIndex the index where the item will be inserted
widget the widget to be added
Returns
  • the item that was added
Throws
IndexOutOfBoundsException if the index is out of range

public void insertItem (int beforeIndex, TreeItem item)

Inserts an item into the root level of this tree.

Parameters
beforeIndex the index where the item will be inserted
item the item to be added
Throws
IndexOutOfBoundsException if the index is out of range

public TreeItem insertItem (int beforeIndex, SafeHtml itemHtml)

Inserts a child tree item at the specified index containing the specified html.

Parameters
beforeIndex the index where the item will be inserted
itemHtml the html of the item to be added
Returns
  • the item that was added
Throws
IndexOutOfBoundsException if the index is out of range

public TreeItem insertItem (int beforeIndex, String itemText)

Inserts a child tree item at the specified index containing the specified text.

Parameters
beforeIndex the index where the item will be inserted
itemText the text to be added
Returns
  • the item that was added
Throws
IndexOutOfBoundsException if the index is out of range

public boolean isAnimationEnabled ()

Returns true if animations are enabled, false if not.

public Iterator<Widget> iterator ()

Gets an iterator for the contained widgets. This iterator is required to implement remove().

public void onBrowserEvent (Event event)

Fired whenever a browser event is received.

Parameters
event the event received

public boolean remove (Widget w)

Removes a child widget.

Parameters
w the widget to be removed
Returns
  • true if the widget was present

public void removeFocusListener (FocusListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by addFocusHandler(FocusHandler) instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void removeItem (TreeItem item)

Removes an item from the root level of this tree.

Parameters
item the item to be removed

public void removeItem (IsTreeItem isItem)

Removes an item from the root level of this tree.

Parameters
isItem the wrapper of item to be removed

public void removeItems ()

Removes all items from the root level of this tree.

public void removeKeyboardListener (KeyboardListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by an add*Handler method instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void removeMouseListener (MouseListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by an add*Handler method instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void removeTreeListener (TreeListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by an add*Handler method instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void setAccessKey (char key)

Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.

Parameters
key the widget's access key

public void setAnimationEnabled (boolean enable)

Enable or disable animations.

Parameters
enable true to enable, false to disable

public void setFocus (boolean focus)

Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.

Parameters
focus whether this widget should take focus or release it

public void setSelectedItem (TreeItem item, boolean fireEvents)

Selects a specified item.

Parameters
item the item to be selected, or null to deselect all items
fireEvents true to allow selection events to be fired

public void setSelectedItem (TreeItem item)

Selects a specified item.

Parameters
item the item to be selected, or null to deselect all items

public void setTabIndex (int index)

Sets the widget's position in the tab index. If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to -1 will cause this widget to be removed from the tab order.

Parameters
index the widget's tab index

public Iterator<TreeItem> treeItemIterator ()

Iterator of tree items.

Returns
  • the iterator

Protected Methods

protected void doAttachChildren ()

If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call onAttach() for each of its child widgets.

protected void doDetachChildren ()

If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call onDetach() for each of its child widgets.

protected boolean isKeyboardNavigationEnabled (TreeItem currentItem)

Indicates if keyboard navigation is enabled for the Tree and for a given TreeItem. Subclasses of Tree can override this function to selectively enable or disable keyboard navigation.

Parameters
currentItem the currently selected TreeItem
Returns
  • true if the Tree will response to arrow keys by changing the currently selected item

protected void onEnsureDebugId (String baseID)

Affected Elements:

Parameters
baseID the base ID used by the main element

protected void onLoad ()

This method is called immediately after a widget becomes attached to the browser's document.