org.apache.wicket.markup.html.tree
Class AbstractTree

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
                  extended by org.apache.wicket.markup.html.panel.Panel
                      extended by org.apache.wicket.markup.html.tree.AbstractTree
All Implemented Interfaces:
Serializable, EventListener, TreeModelListener, AjaxRequestTarget.ITargetRespondListener, IClusterable, IConverterLocator, IHeaderPartContainerProvider, ITreeStateListener
Direct Known Subclasses:
BaseTree, DefaultAbstractTree

public abstract class AbstractTree
extends Panel
implements ITreeStateListener, TreeModelListener, AjaxRequestTarget.ITargetRespondListener

This class encapsulates the logic for displaying and (partial) updating the tree. Actual presentation is out of scope of this class. User should derive they own tree (if needed) from BaseTree (recommended).

Author:
Matej Knopp
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor<T extends Component>, Component.VisibilityChange
 
Field Summary
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_CONFIGURED, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
AbstractTree(String id)
          Tree constructor
AbstractTree(String id, IModel<TreeModel> model)
          Tree constructor
 
Method Summary
protected  void addComponent(AjaxRequestTarget target, Component component)
          Allows to intercept adding dirty components to AjaxRequestTarget.
 void allNodesCollapsed()
          called when all nodes are collapsed.
 void allNodesExpanded()
          called when all nodes are expanded.
 Object getChildAt(Object parent, int index)
           
 int getChildCount(Object parent)
           
 IModel<TreeModel> getModel()
           
 TreeModel getModelObject()
           
 Component getNodeComponent(Object node)
          Returns the component associated with given node, or null, if node is not visible.
 Object getParentNode(Object node)
          Returns parent node of given node.
 ITreeState getTreeState()
          Returns the TreeState of this tree.
 void invalidateAll()
          Call to refresh the whole tree.
protected  boolean isForceRebuildOnSelectionChange()
          Determines whether the TreeNode needs to be rebuilt if it is selected or deselected
 boolean isLeaf(Object node)
           
protected  boolean isNodeExpanded(Object node)
          Returns whether the given node is expanded.
 boolean isRootLess()
           
 void markNodeChildrenDirty(Object node)
          INTERNAL
 void markNodeDirty(Object node)
          INTERNAL
protected  ITreeState newTreeState()
          Creates the TreeState, which is an object where the current state of tree (which nodes are expanded / collapsed, selected, ...) is stored.
 Iterator<Object> nodeChildren(Object node)
          Return the representation of node children as Iterator interface.
 void nodeCollapsed(Object node)
          Fired when given node is collapsed.
 void nodeExpanded(Object node)
          Fired when given node is expanded.
 void nodeSelected(Object node)
          Fired when given node gets selected.
 void nodeUnselected(Object node)
          Fired when given node gets unselected.
protected  void onAfterRender()
          Called after the rendering of tree is complete.
protected  void onBeforeAttach()
          This method is called before the onAttach is called.
 void onBeforeRender()
          Called at the beginning of the request (not ajax request, unless we are rendering the entire component)
 void onDetach()
          Called to allow a component to detach resources after use.
 void onTargetRespond(AjaxRequestTarget target)
          Invoked when AjaxRequestTarget is about the respond.
protected abstract  void populateTreeItem(WebMarkupContainer item, int level)
          This method is called after creating every TreeItem.
 MarkupContainer setModel(IModel<TreeModel> model)
           
 MarkupContainer setModelObject(TreeModel model)
           
 void setRootLess(boolean rootLess)
          Sets whether the root of the tree should be visible.
 void treeNodesChanged(TreeModelEvent e)
           
 void treeNodesInserted(TreeModelEvent e)
           
 void treeNodesRemoved(TreeModelEvent removalEvent)
           
 void treeStructureChanged(TreeModelEvent e)
           
 void updateTree()
          Convenience method that updates changed portions on tree.
 void updateTree(AjaxRequestTarget target)
          Updates the changed portions of the tree using given AjaxRequestTarget.
 
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
onComponentTag, onComponentTagBody, renderHead
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
newHeaderPartContainer, renderHeadFromAssociatedMarkupFile
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onAfterRenderChildren, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, renderNext, replace, setDefaultModel, setMarkupStream, size, swap, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachBehaviors, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdImpl, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalAttach, internalDetach, internalOnAttach, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, onAttach, onBeginRequest, onConfigure, onEndRequest, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractTree

public AbstractTree(String id)
Tree constructor

Parameters:
id - The component id

AbstractTree

public AbstractTree(String id,
                    IModel<TreeModel> model)
Tree constructor

Parameters:
id - The component id
model - The tree model
Method Detail

allNodesCollapsed

public final void allNodesCollapsed()
called when all nodes are collapsed.

Specified by:
allNodesCollapsed in interface ITreeStateListener

allNodesExpanded

public final void allNodesExpanded()
called when all nodes are expanded.

Specified by:
allNodesExpanded in interface ITreeStateListener

getModel

public IModel<TreeModel> getModel()
Returns:
model

getModelObject

public TreeModel getModelObject()
Returns:
treemodel

setModel

public MarkupContainer setModel(IModel<TreeModel> model)
Parameters:
model - model
Returns:
this

setModelObject

public MarkupContainer setModelObject(TreeModel model)
Parameters:
model - model
Returns:
this

getTreeState

public ITreeState getTreeState()
Returns the TreeState of this tree.

Returns:
Tree state instance

onBeforeAttach

protected void onBeforeAttach()
This method is called before the onAttach is called. Code here gets executed before the items have been populated.


onBeforeRender

public void onBeforeRender()
Called at the beginning of the request (not ajax request, unless we are rendering the entire component)

Overrides:
onBeforeRender in class Component
See Also:
Component.callOnBeforeRenderIfNotVisible()

onDetach

public void onDetach()
Description copied from class: Component
Called to allow a component to detach resources after use. Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.

Overrides:
onDetach in class Component
See Also:
Component.onDetach()

invalidateAll

public final void invalidateAll()
Call to refresh the whole tree. This should only be called when the roodNode has been replaced or the entiry tree model changed.


isRootLess

public final boolean isRootLess()
Returns:
whether the tree root is shown

nodeCollapsed

public final void nodeCollapsed(Object node)
Description copied from interface: ITreeStateListener
Fired when given node is collapsed.

Specified by:
nodeCollapsed in interface ITreeStateListener
Parameters:
node - The node that was collapsed
See Also:
ITreeStateListener.nodeCollapsed(Object)

nodeExpanded

public final void nodeExpanded(Object node)
Description copied from interface: ITreeStateListener
Fired when given node is expanded.

Specified by:
nodeExpanded in interface ITreeStateListener
See Also:
ITreeStateListener.nodeExpanded(Object)

nodeSelected

public final void nodeSelected(Object node)
Description copied from interface: ITreeStateListener
Fired when given node gets selected.

Specified by:
nodeSelected in interface ITreeStateListener
Parameters:
node - The node that was selected
See Also:
)

nodeUnselected

public final void nodeUnselected(Object node)
Description copied from interface: ITreeStateListener
Fired when given node gets unselected.

Specified by:
nodeUnselected in interface ITreeStateListener
Parameters:
node - The node that was unselected
See Also:
ITreeStateListener.nodeUnselected(Object)

isForceRebuildOnSelectionChange

protected boolean isForceRebuildOnSelectionChange()
Determines whether the TreeNode needs to be rebuilt if it is selected or deselected

Returns:
true if the node should be rebuilt after (de)selection, false otherwise

setRootLess

public void setRootLess(boolean rootLess)
Sets whether the root of the tree should be visible.

Parameters:
rootLess - whether the root should be visible

treeNodesChanged

public final void treeNodesChanged(TreeModelEvent e)
Specified by:
treeNodesChanged in interface TreeModelListener
See Also:
TreeModelListener.treeNodesChanged(javax.swing.event.TreeModelEvent)

treeNodesInserted

public final void treeNodesInserted(TreeModelEvent e)
Specified by:
treeNodesInserted in interface TreeModelListener
See Also:
TreeModelListener.treeNodesInserted(javax.swing.event.TreeModelEvent)

treeNodesRemoved

public final void treeNodesRemoved(TreeModelEvent removalEvent)
Specified by:
treeNodesRemoved in interface TreeModelListener
See Also:
TreeModelListener.treeNodesRemoved(javax.swing.event.TreeModelEvent)

treeStructureChanged

public final void treeStructureChanged(TreeModelEvent e)
Specified by:
treeStructureChanged in interface TreeModelListener
See Also:
TreeModelListener.treeStructureChanged(javax.swing.event.TreeModelEvent)

updateTree

public final void updateTree()
Convenience method that updates changed portions on tree. You can call this method during Ajax response, where calling updateTree(AjaxRequestTarget) would be appropriate, but you don't have the AjaxRequestTarget instance. However, it is also safe to call this method outside Ajax response.


addComponent

protected void addComponent(AjaxRequestTarget target,
                            Component component)
Allows to intercept adding dirty components to AjaxRequestTarget.

Parameters:
target - ajax request target
component - component

onTargetRespond

public void onTargetRespond(AjaxRequestTarget target)
Description copied from interface: AjaxRequestTarget.ITargetRespondListener
Invoked when AjaxRequestTarget is about the respond.

Specified by:
onTargetRespond in interface AjaxRequestTarget.ITargetRespondListener

updateTree

public final void updateTree(AjaxRequestTarget target)
Updates the changed portions of the tree using given AjaxRequestTarget. Call this method if you modified the tree model during an ajax request target and you want to partially update the component on page. Make sure that the tree model has fired the proper listener functions.

You can only call this method once in a request.

Parameters:
target - Ajax request target used to send the update to the page

isNodeExpanded

protected final boolean isNodeExpanded(Object node)
Returns whether the given node is expanded.

Parameters:
node - The node to inspect
Returns:
true if the node is expanded, false otherwise

newTreeState

protected ITreeState newTreeState()
Creates the TreeState, which is an object where the current state of tree (which nodes are expanded / collapsed, selected, ...) is stored.

Returns:
Tree state instance

onAfterRender

protected void onAfterRender()
Called after the rendering of tree is complete. Here we clear the dirty flags.

Overrides:
onAfterRender in class Component

populateTreeItem

protected abstract void populateTreeItem(WebMarkupContainer item,
                                         int level)
This method is called after creating every TreeItem. This is the place for adding components on item (junction links, labels, icons...)

Parameters:
item - newly created tree item. The node can be obtained as item.getModelObject()
level - how deep the component is in tree hierarchy (0 for root item)

markNodeDirty

public final void markNodeDirty(Object node)
INTERNAL

Parameters:
node - node

markNodeChildrenDirty

public final void markNodeChildrenDirty(Object node)
INTERNAL

Parameters:
node - node

getParentNode

public Object getParentNode(Object node)
Returns parent node of given node.

Parameters:
node - node
Returns:
parent node

nodeChildren

public final Iterator<Object> nodeChildren(Object node)
Return the representation of node children as Iterator interface.

Parameters:
node - The tree node
Returns:
iterable presentation of node children

getChildAt

public final Object getChildAt(Object parent,
                               int index)
Parameters:
parent - parent node
index - index
Returns:
child

isLeaf

public final boolean isLeaf(Object node)
Parameters:
node - node
Returns:
boolean

getChildCount

public final int getChildCount(Object parent)
Parameters:
parent - parent node
Returns:
child count

getNodeComponent

public Component getNodeComponent(Object node)
Returns the component associated with given node, or null, if node is not visible. This is useful in situations when you want to touch the node element in html.

Parameters:
node - Tree node
Returns:
Component associated with given node, or null if node is not visible.


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.