com.sencha.gxt.widget.core.client.tree
Class Tree<M,C>

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.sencha.gxt.widget.core.client.Component
              extended by com.sencha.gxt.widget.core.client.tree.Tree<M,C>
Type Parameters:
M - the model type
C - the cell data type
All Implemented Interfaces:
HasAttachHandlers, HasResizeHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, CheckProvider<M>, BeforeCheckChangeEvent.HasBeforeCheckChangeHandlers<M>, BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers<M>, BeforeExpandItemEvent.HasBeforeExpandItemHandlers<M>, BeforeHideEvent.HasBeforeHideHandlers, BeforeShowContextMenuEvent.HasBeforeShowContextMenuHandler, BeforeShowEvent.HasBeforeShowHandlers, BlurEvent.HasBlurHandlers, CheckChangedEvent.HasCheckChangedHandlers<M>, CheckChangeEvent.HasCheckChangeHandlers<M>, CollapseItemEvent.HasCollapseItemHandlers<M>, DisableEvent.HasDisableHandlers, EnableEvent.HasEnableHandlers, ExpandItemEvent.HasExpandItemHandlers<M>, FocusEvent.HasFocusHandlers, HideEvent.HasHideHandlers, MoveEvent.HasMoveHandlers, ShowContextMenuEvent.HasShowContextMenuHandler, ShowEvent.HasShowHandlers, HasFocusSupport, HasItemId

public class Tree<M,C>
extends Component
implements BeforeExpandItemEvent.HasBeforeExpandItemHandlers<M>, ExpandItemEvent.HasExpandItemHandlers<M>, BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers<M>, CollapseItemEvent.HasCollapseItemHandlers<M>, BeforeCheckChangeEvent.HasBeforeCheckChangeHandlers<M>, CheckChangeEvent.HasCheckChangeHandlers<M>, CheckProvider<M>

A hierarchical tree widget bound directly to a @link TreeStore. Tree contains no child widgets, rather, the tree is rendered based on the models contained in the tree store. Once bound, the tree will remain in sync with the bound tree store.

With state enabled, Tree will save and restore the expand state of the nodes in the tree. A ModelKeyProvider must be specified with the TreeStore this tree is bound to. Save and restore works with both local, and asynchronous loading of children.


Nested Class Summary
static class Tree.CheckCascade
          Check cascade enum.
static class Tree.CheckNodes
          Check nodes enum.
static class Tree.CheckState
           
static class Tree.Joint
          Joint enum.
static interface Tree.TreeAppearance
           
static class Tree.TreeNode<M>
          Maintains the internal state of nodes contained in the tree.
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
Tree(TreeStore<M> store, ValueProvider<? super M,C> valueProvider)
          Creates a new tree panel.
