public class TreeItem extends UIObject implements IsTreeItem, HasTreeItems, HasHTML, HasSafeHtml
Tree
.
Each tree item is assigned a unique DOM id in order to support ARIA. See
Accessibility
for more information.
public class TreeExample implements EntryPoint { @Override public void onModuleLoad() { // Create a tree with a few items in it. TreeItem root = new TreeItem(); root.setText("root"); root.addTextItem("item0"); root.addTextItem("item1"); root.addTextItem("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); } }
Modifier and Type | Class and Description |
---|---|
static class |
TreeItem.TreeItemImpl
Implementation class for
TreeItem . |
static class |
TreeItem.TreeItemImplIE8ToIE10
IE specific implementation class for
TreeItem . |
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
HasTreeItems.ForIsWidget
Modifier and Type | Field and Description |
---|---|
(package private) static int |
IMAGE_PAD |
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
Constructor and Description |
---|
TreeItem()
Creates an empty tree item.
|
TreeItem(boolean isRoot)
Creates an empty tree item.
|
TreeItem(SafeHtml html)
Constructs a tree item with the given HTML.
|
TreeItem(Widget widget)
Constructs a tree item with the given
Widget . |
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
TreeItem |
addTextItem(java.lang.String itemText)
Adds a child tree item containing the specified text.
|
(package private) void |
addTreeItems(java.util.List<TreeItem> accum) |
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.
|
(package private) java.util.ArrayList<TreeItem> |
getChildren() |
(package private) Element |
getContentElem() |
protected Focusable |
getFocusable()
Returns a suggested
Focusable instance to use when this tree item
is selected. |
protected HasFocus |
getFocusableWidget()
Deprecated.
use
getFocusable() instead |
java.lang.String |
getHTML()
Gets this object's contents as HTML.
|
(package private) Element |
getImageElement() |
(package private) Element |
getImageHolderElement() |
TreeItem |
getParentItem()
Gets this item's parent.
|
boolean |
getState()
Gets whether this item's children are displayed.
|
java.lang.String |
getText()
Gets this object's text.
|
java.lang.String |
getTitle()
Gets the title associated with this object.
|
Tree |
getTree()
Gets the tree that contains this item.
|
java.lang.Object |
getUserObject()
Gets the user-defined object associated with this item.
|
Widget |
getWidget()
Gets the
Widget associated with this tree item. |
(package private) void |
initChildren() |
TreeItem |
insertItem(int beforeIndex,
SafeHtml itemHtml)
Inserts a child tree item at the specified index containing the specified
html.
|
void |
insertItem(int beforeIndex,
TreeItem item)
Inserts an item as a child to this one.
|
TreeItem |
insertItem(int beforeIndex,
Widget widget)
Inserts a child tree item at the specified index containing the specified
widget.
|
TreeItem |
insertTextItem(int beforeIndex,
java.lang.String itemText)
Inserts a child tree item at the specified index containing the specified
text.
|
(package private) boolean |
isFullNode() |
boolean |
isSelected()
Determines whether this item is currently selected.
|
(package private) void |
maybeRemoveItemFromParent(TreeItem item)
Remove a tree item from its parent if it has one.
|
protected void |
onEnsureDebugId(java.lang.String baseID)
Affected Elements:
-content = The text or
Widget next to the image.
-child# = The child at the specified index.
|
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(java.lang.String html)
Sets this object's contents via HTML.
|
(package private) void |
setParentItem(TreeItem parent) |
void |
setSelected(boolean selected)
Selects or deselects this item.
|
void |
setState(boolean open)
Sets whether this item's children are displayed.
|
void |
setState(boolean open,
boolean fireEvents)
Sets whether this item's children are displayed.
|
void |
setText(java.lang.String text)
Sets this object's text.
|
void |
setTitle(java.lang.String title)
Sets the title associated with this object.
|
(package private) void |
setTree(Tree newTree) |
void |
setUserObject(java.lang.Object userObj)
Sets the user-defined object associated with this item.
|
void |
setWidget(Widget newWidget)
Sets the current widget.
|
(package private) void |
updateState(boolean animate,
boolean updateTreeSelection) |
(package private) void |
updateStateRecursive() |
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, isVisible, isVisible, removeStyleDependentName, removeStyleName, replaceElement, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setVisible, setVisible, setWidth, sinkBitlessEvent, sinkEvents, toString, unsinkEvents
static final int IMAGE_PAD
public TreeItem()
public TreeItem(SafeHtml html)
html
- the item's HTMLpublic TreeItem(Widget widget)
Widget
.widget
- the item's widgetTreeItem(boolean isRoot)
isRoot
- true if this item is the root of a treepublic TreeItem addItem(SafeHtml itemHtml)
addItem
in interface HasTreeItems
itemHtml
- the item's HTMLpublic void addItem(TreeItem item)
addItem
in interface HasTreeItems
item
- the item to be addedpublic void addItem(IsTreeItem isItem)
addItem
in interface HasTreeItems
isItem
- the wrapper of item to be addedpublic TreeItem addItem(Widget widget)
addItem
in interface HasTreeItems
widget
- the widget to be addedpublic TreeItem addTextItem(java.lang.String itemText)
addTextItem
in interface HasTreeItems
itemText
- the text of the item to be addedpublic TreeItem asTreeItem()
IsTreeItem
TreeItem
aspect of the receiver.asTreeItem
in interface IsTreeItem
public TreeItem getChild(int index)
index
- the index to be retrievedpublic int getChildCount()
public int getChildIndex(TreeItem child)
child
- the child item to be found-1
if none is foundpublic java.lang.String getHTML()
HasHTML
public TreeItem getParentItem()
public boolean getState()
true
if the item is openpublic java.lang.String getText()
HasText
public final Tree getTree()
public java.lang.Object getUserObject()
public Widget getWidget()
Widget
associated with this tree item.public java.lang.String getTitle()
UIObject
public void setTitle(java.lang.String title)
UIObject
public TreeItem insertItem(int beforeIndex, SafeHtml itemHtml) throws java.lang.IndexOutOfBoundsException
beforeIndex
- the index where the item will be inserteditemHtml
- the item's HTMLjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic void insertItem(int beforeIndex, TreeItem item) throws java.lang.IndexOutOfBoundsException
beforeIndex
- the index where the item will be inserteditem
- the item to be addedjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic TreeItem insertItem(int beforeIndex, Widget widget) throws java.lang.IndexOutOfBoundsException
beforeIndex
- the index where the item will be insertedwidget
- the widget to be addedjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic TreeItem insertTextItem(int beforeIndex, java.lang.String itemText)
beforeIndex
- the index where the item will be inserteditemText
- the item's textjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic boolean isSelected()
true
if it is selectedpublic void remove()
public void removeItem(TreeItem item)
removeItem
in interface HasTreeItems
item
- the item to be removedpublic void removeItem(IsTreeItem isItem)
removeItem
in interface HasTreeItems
isItem
- the wrapper of item to be removedpublic void removeItems()
removeItems
in interface HasTreeItems
public void setHTML(java.lang.String html)
HasHTML
HasText.setText(String)
whenever possible.public void setHTML(SafeHtml html)
HasSafeHtml
The object will behave exactly the same as when a widget's
HasHTML.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
HasHTML.setHTML(String)
, using this
method cannot result in Cross-Site Scripting security vulnerabilities.
setHTML
in interface HasSafeHtml
html
- the object's new HTML, represented as a SafeHtml
objectpublic void setSelected(boolean selected)
selected
- true
to select the item, false
to
deselect itpublic void setState(boolean open)
open
- whether the item is openpublic void setState(boolean open, boolean fireEvents)
open
- whether the item is openfireEvents
- true
to allow open/close events to bepublic void setText(java.lang.String text)
HasText
public void setUserObject(java.lang.Object userObj)
userObj
- the item's user-defined objectpublic void setWidget(Widget newWidget)
newWidget
- Widget to setprotected Focusable getFocusable()
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.@Deprecated protected HasFocus getFocusableWidget()
getFocusable()
insteadprotected void onEnsureDebugId(java.lang.String baseID)
Widget
next to the image.onEnsureDebugId
in class UIObject
baseID
- the base ID used by the main elementUIObject.onEnsureDebugId(String)
void addTreeItems(java.util.List<TreeItem> accum)
java.util.ArrayList<TreeItem> getChildren()
Element getContentElem()
Element getImageElement()
Element getImageHolderElement()
void initChildren()
boolean isFullNode()
void maybeRemoveItemFromParent(TreeItem item)
item
- the tree item to remove from its parentvoid setParentItem(TreeItem parent)
void setTree(Tree newTree)
void updateState(boolean animate, boolean updateTreeSelection)
void updateStateRecursive()