public class Tree extends Widget implements HasTreeItems.ForIsWidget, HasWidgets.ForIsWidget, SourcesTreeEvents, HasFocus, HasAnimation, HasAllKeyHandlers, HasAllFocusHandlers, HasSelectionHandlers<TreeItem>, HasOpenHandlers<TreeItem>, HasCloseHandlers<TreeItem>, SourcesMouseEvents, HasAllMouseHandlers
TreeItems that the user can
open, close, and select.
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 |
|---|---|
(package private) static class |
Tree.ImageAdapter
There are several ways of configuring images for the Tree widget due to
deprecated APIs.
|
static interface |
Tree.Resources
A ClientBundle that provides images for this widget.
|
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledHasTreeItems.ForIsWidgetHasWidgets.ForIsWidgeteventsToSinkDEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR| Constructor and Description |
|---|
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)
Deprecated.
replaced by
Tree(Resources) |
Tree(TreeImages images,
boolean useLeafImages)
Deprecated.
replaced by
Tree(Resources, boolean) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(IsWidget w)
Overloaded version for IsWidget.
|
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)
Adds a
CloseEvent handler. |
HandlerRegistration |
addFocusHandler(FocusHandler handler)
Adds a
FocusEvent handler. |
void |
addFocusListener(FocusListener listener)
Deprecated.
|
void |
addItem(IsTreeItem isItem)
Adds an item to the root level of this tree.
|
TreeItem |
addItem(IsWidget w)
Overloaded version for IsWidget.
|
TreeItem |
addItem(SafeHtml itemHtml)
Adds a simple tree item containing the specified html.
|
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)
|
HandlerRegistration |
addKeyDownHandler(KeyDownHandler handler)
Adds a
KeyDownEvent handler. |
HandlerRegistration |
addKeyPressHandler(KeyPressHandler handler)
Adds a
KeyPressEvent handler. |
HandlerRegistration |
addKeyUpHandler(KeyUpHandler handler)
Adds a
KeyUpEvent handler. |
HandlerRegistration |
addMouseDownHandler(MouseDownHandler handler)
Adds a
MouseDownEvent handler. |
void |
addMouseListener(MouseListener listener)
Deprecated.
Use
addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler) addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler),
addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler), addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) and
addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) instead |
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. |
HandlerRegistration |
addOpenHandler(OpenHandler<TreeItem> handler)
Adds an
OpenEvent handler. |
HandlerRegistration |
addSelectionHandler(SelectionHandler<TreeItem> handler)
Adds a
SelectionEvent handler. |
TreeItem |
addTextItem(java.lang.String itemText)
Adds a simple tree item containing the specified text.
|
void |
addTreeListener(TreeListener listener)
Deprecated.
Use
addSelectionHandler(com.google.gwt.event.logical.shared.SelectionHandler<com.google.gwt.user.client.ui.TreeItem>), addOpenHandler(com.google.gwt.event.logical.shared.OpenHandler<com.google.gwt.user.client.ui.TreeItem>), and
addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.ui.TreeItem>) instead |
(package private) void |
adopt(Widget widget,
TreeItem treeItem) |
void |
clear()
Clears all tree items from the current tree.
|
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
Widget.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
Widget.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.
|
(package private) void |
fireStateChanged(TreeItem item,
boolean open) |
(package private) java.util.Map<Widget,TreeItem> |
getChildWidgets() |
(package private) Tree.ImageAdapter |
getImages() |
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,
SafeHtml itemHtml)
Inserts a child tree item at the specified index containing the specified
html.
|
void |
insertItem(int beforeIndex,
TreeItem item)
Inserts an item into the root level of this tree.
|
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.
|
boolean |
isAnimationEnabled()
Returns true if animations are enabled, false if not.
|
protected boolean |
isKeyboardNavigationEnabled(TreeItem currentItem)
Indicates if keyboard navigation is enabled for the Tree and for a given
TreeItem.
|
boolean |
isScrollOnSelectEnabled()
Determines whether selecting a tree item will scroll it into view.
|
java.util.Iterator<Widget> |
iterator()
Gets an iterator for the contained widgets.
|
(package private) void |
maybeUpdateSelection(TreeItem itemThatChangedState,
boolean isItemOpening) |
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.
|
(package private) void |
orphan(Widget widget) |
boolean |
remove(IsWidget w)
Overloaded version for IsWidget.
|
boolean |
remove(Widget w)
Removes a child widget.
|
void |
removeFocusListener(FocusListener listener)
Deprecated.
Use the
HandlerRegistration.removeHandler() method on the
object returned by addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) instead |
void |
removeItem(IsTreeItem isItem)
Removes an item from the root level of this tree.
|
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)
Deprecated.
Use the
HandlerRegistration.removeHandler() method on the
object returned by an add*Handler method instead |
void |
removeMouseListener(MouseListener listener)
Deprecated.
Use the
HandlerRegistration.removeHandler() method on the
object returned by an add*Handler method instead |
void |
removeTreeListener(TreeListener listener)
Deprecated.
Use the
HandlerRegistration.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 |
setScrollOnSelectEnabled(boolean enable)
Enable or disable scrolling a tree item into view when it is selected.
|
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.
|
(package private) static boolean |
shouldTreeDelegateFocusToElement(Element elem) |
(package private) void |
showClosedImage(TreeItem treeItem)
Called only from
TreeItem: Shows the closed image on that tree
item. |
(package private) void |
showLeafImage(TreeItem treeItem)
Called only from
TreeItem: Shows the leaf image on a tree item. |
(package private) void |
showOpenImage(TreeItem treeItem)
Called only from
TreeItem: Shows the open image on a tree item. |
java.util.Iterator<TreeItem> |
treeItemIterator()
Iterator of tree items.
|
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onDetach, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEventsaddStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitfireEventpublic Tree()
public Tree(Tree.Resources resources)
resources - a bundle that provides tree specific imagespublic Tree(Tree.Resources resources, boolean useLeafImages)
resources - a bundle that provides tree specific imagesuseLeafImages - use leaf images from bundle@Deprecated public Tree(TreeImages images)
Tree(Resources)images - a bundle that provides tree specific images@Deprecated public Tree(TreeImages images, boolean useLeafImages)
Tree(Resources, boolean)images - a bundle that provides tree specific imagesuseLeafImages - use leaf images from bundlestatic boolean shouldTreeDelegateFocusToElement(Element elem)
public void add(Widget widget)
add in interface HasWidgetswidget - widget to add.HasWidgets.add(com.google.gwt.user.client.ui.Widget)public void add(IsWidget w)
add in interface HasWidgets.ForIsWidgetadd(Widget)public HandlerRegistration addBlurHandler(BlurHandler handler)
HasBlurHandlersBlurEvent handler.addBlurHandler in interface HasBlurHandlershandler - the blur handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addCloseHandler(CloseHandler<TreeItem> handler)
HasCloseHandlersCloseEvent handler.addCloseHandler in interface HasCloseHandlers<TreeItem>handler - the handlerpublic HandlerRegistration addFocusHandler(FocusHandler handler)
HasFocusHandlersFocusEvent handler.addFocusHandler in interface HasFocusHandlershandler - the focus handlerHandlerRegistration used to remove this handler@Deprecated public void addFocusListener(FocusListener listener)
addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) insteadSourcesFocusEventsaddFocusListener in interface SourcesFocusEventslistener - the listener interface to addpublic TreeItem addItem(SafeHtml itemHtml)
addItem in interface HasTreeItemsitemHtml - the html of the item to be addedpublic void addItem(TreeItem item)
addItem in interface HasTreeItemsitem - the item to be addedpublic void addItem(IsTreeItem isItem)
addItem in interface HasTreeItemsisItem - the wrapper of item to be addedpublic TreeItem addItem(Widget widget)
addItem in interface HasTreeItemswidget - the widget to be addedpublic TreeItem addItem(IsWidget w)
addItem in interface HasTreeItems.ForIsWidgetaddItem(Widget)@Deprecated public void addKeyboardListener(KeyboardListener listener)
addKeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler), addKeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) and
addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) insteadSourcesKeyboardEventsaddKeyboardListener in interface SourcesKeyboardEventslistener - the listener interface to addpublic HandlerRegistration addKeyDownHandler(KeyDownHandler handler)
HasKeyDownHandlersKeyDownEvent handler.addKeyDownHandler in interface HasKeyDownHandlershandler - the key down handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addKeyPressHandler(KeyPressHandler handler)
HasKeyPressHandlersKeyPressEvent handler.addKeyPressHandler in interface HasKeyPressHandlershandler - the key press handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addKeyUpHandler(KeyUpHandler handler)
HasKeyUpHandlersKeyUpEvent handler.addKeyUpHandler in interface HasKeyUpHandlershandler - the key up handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addMouseDownHandler(MouseDownHandler handler)
HasMouseDownHandlersMouseDownEvent handler.addMouseDownHandler in interface HasMouseDownHandlershandler - the mouse down handlerHandlerRegistration used to remove this handler@Deprecated public void addMouseListener(MouseListener listener)
addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler) addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler),
addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler), addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) and
addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) insteadSourcesMouseEventsaddMouseListener in interface SourcesMouseEventslistener - the listener interface to addpublic HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)
HasMouseMoveHandlersMouseMoveEvent handler.addMouseMoveHandler in interface HasMouseMoveHandlershandler - the mouse move handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addMouseOutHandler(MouseOutHandler handler)
HasMouseOutHandlersMouseOutEvent handler.addMouseOutHandler in interface HasMouseOutHandlershandler - the mouse out handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addMouseOverHandler(MouseOverHandler handler)
HasMouseOverHandlersMouseOverEvent handler.addMouseOverHandler in interface HasMouseOverHandlershandler - the mouse over handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addMouseUpHandler(MouseUpHandler handler)
HasMouseUpHandlersMouseUpEvent handler.addMouseUpHandler in interface HasMouseUpHandlershandler - the mouse up handlerHandlerRegistration used to remove this handlerpublic HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)
HasMouseWheelHandlersMouseWheelEvent handler.addMouseWheelHandler in interface HasMouseWheelHandlershandler - the mouse wheel handlerHandlerRegistration used to remove this handlerpublic final HandlerRegistration addOpenHandler(OpenHandler<TreeItem> handler)
HasOpenHandlersOpenEvent handler.addOpenHandler in interface HasOpenHandlers<TreeItem>handler - the handlerpublic HandlerRegistration addSelectionHandler(SelectionHandler<TreeItem> handler)
HasSelectionHandlersSelectionEvent handler.addSelectionHandler in interface HasSelectionHandlers<TreeItem>handler - the handlerpublic TreeItem addTextItem(java.lang.String itemText)
addTextItem in interface HasTreeItemsitemText - the text of the item to be added@Deprecated public void addTreeListener(TreeListener listener)
addSelectionHandler(com.google.gwt.event.logical.shared.SelectionHandler<com.google.gwt.user.client.ui.TreeItem>), addOpenHandler(com.google.gwt.event.logical.shared.OpenHandler<com.google.gwt.user.client.ui.TreeItem>), and
addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.ui.TreeItem>) insteadSourcesTreeEventsaddTreeListener in interface SourcesTreeEventslistener - the listener interface to addpublic void clear()
clear in interface HasWidgetspublic void ensureSelectedItemVisible()
public TreeItem getItem(int index)
index - the index to be retrievedpublic int getItemCount()
public TreeItem getSelectedItem()
public int getTabIndex()
FocusablegetTabIndex in interface Focusablepublic TreeItem insertItem(int beforeIndex, SafeHtml itemHtml)
beforeIndex - the index where the item will be inserteditemHtml - the html of the item to be addedjava.lang.IndexOutOfBoundsException - if the index is out of rangepublic void insertItem(int beforeIndex,
TreeItem item)
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)
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 text of the item to be addedjava.lang.IndexOutOfBoundsException - if the index is out of rangepublic boolean isAnimationEnabled()
HasAnimationisAnimationEnabled in interface HasAnimationpublic boolean isScrollOnSelectEnabled()
public java.util.Iterator<Widget> iterator()
HasWidgetsIterator.remove().iterator in interface HasWidgetsiterator in interface java.lang.Iterable<Widget>public void onBrowserEvent(Event event)
EventListeneronBrowserEvent in interface EventListeneronBrowserEvent in class Widgetevent - the event receivedpublic boolean remove(Widget w)
HasWidgetsremove in interface HasWidgetsw - the widget to be removedtrue if the widget was presentpublic boolean remove(IsWidget w)
remove in interface HasWidgets.ForIsWidgetremove(Widget)@Deprecated public void removeFocusListener(FocusListener listener)
HandlerRegistration.removeHandler() method on the
object returned by addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) insteadSourcesFocusEventsremoveFocusListener in interface SourcesFocusEventslistener - the listener interface to removepublic void removeItem(TreeItem item)
removeItem in interface HasTreeItemsitem - the item to be removedpublic void removeItem(IsTreeItem isItem)
removeItem in interface HasTreeItemsisItem - the wrapper of item to be removedpublic void removeItems()
removeItems in interface HasTreeItems@Deprecated public void removeKeyboardListener(KeyboardListener listener)
HandlerRegistration.removeHandler() method on the
object returned by an add*Handler method insteadSourcesKeyboardEventsremoveKeyboardListener in interface SourcesKeyboardEventslistener - the listener interface to remove@Deprecated public void removeMouseListener(MouseListener listener)
HandlerRegistration.removeHandler() method on the
object returned by an add*Handler method insteadSourcesMouseEventsremoveMouseListener in interface SourcesMouseEventslistener - the listener interface to remove@Deprecated public void removeTreeListener(TreeListener listener)
HandlerRegistration.removeHandler() method on the
object returned by an add*Handler method insteadSourcesTreeEventsremoveTreeListener in interface SourcesTreeEventslistener - the listener interface to removepublic void setAccessKey(char key)
FocusablesetAccessKey in interface Focusablekey - the widget's access keypublic void setAnimationEnabled(boolean enable)
HasAnimationsetAnimationEnabled in interface HasAnimationenable - true to enable, false to disablepublic void setFocus(boolean focus)
FocusableGWTTestCase#delayTestFinish for more information on how to do this.public void setScrollOnSelectEnabled(boolean enable)
public void setSelectedItem(TreeItem item)
item - the item to be selected, or null to deselect all
itemspublic void setSelectedItem(TreeItem item, boolean fireEvents)
item - the item to be selected, or null to deselect all
itemsfireEvents - true to allow selection events to be firedpublic void setTabIndex(int index)
Focusable-1 will cause this widget to
be removed from the tab order.setTabIndex in interface Focusableindex - the widget's tab indexpublic java.util.Iterator<TreeItem> treeItemIterator()
protected void doAttachChildren()
WidgetWidget.onAttach() for each of its
child widgets.doAttachChildren in class WidgetWidget.onAttach()protected void doDetachChildren()
WidgetWidget.onDetach() for each of its
child widgets.doDetachChildren in class WidgetWidget.onDetach()protected boolean isKeyboardNavigationEnabled(TreeItem currentItem)
currentItem - the currently selected TreeItemtrue if the Tree will response to arrow keys by
changing the currently selected itemprotected void onEnsureDebugId(java.lang.String baseID)
TreeItem.onEnsureDebugId in class UIObjectbaseID - the base ID used by the main elementUIObject.onEnsureDebugId(String)protected void onLoad()
Widgetvoid fireStateChanged(TreeItem item, boolean open)
Tree.ImageAdapter getImages()
void maybeUpdateSelection(TreeItem itemThatChangedState, boolean isItemOpening)
void orphan(Widget widget)
void showClosedImage(TreeItem treeItem)
TreeItem: Shows the closed image on that tree
item.treeItem - the tree itemvoid showLeafImage(TreeItem treeItem)
TreeItem: Shows the leaf image on a tree item.treeItem - the tree item