Tree(TreeStore<M> store, ValueProvider<? super M,C> valueProvider, Tree.TreeAppearance appearance)
           
 
Method Summary
 HandlerRegistration addBeforeCheckChangeHandler(BeforeCheckChangeEvent.BeforeCheckChangeHandler<M> handler)
          Adds a BeforeCheckChangeEvent.BeforeCheckChangeHandler handler for BeforeCheckChangeEvent events.
 HandlerRegistration addBeforeCollapseHandler(BeforeCollapseItemEvent.BeforeCollapseItemHandler<M> handler)
          Adds a BeforeCollapseItemEvent.BeforeCollapseItemHandler handler for BeforeCollapseItemEvent events.
 HandlerRegistration addBeforeExpandHandler(BeforeExpandItemEvent.BeforeExpandItemHandler<M> handler)
          Adds a BeforeExpandItemEvent.BeforeExpandItemHandler handler for BeforeExpandItemEvent events.
 HandlerRegistration addCheckChangedHandler(CheckChangedEvent.CheckChangedHandler<M> handler)
          Adds a CheckChangedEvent.CheckChangedHandler handler for CheckChangedEvent events.
 HandlerRegistration addCheckChangeHandler(CheckChangeEvent.CheckChangeHandler<M> handler)
          Adds a CheckChangeEvent.CheckChangeHandler handler for CheckChangeEvent events.
 HandlerRegistration addCollapseHandler(CollapseItemEvent.CollapseItemHandler<M> handler)
          Adds a CollapseItemEvent.CollapseItemHandler handler for CollapseItemEvent events.
 HandlerRegistration addExpandHandler(ExpandItemEvent.ExpandItemHandler<M> handler)
          Adds a ExpandItemEvent.ExpandItemHandler handler for ExpandItemEvent events.
 void collapseAll()
          Collapses all nodes.
 void expandAll()
          Expands all nodes.
 Tree.TreeNode<M> findNode(Element target)
          Returns the tree node for the given target.
 Tree.TreeNode<M> findNode(M model)
          Returns the tree node for the given model.
 Tree.TreeAppearance getAppearance()
          Returns the tree appearance.
 Cell<C> getCell()
          Return the tree's cell.
 Tree.CheckState getChecked(M model)
          Returns the models checked state.
 List<M> getCheckedSelection()
          Returns the current checked selection.
 Tree.CheckNodes getCheckNodes()
          Returns the child nodes value which determines what node types have a check box.
 Tree.CheckCascade getCheckStyle()
          The check cascade style value which determines if check box changes cascade to parent and children.
 IconProvider<M> getIconProvider()
          Returns the model icon provider.
 TreeSelectionModel<M> getSelectionModel()
          Returns the tree's selection model.
 TreeStore<M> getStore()
          Returns the tree's store.
 TreeStyle getStyle()
          Returns the tree style.
 TreeView<M> getView()
          Returns the tree's view.
 boolean isAutoExpand()
          Returns true if auto expand is enabled.
 boolean isAutoLoad()
          Returns true if auto load is enabled.
 boolean isAutoSelect()
          Returns true if select on load is enabled.
 boolean isBufferedRender()
          Returns true if buffered rendering is enabled.
 boolean isCaching()
          Returns true when a loader is queried for it's children each time a node is expanded.
 boolean isCheckable()
          Returns true if check boxes are enabled.
 boolean isChecked(M model)
          Returns true if the model is checked.
 boolean isExpanded(M model)
          Returns true if the model is expanded.
 boolean isExpandOnFilter()
          Returns the if expand all and collapse all is enabled on filter changes.
 boolean isLeaf(M model)
          Returns true if the model is a leaf node.
 boolean isTrackMouseOver()
          Returns true if nodes are highlighted on mouse over.
 void onBrowserEvent(Event event)
           
 void refresh(M model)
           
 void scrollIntoView(M model)
          Scrolls the tree to ensure the given model is visible.
 void setAutoExpand(boolean autoExpand)
          If set to true, all non leaf nodes will be expanded automatically (defaults to false).
 void setAutoLoad(boolean autoLoad)
          Sets whether all children should automatically be loaded recursively (defaults to false).
 void setAutoSelect(boolean autoSelect)
          True to select the first model after the store's data changes (defaults to false).
 void setBufferedRender(boolean bufferRender)
          True to only render tree nodes that are in view (defaults to false).
 void setCaching(boolean caching)
          Sets whether the children should be cached after first being retrieved from the store (defaults to true).
 void setCell(Cell<C> cell)
          Sets the tree's cell.
 void setCheckable(boolean checkable)
          Sets whether check boxes are used in the tree (defaults to false).
 void setChecked(M item, Tree.CheckState checked)
          Sets the check state of the item.
 void setCheckedSelection(List<M> selection)
          Sets the current checked selection.
 void setCheckNodes(Tree.CheckNodes checkNodes)
          Sets which tree items will display a check box (defaults to BOTH).
 void setCheckStyle(Tree.CheckCascade checkStyle)
          Sets the cascading behavior for check tree (defaults to PARENTS).
 void setExpanded(M model, boolean expand)
          Sets the item's expand state.
 void setExpanded(M model, boolean expand, boolean deep)
          Sets the item's expand state.
 void setExpandOnFilter(boolean expandOnFilter)
          Sets whether the tree should expand all and collapse all when filters are applied (defaults to true).
 void setIconProvider(IconProvider<M> iconProvider)
          Sets the tree's model icon provider which provides the icon style for each model.
 void setLeaf(M model, boolean leaf)
          Sets the item's leaf state.
 void setLoader(TreeLoader<M> loader)
          Sets the tree loader.
 void setSelectionModel(TreeSelectionModel<M> sm)
          Sets the tree's selection model.
 void setStyle(TreeStyle style)
          Sets the tree style.
 void setTrackMouseOver(boolean trackMouseOver)
          True to highlight nodes when the mouse is over (defaults to true).
 void setView(TreeView<M> view)
          Sets the tree's view.
 void toggle(M model)
          Toggles the model's expand state.
 
