Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.user.client.ui
Class Tree

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

All Implemented Interfaces:
  EventListener, HasAnimation, HasFocus, HasWidgets, SourcesFocusEvents, SourcesKeyboardEvents, SourcesTreeEvents, java.lang.Iterable<Widget>

    public class Tree

extends Widget
implements HasWidgets, SourcesTreeEvents, HasFocus, HasAnimation

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

>     public class TreeExample implements EntryPoint {

>       public void onModuleLoad() {
>         // Create a tree with a few items in it.
>         TreeItem root = new TreeItem("root");
>         root.addItem("item0");
>         root.addItem("item1");
>         root.addItem("item2");

>         // Add a CheckBox to the tree
>         TreeItem item = new TreeItem(new CheckBox("item3"));
>         root.addItem(item);

>         Tree t = new Tree();
>         t.addItem(root);

>         // Add it to the root panel.
>         RootPanel.get().add(t);
>       }
>     }

Nested Class Summary

Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
`UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled`

Field Summary

Fields inherited from class com.google.gwt.user.client.ui.UIObject
`DEBUG_ID_PREFIX`

Constructor Summary
`Tree()` Constructs an empty tree.
`Tree(TreeImages images)` Constructs a tree that uses the specified image bundle for images.
`Tree(TreeImages images, boolean useLeafImages)` Constructs a tree that uses the specified image bundle for images.

Method Summary
`void` | `add(Widget widget)` Adds the widget as a root tree item.
`void` | `addFocusListener(FocusListener listener)` Adds a listener interface to receive mouse events.
`TreeItem` | `addItem(java.lang.String itemText)` Adds a simple tree item containing the specified text.
`void` | `addItem(TreeItem item)` Adds an item to the root level of this tree.
`TreeItem` | `addItem(Widget widget)` Adds a new tree item containing the specified widget.
`void` | `addKeyboardListener(KeyboardListener listener)` Adds a listener interface to receive keyboard events.
`void` | `addMouseListener(MouseListener listener)`
`void` | `addTreeListener(TreeListener listener)` Adds a listener interface to receive tree events.
`void` | `clear()` Clears all tree items from the current tree.
`protected void` | `doAttachChildren()` If a widget implements HasWidgets, it must override this method and call onAttach() for each of its child widgets.
`protected void` | `doDetachChildren()` If a widget implements HasWidgets, it must override this method and call onDetach() for each of its child widgets.
`void` | `ensureSelectedItemVisible()` Ensures that the currently-selected item is visible, opening its parents and scrolling the tree as necessary.
`java.lang.String` | `getImageBase()` Deprecated. Use `Tree(TreeImages)` as it provides a more efficent and manageable way to supply a set of images to be used within a tree.
`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.
`boolean` | `isAnimationEnabled()`
`protected boolean` | `isKeyboardNavigationEnabled(TreeItem currentItem)` Indicates if keyboard navigation is enabled for the Tree and for a given TreeItem.
`java.util.Iterator<Widget>` | `iterator()` Gets an iterator for the contained widgets.
`void` | `onBrowserEvent(Event event)` Fired whenever a browser event is received.
`protected void` | `onEnsureDebugId(java.lang.String baseID)` Affected Elements: -root = The root `TreeItem`.
`protected void` | `onLoad()` This method is called immediately after a widget becomes attached to the browser's document.
`boolean` | `remove(Widget w)` Removes a child widget.
`void` | `removeFocusListener(FocusListener listener)` Removes a previously added listener interface.
`void` | `removeItem(TreeItem item)` 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)` Removes a previously added listener interface.
`void` | `removeTreeListener(TreeListener listener)` Removes a previously added listener interface.
`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` | `setImageBase(java.lang.String baseUrl)` Deprecated. Use `Tree(TreeImages)` as it provides a more efficent and manageable way to supply a set of images to be used within a tree.
`void` | `setSelectedItem(TreeItem item)` Selects a specified item.
`void` | `setSelectedItem(TreeItem item, boolean fireEvents)` Selects a specified item.
`void` | `setTabIndex(int index)` Sets the widget's position in the tab index.
`java.util.Iterator<TreeItem>` | `treeItemIterator()` Iterator of tree items.

