Package com.google.gwt.user.client.ui
Class TreeItem
java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.TreeItem
- All Implemented Interfaces:
HasSafeHtml,HasHTML,HasText,HasTreeItems,HasVisibility,IsTreeItem
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
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);
}
}
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasTreeItems
HasTreeItems.ForIsWidget -
Field Summary
FieldsFields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a child tree item containing the specified html.voidaddItem(IsTreeItem isItem) Adds another item as a child to this one.voidAdds another item as a child to this one.Adds a child tree item containing the specified widget.addTextItem(String itemText) Adds a child tree item containing the specified text.(package private) voidaddTreeItems(List<TreeItem> accum) Returns theTreeItemaspect of the receiver.getChild(int index) Gets the child at the specified index.intGets the number of children contained in this item.intgetChildIndex(TreeItem child) Gets the index of the specified child item.(package private) Elementprotected FocusableReturns a suggestedFocusableinstance to use when this tree item is selected.protected HasFocusDeprecated.getHTML()Gets this object's contents as HTML.(package private) Element(package private) ElementGets this item's parent.booleangetState()Gets whether this item's children are displayed.getText()Gets this object's text.getTitle()Gets the title associated with this object.final TreegetTree()Gets the tree that contains this item.Gets the user-defined object associated with this item.Gets theWidgetassociated with this tree item.(package private) voidinsertItem(int beforeIndex, SafeHtml itemHtml) Inserts a child tree item at the specified index containing the specified html.voidinsertItem(int beforeIndex, TreeItem item) Inserts an item as a child to this one.insertItem(int beforeIndex, Widget widget) Inserts a child tree item at the specified index containing the specified widget.insertTextItem(int beforeIndex, String itemText) Inserts a child tree item at the specified index containing the specified text.(package private) booleanbooleanDetermines whether this item is currently selected.(package private) voidRemove a tree item from its parent if it has one.protected voidonEnsureDebugId(String baseID) Affected Elements: -content = The text orWidgetnext to the image. -child# = The child at the specified index.voidremove()Removes this item from its tree.voidremoveItem(IsTreeItem isItem) Removes one of this item's children.voidremoveItem(TreeItem item) Removes one of this item's children.voidRemoves all of this item's children.voidSets this object's contents via known-safe HTML.voidSets this object's contents via HTML.(package private) voidsetParentItem(TreeItem parent) voidsetSelected(boolean selected) Selects or deselects this item.voidsetState(boolean open) Sets whether this item's children are displayed.voidsetState(boolean open, boolean fireEvents) Sets whether this item's children are displayed.voidSets this object's text.voidSets the title associated with this object.(package private) voidvoidsetUserObject(Object userObj) Sets the user-defined object associated with this item.voidSets the current widget.(package private) voidupdateState(boolean animate, boolean updateTreeSelection) (package private) voidMethods 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, 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
-
Field Details
-
IMAGE_PAD
static final int IMAGE_PAD- See Also:
-
-
Constructor Details
-
TreeItem
public TreeItem()Creates an empty tree item. -
TreeItem
Constructs a tree item with the givenWidget.- Parameters:
widget- the item's widget
-
TreeItem
TreeItem(boolean isRoot) Creates an empty tree item.- Parameters:
isRoot- true if this item is the root of a tree
-
-
Method Details
-
addItem
Adds another item as a child to this one.- Specified by:
addItemin interfaceHasTreeItems- Parameters:
item- the item to be added
-
addItem
Adds another item as a child to this one.- Specified by:
addItemin interfaceHasTreeItems- Parameters:
isItem- the wrapper of item to be added
-
addItem
Adds a child tree item containing the specified widget.- Specified by:
addItemin interfaceHasTreeItems- Parameters:
widget- the widget to be added- Returns:
- the item that was added
-
addTextItem
Adds a child tree item containing the specified text.- Specified by:
addTextItemin interfaceHasTreeItems- Parameters:
itemText- the text of the item to be added- Returns:
- the item that was added
-
asTreeItem
Description copied from interface:IsTreeItemReturns theTreeItemaspect of the receiver.- Specified by:
asTreeItemin interfaceIsTreeItem
-
getChild
Gets the child at the specified index.- Parameters:
index- the index to be retrieved- Returns:
- the item at that index
-
getChildCount
public int getChildCount()Gets the number of children contained in this item.- Returns:
- this item's child count.
-
getChildIndex
Gets the index of the specified child item.- Parameters:
child- the child item to be found- Returns:
- the child's index, or
-1if none is found
-
getHTML
Description copied from interface:HasHTMLGets this object's contents as HTML. -
getParentItem
Gets this item's parent.- Returns:
- the parent item
-
getState
public boolean getState()Gets whether this item's children are displayed.- Returns:
trueif the item is open
-
getText
Description copied from interface:HasTextGets this object's text. -
getTree
Gets the tree that contains this item.- Returns:
- the containing tree
-
getUserObject
Gets the user-defined object associated with this item.- Returns:
- the item's user-defined object
-
getWidget
Gets theWidgetassociated with this tree item.- Returns:
- the widget
-
getTitle
Description copied from class:UIObjectGets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object. -
setTitle
Description copied from class:UIObjectSets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object. -
insertItem
Inserts an item as a child to this one.- Parameters:
beforeIndex- the index where the item will be inserteditem- the item to be added- Throws:
IndexOutOfBoundsException- if the index is out of range
-
insertItem
Inserts a child tree item at the specified index containing the specified widget.- Parameters:
beforeIndex- the index where the item will be insertedwidget- the widget to be added- Returns:
- the item that was added
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
insertTextItem
Inserts a child tree item at the specified index containing the specified text.- Parameters:
beforeIndex- the index where the item will be inserteditemText- the item's text- Returns:
- the item that was added
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
isSelected
public boolean isSelected()Determines whether this item is currently selected.- Returns:
trueif it is selected
-
remove
public void remove()Removes this item from its tree. -
removeItem
Removes one of this item's children.- Specified by:
removeItemin interfaceHasTreeItems- Parameters:
item- the item to be removed
-
removeItem
Removes one of this item's children.- Specified by:
removeItemin interfaceHasTreeItems- Parameters:
isItem- the wrapper of item to be removed
-
removeItems
public void removeItems()Removes all of this item's children.- Specified by:
removeItemsin interfaceHasTreeItems
-
setHTML
Description copied from interface:HasHTMLSets 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 usingHasText.setText(String)whenever possible. -
setSelected
public void setSelected(boolean selected) Selects or deselects this item.- Parameters:
selected-trueto select the item,falseto deselect it
-
setState
public void setState(boolean open) Sets whether this item's children are displayed.- Parameters:
open- whether the item is open
-
setState
public void setState(boolean open, boolean fireEvents) Sets whether this item's children are displayed.- Parameters:
open- whether the item is openfireEvents-trueto allow open/close events to be
-
setText
Description copied from interface:HasTextSets this object's text. -
setUserObject
Sets the user-defined object associated with this item.- Parameters:
userObj- the item's user-defined object
-
setWidget
Sets the current widget. Any existing child widget will be removed.- Parameters:
newWidget- Widget to set
-
getFocusable
Returns a suggestedFocusableinstance 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, theTreewill 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
-
getFocusableWidget
Deprecated.usegetFocusable()insteadReturns the widget, if any, that should be focused on if this TreeItem is selected.- Returns:
- widget to be focused.
-
onEnsureDebugId
Affected Elements:- -content = The text or
Widgetnext to the image. - -child# = The child at the specified index.
- Overrides:
onEnsureDebugIdin classUIObject- Parameters:
baseID- the base ID used by the main element- See Also:
- -content = The text or
-
addTreeItems
-
getChildren
-
getContentElem
Element getContentElem() -
getImageElement
Element getImageElement() -
getImageHolderElement
Element getImageHolderElement() -
initChildren
void initChildren() -
isFullNode
boolean isFullNode() -
maybeRemoveItemFromParent
Remove a tree item from its parent if it has one.- Parameters:
item- the tree item to remove from its parent
-
setParentItem
-
setTree
-
updateState
void updateState(boolean animate, boolean updateTreeSelection) -
updateStateRecursive
void updateStateRecursive()
getFocusable()instead