Methods inherited from class com.sencha.gxt.widget.core.client.Component
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleOnOver, clearSizeCache, disable, disableEvents, enable, enableEvents, fireEvent, focus, getData, getElement, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getShadow, getStateId, getToolTip, hide, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isRendered, isStateful, isVisible, isVisible, mask, mask, removeToolTip, setAllowTextSelection, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setPagePosition, setPixelSize, setPosition, setShadow, setSize, setStateful, setStateId, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, getLayoutData, getParent, isAttached, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, removeStyleName, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, sinkBitlessEvent, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tree

@UiConstructor
public Tree(TreeStore<M> store,
                          ValueProvider<? super M,C> valueProvider)
Creates a new tree panel.

Parameters:
store - the tree store

Tree

public Tree(TreeStore<M> store,
            ValueProvider<? super M,C> valueProvider,
            Tree.TreeAppearance appearance)
Method Detail

addBeforeCheckChangeHandler

public HandlerRegistration addBeforeCheckChangeHandler(BeforeCheckChangeEvent.BeforeCheckChangeHandler<M> handler)
Description copied from interface: BeforeCheckChangeEvent.HasBeforeCheckChangeHandlers
Adds a BeforeCheckChangeEvent.BeforeCheckChangeHandler handler for BeforeCheckChangeEvent events.

Specified by:
addBeforeCheckChangeHandler in interface BeforeCheckChangeEvent.HasBeforeCheckChangeHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addBeforeCollapseHandler

public HandlerRegistration addBeforeCollapseHandler(BeforeCollapseItemEvent.BeforeCollapseItemHandler<M> handler)
Description copied from interface: BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers
Adds a BeforeCollapseItemEvent.BeforeCollapseItemHandler handler for BeforeCollapseItemEvent events.

Specified by:
addBeforeCollapseHandler in interface BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addBeforeExpandHandler

public HandlerRegistration addBeforeExpandHandler(BeforeExpandItemEvent.BeforeExpandItemHandler<M> handler)
Description copied from interface: BeforeExpandItemEvent.HasBeforeExpandItemHandlers
Adds a BeforeExpandItemEvent.BeforeExpandItemHandler handler for BeforeExpandItemEvent events.

Specified by:
addBeforeExpandHandler in interface BeforeExpandItemEvent.HasBeforeExpandItemHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addCheckChangedHandler

public HandlerRegistration addCheckChangedHandler(CheckChangedEvent.CheckChangedHandler<M> handler)
Description copied from interface: CheckChangedEvent.HasCheckChangedHandlers
Adds a CheckChangedEvent.CheckChangedHandler handler for CheckChangedEvent events.

Specified by:
addCheckChangedHandler in interface CheckChangedEvent.HasCheckChangedHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addCheckChangeHandler

public HandlerRegistration addCheckChangeHandler(CheckChangeEvent.CheckChangeHandler<M> handler)
Description copied from interface: CheckChangeEvent.HasCheckChangeHandlers
Adds a CheckChangeEvent.CheckChangeHandler handler for CheckChangeEvent events.

Specified by:
addCheckChangeHandler in interface CheckChangeEvent.HasCheckChangeHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addCollapseHandler

public HandlerRegistration addCollapseHandler(CollapseItemEvent.CollapseItemHandler<M> handler)
Description copied from interface: CollapseItemEvent.HasCollapseItemHandlers
Adds a CollapseItemEvent.CollapseItemHandler handler for CollapseItemEvent events.

Specified by:
addCollapseHandler in interface CollapseItemEvent.HasCollapseItemHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addExpandHandler

public HandlerRegistration addExpandHandler(ExpandItemEvent.ExpandItemHandler<M> handler)
Description copied from interface: ExpandItemEvent.HasExpandItemHandlers
Adds a ExpandItemEvent.ExpandItemHandler handler for ExpandItemEvent events.