Methods inherited from class com.google.gwt.user.client.ui.Widget
`getParent, isAttached, onAttach, onDetach, onUnload, removeFromParent`

Methods inherited from class com.google.gwt.user.client.ui.UIObject
`addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Tree

    public Tree()

  Constructs an empty tree.

### Tree

    public Tree(TreeImages images)

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

  Parameters:
    `images` - a bundle that provides tree specific images

### Tree

    public Tree(TreeImages images,
                boolean useLeafImages)

  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

Method Detail

### add

    public void add(Widget widget)

  Adds the widget as a root tree item.

  Specified by:
    `add` in interface `HasWidgets`
  Parameters:
    `widget` - widget to add.
  See Also:
    `HasWidgets.add(com.google.gwt.user.client.ui.Widget)`

### addFocusListener

    public void addFocusListener(FocusListener listener)

  Description copied from interface: `SourcesFocusEvents`
  Adds a listener interface to receive mouse events.

  Specified by:
    `addFocusListener` in interface `SourcesFocusEvents`
  Parameters:
    `listener` - the listener interface to add

### addItem

    public TreeItem addItem(java.lang.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

### addItem

    public void addItem(TreeItem item)

  Adds an item to the root level of this tree.

  Parameters:
    `item` - the item to be added

### addItem

    public TreeItem addItem(Widget widget)

  Adds a new tree item containing the specified widget.

  Parameters:
    `widget` - the widget to be added

### addKeyboardListener

    public void addKeyboardListener(KeyboardListener listener)

  Description copied from interface: `SourcesKeyboardEvents`
  Adds a listener interface to receive keyboard events.

  Specified by:
    `addKeyboardListener` in interface `SourcesKeyboardEvents`
  Parameters:
    `listener` - the listener interface to add

### addMouseListener

    public void addMouseListener(MouseListener listener)

### addTreeListener

    public void addTreeListener(TreeListener listener)

  Description copied from interface: `SourcesTreeEvents`
  Adds a listener interface to receive tree events.

  Specified by:
    `addTreeListener` in interface `SourcesTreeEvents`
  Parameters:
    `listener` - the listener interface to add

### clear

    public void clear()

  Clears all tree items from the current tree.

  Specified by:
    `clear` in interface `HasWidgets`

### ensureSelectedItemVisible

    public void ensureSelectedItemVisible()

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

### getImageBase

    @Deprecated
    public java.lang.String getImageBase()

  Deprecated. Use `Tree(TreeImages)` as it provides a more efficent and manageable way to supply a set of images to be used within a tree.

  Gets this tree's default image package.

  Returns:
    the tree's image package
  See Also:
    `setImageBase(java.lang.String)`

### getItem

    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

### getItemCount

    public int getItemCount()

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

  Returns:
    this tree's item count

### getSelectedItem

    public TreeItem getSelectedItem()

  Gets the currently selected item.

  Returns:
    the selected item

### getTabIndex

    public int getTabIndex()

  Description copied from interface: `HasFocus`
  Gets the widget's position in the tab index.

  Specified by:
    `getTabIndex` in interface `HasFocus`
  Returns:
    the widget's tab index

### isAnimationEnabled

    public boolean isAnimationEnabled()

  Specified by:
    `isAnimationEnabled` in interface `HasAnimation`
  Returns:
    true if animations are enabled, false if not

### iterator

    public java.util.Iterator<Widget> iterator()

  Description copied from interface: `HasWidgets`
  Gets an iterator for the contained widgets. This iterator is required to implement `Iterator.remove()`.

  Specified by:
    `iterator` in interface `HasWidgets`
  Specified by:
    `iterator` in interface `java.lang.Iterable<Widget>`

### onBrowserEvent

    public void onBrowserEvent(Event event)

  Description copied from interface: `EventListener`
  Fired whenever a browser event is received.

  Specified by:
    `onBrowserEvent` in interface `EventListener`
  Overrides:
    `onBrowserEvent` in class `Widget`
  Parameters:
    `event` - the event received

### remove

    public boolean remove(Widget w)

  Description copied from interface: `HasWidgets`
  Removes a child widget.

  Specified by:
    `remove` in interface `HasWidgets`
  Parameters:
    `w` - the widget to be removed
  Returns:
    `true` if the widget was present

### removeFocusListener

    public void removeFocusListener(FocusListener listener)

  Description copied from interface: `SourcesFocusEvents`
  Removes a previously added listener interface.

  Specified by:
    `removeFocusListener` in interface `SourcesFocusEvents`
  Parameters:
    `listener` - the listener interface to remove

### removeItem

    public void removeItem(TreeItem item)

  Removes an item from the root level of this tree.

  Parameters:
    `item` - the item to be removed

### removeItems

    public void removeItems()

  Removes all items from the root level of this tree.

### removeKeyboardListener

    public void removeKeyboardListener(KeyboardListener listener)

  Description copied from interface: `SourcesKeyboardEvents`
  Removes a previously added listener interface.

  Specified by:
    `removeKeyboardListener` in interface `SourcesKeyboardEvents`
  Parameters:
    `listener` - the listener interface to remove

### removeTreeListener

    public void removeTreeListener(TreeListener listener)

  Description copied from interface: `SourcesTreeEvents`
  Removes a previously added listener interface.

  Specified by:
    `removeTreeListener` in interface `SourcesTreeEvents`
  Parameters:
    `listener` - the listener interface to remove

### setAccessKey

    public void setAccessKey(char key)

  Description copied from interface: `HasFocus`
  Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.

  Specified by:
    `setAccessKey` in interface `HasFocus`
  Parameters:
    `key` - the widget's access key

### setAnimationEnabled

    public void setAnimationEnabled(boolean enable)

  Description copied from interface: `HasAnimation`
  Enable or disable animations.

  Specified by:
    `setAnimationEnabled` in interface `HasAnimation`
  Parameters:
    `enable` - true to enable, false to disable

### setFocus

    public void setFocus(boolean focus)

  Description copied from interface: `HasFocus`
  Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.

  Specified by:
    `setFocus` in interface `HasFocus`
  Parameters:
    `focus` - whether this widget should take focus or release it

### setImageBase

    @Deprecated
    public void setImageBase(java.lang.String baseUrl)

  Deprecated. Use `Tree(TreeImages)` as it provides a more efficent and manageable way to supply a set of images to be used within a tree.

  Sets the base URL under which this tree will find its default images. These images must be named "tree_white.gif", "tree_open.gif", and "tree_closed.gif".

  Parameters:
    `baseUrl` -

### setSelectedItem

    public void setSelectedItem(TreeItem item)

  Selects a specified item.

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

### setSelectedItem

    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

### setTabIndex

    public void setTabIndex(int index)

  Description copied from interface: `HasFocus`
  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.

  Specified by:
    `setTabIndex` in interface `HasFocus`
  Parameters:
    `index` - the widget's tab index

### treeItemIterator

    public java.util.Iterator<TreeItem> treeItemIterator()

  Iterator of tree items.

### doAttachChildren

    protected void doAttachChildren()

  Description copied from class: `Widget`
  If a widget implements HasWidgets, it must override this method and call onAttach() for each of its child widgets.

  Overrides:
    `doAttachChildren` in class `Widget`
  See Also:
    `Widget.onAttach()`

### doDetachChildren

    protected void doDetachChildren()

  Description copied from class: `Widget`
  If a widget implements HasWidgets, it must override this method and call onDetach() for each of its child widgets.

  Overrides:
    `doDetachChildren` in class `Widget`
  See Also:
    `Widget.onDetach()`

### isKeyboardNavigationEnabled

    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

### onEnsureDebugId

    protected void onEnsureDebugId(java.lang.String baseID)

  Affected Elements:
  - -root = The root `TreeItem`.

  Overrides:
    `onEnsureDebugId` in class `UIObject`
  Parameters:
    `baseID` - the base ID used by the main element
  See Also:
    `UIObject.onEnsureDebugId(String)`

### onLoad

    protected void onLoad()

  Description copied from class: `Widget`
  This method is called immediately after a widget becomes attached to the browser's document.

  Overrides:
    `onLoad` in class `Widget`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD