public class

TreeItem

extends UIObject
implements HasSafeHtml HasHTML HasTreeItems IsTreeItem
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.TreeItem

Class Overview

An item that can be contained within a Tree. Each tree item is assigned a unique DOM id in order to support ARIA. See Accessibility for more information.

Example

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

Summary

Nested Classes
class TreeItem.TreeItemImpl Implementation class for TreeItem
class TreeItem.TreeItemImplIE6 IE specific implementation class for TreeItem
[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
TreeItem()
Creates an empty tree item.
TreeItem(String html)
Constructs a tree item with the given HTML.
TreeItem(SafeHtml html)
Constructs a tree item with the given HTML.
TreeItem(Widget widget)
Constructs a tree item with the given Widget.
Public Methods
TreeItem addItem(String itemHtml)
Adds a child tree item containing the specified html.
void addItem(TreeItem item)
Adds another item as a child to this one.
TreeItem addItem(Widget widget)
Adds a child tree item containing the specified widget.
void addItem(IsTreeItem isItem)
Adds another item as a child to this one.
TreeItem addItem(SafeHtml itemHtml)
Adds a child tree item containing the specified html.
TreeItem addTextItem(String itemText)
Adds a child tree item containing the specified text.
TreeItem asTreeItem()
Returns the TreeItem aspect of the receiver.
TreeItem getChild(int index)
Gets the child at the specified index.
int getChildCount()
Gets the number of children contained in this item.
int getChildIndex(TreeItem child)
Gets the index of the specified child item.
String getHTML()
Gets this object's contents as HTML.
TreeItem getParentItem()
Gets this item's parent.
boolean getState()
Gets whether this item's children are displayed.
String getText()
Gets this object's text.
final Tree getTree()
Gets the tree that contains this item.
Object getUserObject()
Gets the user-defined object associated with this item.
Widget getWidget()
Gets the Widget associated with this tree item.
TreeItem insertItem(int beforeIndex, Widget widget)
Inserts a child tree item at the specified index containing the specified widget.
TreeItem insertItem(int beforeIndex, SafeHtml itemHtml)
Inserts a child tree item at the specified index containing the specified text.
TreeItem insertItem(int beforeIndex, String itemText)
Inserts a child tree item at the specified index containing the specified text.
void insertItem(int beforeIndex, TreeItem item)
Inserts an item as a child to this one.
boolean isSelected()
Determines whether this item is currently selected.
void remove()
Removes this item from its tree.
void removeItem(IsTreeItem isItem)
Removes one of this item's children.
void removeItem(TreeItem item)
Removes one of this item's children.
void removeItems()
Removes all of this item's children.
void setHTML(SafeHtml html)
Sets this object's contents via known-safe HTML.
void setHTML(String html)
Sets this object's contents via HTML.
void setSelected(boolean selected)
Selects or deselects this item.
void setState(boolean open, boolean fireEvents)
Sets whether this item's children are displayed.
void setState(boolean open)
Sets whether this item's children are displayed.
void setText(String text)
Sets this object's text.
void setUserObject(Object userObj)
Sets the user-defined object associated with this item.
void setWidget(Widget newWidget)
Sets the current widget.
Protected Methods
Focusable getFocusable()
Returns a suggested Focusable instance to use when this tree item is selected.
HasFocus getFocusableWidget()
This method is deprecated. use getFocusable() instead
void onEnsureDebugId(String baseID)
Affected Elements:
  • -content = The text or Widget next to the image.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.safehtml.client.HasSafeHtml
From interface com.google.gwt.user.client.ui.HasHTML
From interface com.google.gwt.user.client.ui.HasText
From interface com.google.gwt.user.client.ui.HasTreeItems
From interface com.google.gwt.user.client.ui.IsTreeItem

Public Constructors

public TreeItem ()

Creates an empty tree item.

public TreeItem (String html)

Constructs a tree item with the given HTML.

Parameters
html the item's HTML

public TreeItem (SafeHtml html)

Constructs a tree item with the given HTML.

Parameters
html the item's HTML

public TreeItem (Widget widget)

Constructs a tree item with the given Widget.

Parameters
widget the item's widget

Public Methods

public TreeItem addItem (String itemHtml)

Adds a child tree item containing the specified html.

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

public void addItem (TreeItem item)

Adds another item as a child to this one.

Parameters
item the item to be added

public TreeItem addItem (Widget widget)

Adds a child tree item containing the specified widget.

Parameters
widget the widget to be added
Returns
  • the item that was added

public void addItem (IsTreeItem isItem)

Adds another item as a child to this one.

Parameters
isItem the wrapper of item to be added

public TreeItem addItem (SafeHtml itemHtml)

Adds a child tree item containing the specified html.

Parameters
itemHtml the item's HTML
Returns
  • the item that was added

public TreeItem addTextItem (String itemText)

Adds a child tree item containing the specified text.

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

public TreeItem asTreeItem ()

Returns the TreeItem aspect of the receiver.

public TreeItem getChild (int index)

Gets the child at the specified index.

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

public int getChildCount ()

Gets the number of children contained in this item.

Returns
  • this item's child count.

public int getChildIndex (TreeItem child)

Gets the index of the specified child item.

Parameters
child the child item to be found
Returns
  • the child's index, or -1 if none is found

public String getHTML ()

Gets this object's contents as HTML.

Returns
  • the object's HTML

public TreeItem getParentItem ()

Gets this item's parent.

Returns
  • the parent item

public boolean getState ()

Gets whether this item's children are displayed.

Returns
  • true if the item is open

public String getText ()

Gets this object's text.

Returns
  • the object's text

public final Tree getTree ()

Gets the tree that contains this item.

Returns
  • the containing tree

public Object getUserObject ()

Gets the user-defined object associated with this item.

Returns
  • the item's user-defined object

public Widget getWidget ()

Gets the Widget associated with this tree item.

Returns
  • the widget

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 TreeItem insertItem (int beforeIndex, SafeHtml itemHtml)

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

Parameters
beforeIndex the index where the item will be inserted
itemHtml the item's HTML
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 void insertItem (int beforeIndex, TreeItem item)

Inserts an item as a child to this one.

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 boolean isSelected ()

Determines whether this item is currently selected.

Returns
  • true if it is selected

public void remove ()

Removes this item from its tree.

public void removeItem (IsTreeItem isItem)

Removes one of this item's children.

Parameters
isItem the wrapper of item to be removed

public void removeItem (TreeItem item)

Removes one of this item's children.

Parameters
item the item to be removed

public void removeItems ()

Removes all of this item's children.

public void setHTML (SafeHtml html)

Sets this object's contents via known-safe HTML.

The object will behave exactly the same as when a widget's setHTML(String) method is invoked; however the SafeHtml passed to this method observes the contract that it can be used in an HTML context without causing unsafe script execution. Thus, unlike setHTML(String), using this method cannot result in Cross-Site Scripting security vulnerabilities.

Parameters
html the object's new HTML, represented as a SafeHtml object

public void setHTML (String html)

Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setText(String) whenever possible.

Parameters
html the object's new HTML

public void setSelected (boolean selected)

Selects or deselects this item.

Parameters
selected true to select the item, false to deselect it

public void setState (boolean open, boolean fireEvents)

Sets whether this item's children are displayed.

Parameters
open whether the item is open
fireEvents true to allow open/close events to be

public void setState (boolean open)

Sets whether this item's children are displayed.

Parameters
open whether the item is open

public void setText (String text)

Sets this object's text.

Parameters
text the object's new text

public void setUserObject (Object userObj)

Sets the user-defined object associated with this item.

Parameters
userObj the item's user-defined object

public void setWidget (Widget newWidget)

Sets the current widget. Any existing child widget will be removed.

Parameters
newWidget Widget to set

Protected Methods

protected Focusable getFocusable ()

Returns a suggested Focusable instance to use when this tree item is selected. The tree maintains focus if this method returns null. By default, if the tree item contains a focusable widget, that widget is returned. Note, the Tree will ignore this value if the user clicked on an input element such as a button or text area when selecting this item.

Returns
  • the focusable item

protected HasFocus getFocusableWidget ()

This method is deprecated.
use getFocusable() instead

Returns the widget, if any, that should be focused on if this TreeItem is selected.

Returns
  • widget to be focused.

protected void onEnsureDebugId (String baseID)

Affected Elements:

  • -content = The text or Widget next to the image.
  • -child# = The child at the specified index.

Parameters
baseID the base ID used by the main element