Specified by:
addExpandHandler in interface ExpandItemEvent.HasExpandItemHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

collapseAll

public void collapseAll()
Collapses all nodes.


expandAll

public void expandAll()
Expands all nodes.


findNode

public Tree.TreeNode<M> findNode(Element target)
Returns the tree node for the given target.

Parameters:
target - the target element
Returns:
the tree node or null if no match

findNode

public Tree.TreeNode<M> findNode(M model)
Returns the tree node for the given model.

Parameters:
model - the model
Returns:
the tree node or null if no match

getAppearance

public Tree.TreeAppearance getAppearance()
Returns the tree appearance.

Returns:
the tree appearance

getCell

public Cell<C> getCell()
Return the tree's cell.

Returns:
the cell

getChecked

public Tree.CheckState getChecked(M model)
Returns the models checked state.

Parameters:
model - the model
Returns:
the check state

getCheckedSelection

public List<M> getCheckedSelection()
Returns the current checked selection. Only items that have been rendered will be returned in this list. Set setAutoLoad(boolean) to true to fully render the tree to receive all checked items in the tree.

Specified by:
getCheckedSelection in interface CheckProvider<M>
Returns:
the checked selection

getCheckNodes

public Tree.CheckNodes getCheckNodes()
Returns the child nodes value which determines what node types have a check box. Only applies when check boxes have been enabled ( setCheckable(boolean).

Returns:
the child nodes value

getCheckStyle

public Tree.CheckCascade getCheckStyle()
The check cascade style value which determines if check box changes cascade to parent and children.

Returns:
the check cascade style

getIconProvider

public IconProvider<M> getIconProvider()
Returns the model icon provider.

Returns:
the icon provider

getSelectionModel

public TreeSelectionModel<M> getSelectionModel()
Returns the tree's selection model.

Returns:
the selection model

getStore

public TreeStore<M> getStore()
Returns the tree's store.

Returns:
the store

getStyle

public TreeStyle getStyle()
Returns the tree style.

Returns:
the tree style

getView

public TreeView<M> getView()
Returns the tree's view.

Returns:
the view

isAutoExpand

public boolean isAutoExpand()
Returns true if auto expand is enabled.

Returns:
the auto expand state

isAutoLoad

public boolean isAutoLoad()
Returns true if auto load is enabled.

Returns:
the auto load state

isAutoSelect

public boolean isAutoSelect()
Returns true if select on load is enabled.

Returns:
the auto select state

isBufferedRender

public boolean isBufferedRender()
Returns true if buffered rendering is enabled.

Returns:
true for buffered rendering

isCaching

public boolean isCaching()
Returns true when a loader is queried for it's children each time a node is expanded. Only applies when using a loader with the tree store.

Returns:
true if caching

isCheckable

public boolean isCheckable()
Returns true if check boxes are enabled.

Returns:
the check box state

isChecked

public boolean isChecked(M model)
Description copied from interface: CheckProvider
Returns true if the model is checked.

Specified by:
isChecked in interface CheckProvider<M>
Parameters:
model - the model
Returns:
the check state

isExpanded

public boolean isExpanded(M model)
Returns true if the model is expanded.

Parameters:
model - the model
Returns:
true if expanded

isExpandOnFilter

public boolean isExpandOnFilter()
Returns the if expand all and collapse all is enabled on filter changes.

Returns:
the expand all collapse all state

isLeaf

public boolean isLeaf(M model)
Returns true if the model is a leaf node. The leaf state allows a tree item to specify if it has children before the children have been realized.

Parameters:
model - the model
Returns:
the leaf state

isTrackMouseOver

public boolean isTrackMouseOver()
Returns true if nodes are highlighted on mouse over.

Returns:
true if enabled

onBrowserEvent

public void onBrowserEvent(Event event)
Specified by:
onBrowserEvent in interface EventListener
Overrides:
onBrowserEvent in class Component

refresh

public void refresh(M model)

scrollIntoView

public void scrollIntoView(M model)
Scrolls the tree to ensure the given model is visible.

Parameters:
model - the model to scroll into view

setAutoExpand

public void setAutoExpand(boolean autoExpand)
If set to true, all non leaf nodes will be expanded automatically (defaults to false).

Parameters:
autoExpand - the auto expand state to set.

setAutoLoad

public void setAutoLoad(boolean autoLoad)
Sets whether all children should automatically be loaded recursively (defaults to false). Useful when the tree must be fully populated when initially rendered.

Parameters:
autoLoad - true to auto load

setAutoSelect

public void setAutoSelect(boolean autoSelect)
True to select the first model after the store's data changes (defaults to false).

Parameters:
autoSelect - true to auto select

setBufferedRender

public void setBufferedRender(boolean bufferRender)
True to only render tree nodes that are in view (defaults to false). Set this to true when dealing with very large trees.

Parameters:
bufferRender - true to buffer render

setCaching

public void setCaching(boolean caching)
Sets whether the children should be cached after first being retrieved from the store (defaults to true). When false, a load request will be made each time a node is expanded.

Parameters:
caching - the caching state

setCell

public void setCell(Cell<C> cell)
Sets the tree's cell.

Parameters:
cell - the cell

setCheckable

public void setCheckable(boolean checkable)
Sets whether check boxes are used in the tree (defaults to false).

Parameters:
checkable - true for check boxes

setChecked

public void setChecked(M item,
                       Tree.CheckState checked)
Sets the check state of the item. The checked state will only be set for nodes that have been rendered, setAutoLoad(boolean) can be used to render all children.

Parameters:
item - the item
checked - the check state

setCheckedSelection

public void setCheckedSelection(List<M> selection)
Description copied from interface: CheckProvider
Sets the current checked selection.

Specified by:
setCheckedSelection in interface CheckProvider<M>
Parameters:
selection - the checked selection

setCheckNodes

public void setCheckNodes(Tree.CheckNodes checkNodes)
Sets which tree items will display a check box (defaults to BOTH).

Valid values are:

Parameters:
checkNodes - the child nodes value

setCheckStyle

public void setCheckStyle(Tree.CheckCascade checkStyle)
Sets the cascading behavior for check tree (defaults to PARENTS). When using CHILDREN, it is important to note that the cascade will only be applied to rendered nodes. setAutoLoad(boolean) can be used to fully render the tree on render.

Valid values are:

Parameters:
checkStyle - the child style

setExpanded

public void setExpanded(M model,
                        boolean expand)
Sets the item's expand state.

Parameters:
model - the model
expand - true to expand

setExpanded

public void setExpanded(M model,
                        boolean expand,
                        boolean deep)
Sets the item's expand state.

Parameters:
model - the model
expand - true to expand
deep - true to expand all children recursively

setExpandOnFilter

public void setExpandOnFilter(boolean expandOnFilter)
Sets whether the tree should expand all and collapse all when filters are applied (defaults to true).

Parameters:
expandOnFilter - true to expand and collapse on filter changes

setIconProvider

public void setIconProvider(IconProvider<M> iconProvider)
Sets the tree's model icon provider which provides the icon style for each model.

Parameters:
iconProvider - the icon provider

setLeaf

public void setLeaf(M model,
                    boolean leaf)
Sets the item's leaf state. The leaf state allows control of the expand icon before the children have been realized.

Parameters:
model - the model
leaf - the leaf state

setLoader

public void setLoader(TreeLoader<M> loader)
Sets the tree loader.

Parameters:
loader - the loader

setSelectionModel

public void setSelectionModel(TreeSelectionModel<M> sm)
Sets the tree's selection model.

Parameters:
sm - the selection model

setStyle

public void setStyle(TreeStyle style)
Sets the tree style.

Parameters:
style - the tree style

setTrackMouseOver

public void setTrackMouseOver(boolean trackMouseOver)
True to highlight nodes when the mouse is over (defaults to true).

Parameters:
trackMouseOver - true to highlight nodes on mouse over

setView

public void setView(TreeView<M> view)
Sets the tree's view. Only needs to be called when customizing the tree's presentation.

Parameters:
view - the view

toggle

public void toggle(M model)
Toggles the model's expand state.

Parameters:
model - the model


Copyright © 2012. All Rights Reserved.