Class Tree

public class Tree
extends Widget
implements SourcesTreeEvents
A standard hierarchical tree widget. The tree contains a hierarchy of TreeItems that the user can open, close, and select.

CSS Style Rules

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");

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

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

Constructors

Tree()Constructs an empty tree.

Methods

addFocusListener(FocusListener)
addItem(String)Adds a simple tree item containing the specified text.
addItem(TreeItem)Adds an item to the root level of this tree.
addKeyboardListener(KeyboardListener)
addMouseListener(MouseListener)
addTreeListener(TreeListener)Adds a listener interface to receive tree events.
ensureSelectedItemVisible()Ensures that the currently-selected item is visible, opening its parents and scrolling the tree as necessary.
getImageBase()Gets this tree's default image package.
getItem(int)Gets the top-level tree item at the specified index.
getItemCount()Gets the number of items contained at the root of this tree.
getSelectedItem()Gets the currently selected item.
getTabIndex()
moveSelectionDown(TreeItem, boolean)
moveSelectionUp(TreeItem, boolean)
onBrowserEvent(Event)
onLoad()This method is called when the widget becomes attached to the browser's document.
removeFocusListener(FocusListener)
removeItem(TreeItem)Removes an item from the root level of this tree.
removeItems()Removes all items from the root level of this tree.
removeKeyboardListener(KeyboardListener)
removeTreeListener(TreeListener)Removes a previously added listener interface.
setAccessKey(char)
setFocus(boolean)
setImageBase(String)Sets the base URL under which this tree will find its default images.
setSelectedItem(TreeItem)Selects a specified item.
setSelectedItem(TreeItem, boolean)Selects a specified item.
setTabIndex(int)

Constructor Detail

Tree

public Tree()
Constructs an empty tree.

Method Detail

addFocusListener

public void addFocusListener(FocusListener listener)

Parameters

listener

addItem

public TreeItem addItem(String itemText)
Adds a simple tree item containing the specified text.

Parameters

itemText
the text of the item to be added

Return Value

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

addKeyboardListener

public void addKeyboardListener(KeyboardListener listener)

Parameters

listener

addMouseListener

public void addMouseListener(MouseListener listener)

Parameters

listener

addTreeListener

public void addTreeListener(TreeListener listener)
Adds a listener interface to receive tree events.

Parameters

listener
the listener interface to add

ensureSelectedItemVisible

public void ensureSelectedItemVisible()
Ensures that the currently-selected item is visible, opening its parents and scrolling the tree as necessary.

getImageBase

public String getImageBase()
Gets this tree's default image package.

Return Value

the tree's image package

See Also

setImageBase

getItem

public TreeItem getItem(int index)
Gets the top-level tree item at the specified index.

Parameters

index
the index to be retrieved

Return Value

the item at that index

getItemCount

public int getItemCount()
Gets the number of items contained at the root of this tree.

Return Value

this tree's item count

getSelectedItem

public TreeItem getSelectedItem()
Gets the currently selected item.

Return Value

the selected item

getTabIndex

public int getTabIndex()

moveSelectionDown

public void moveSelectionDown(TreeItem sel, boolean dig)

Parameters

sel
dig

moveSelectionUp

public void moveSelectionUp(TreeItem sel, boolean climb)

Parameters

sel
climb

onBrowserEvent

public void onBrowserEvent(Event event)

Parameters

event

onLoad

protected void onLoad()
This method is called when the widget becomes attached to the browser's document.

removeFocusListener

public void removeFocusListener(FocusListener listener)

Parameters

listener

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)

Parameters

listener

removeTreeListener

public void removeTreeListener(TreeListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

setAccessKey

public void setAccessKey(char key)

Parameters

key

setFocus

public void setFocus(boolean focus)

Parameters

focus

setImageBase

public void setImageBase(String baseUrl)
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 unselect all items

setSelectedItem

public void setSelectedItem(TreeItem item, boolean fireEvents)
Selects a specified item.

Parameters

item
the item to be selected, or null to unselect all items
fireEvents
true to allow selection events to be fired

setTabIndex

public void setTabIndex(int index)

Parameters

index