wicket.markup.html.tree
Class Tree

java.lang.Object
  extended by wicket.Component
      extended by wicket.MarkupContainer
          extended by wicket.markup.html.WebMarkupContainer
              extended by wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
                  extended by wicket.markup.html.panel.Panel
                      extended by wicket.markup.html.tree.AbstractTree
                          extended by wicket.markup.html.tree.Tree
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.TreeModelListener

public class Tree
extends AbstractTree
implements javax.swing.event.TreeModelListener

An tree that renders as a flat (not-nested) list, using spacers for indentation and nodes at the end of one row.

The visible tree rows are put in one flat list. For each row, a list is constructed with fillers, that can be used to create indentation. After the fillers, the actual node content is put.

Author:
Eelco Hillenius
See Also:
Serialized Form

Nested Class Summary
static class Tree.DefaultNodePanel
          The default node panel.
 
Nested classes/interfaces inherited from class wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
WebMarkupContainerWithAssociatedMarkup.HeaderPartContainer
 
Nested classes/interfaces inherited from class wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor, Component.VisibilityChange
 
Field Summary
static java.lang.String JUNCTION_IMAGE_NAME
          Name of the junction image component; value = 'junctionImage'.
static java.lang.String NODE_IMAGE_NAME
          Name of the node image component; value = 'nodeImage'.
 
Fields inherited from class wicket.Component
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Constructor Summary
Tree(java.lang.String id, javax.swing.tree.TreeModel model)
          Constructor.
Tree(java.lang.String id, TreeState treeState)
          Construct using the given tree state that holds the model to be used as the tree model.
 
Method Summary
protected  Link createJunctionLink(javax.swing.tree.DefaultMutableTreeNode node)
          Creates a junction link.
protected  Link createNodeLink(javax.swing.tree.DefaultMutableTreeNode node)
          Creates a node link.
protected  wicket.markup.html.tree.Tree.TreePathsListView createTreePathsListView()
          Creates the tree paths list view.
protected  boolean equals(javax.swing.tree.TreePath path, javax.swing.tree.TreePath selectedPath)
          Returns whether the path and the selected path are equal.
protected  PackageResourceReference getCss()
          Gets the stylesheet.
protected  Image getJunctionImage(javax.swing.tree.DefaultMutableTreeNode node)
          Get image for a junction; used by method createExpandCollapseLink.
protected  Image getNodeImage(javax.swing.tree.DefaultMutableTreeNode node)
          Get image for a node; used by method createNodeLink.
protected  java.lang.String getNodeLabel(javax.swing.tree.DefaultMutableTreeNode node)
          Gets the label of the node that is used for the node link.
 boolean getOptimizeItemRemoval()
          Deprecated. Will be replaced by getReuseItems()
 boolean getReuseItems()
          Gets whether items should be reused.
protected  void internalOnAttach()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  void junctionLinkClicked(javax.swing.tree.DefaultMutableTreeNode node)
          Handler that is called when a junction link is clicked; this implementation sets the expanded state to one that corresponds with the node selection.
protected  Component newNodePanel(java.lang.String panelId, javax.swing.tree.DefaultMutableTreeNode node)
          Create a new panel for a tree node.
protected  void nodeLinkClicked(javax.swing.tree.DefaultMutableTreeNode node)
          Handler that is called when a node link is clicked; this implementation sets the expanded state just as a click on a junction would do.
 void setOptimizeItemRemoval(boolean optimizeItemRemoval)
          Deprecated. Will be replaced by setReuseItems(boolean)
 Tree setReuseItems(boolean reuseItems)
          Sets whether item removal should be optimized.
 void setTreeModel(javax.swing.tree.TreeModel treeModel)
          Sets the current tree model.
 void setTreeState(TreeState treeState)
          Sets the current tree state to the given tree state.
 void treeNodesChanged(javax.swing.event.TreeModelEvent e)
           
 void treeNodesInserted(javax.swing.event.TreeModelEvent e)
           
 void treeNodesRemoved(javax.swing.event.TreeModelEvent e)
           
 void treeStructureChanged(javax.swing.event.TreeModelEvent e)
           
 
Methods inherited from class wicket.markup.html.tree.AbstractTree
collapsePath, collapseSiblings, expandAll, expandPath, getTreeState, isExpanded, isExpanded, isRootVisible, isVisible, newTreeState, newTreeState, setExpandedState, setExpandedState, setRootVisible, setSelected, toString
 
Methods inherited from class wicket.markup.html.panel.Panel
onComponentTag, onComponentTagBody, renderHead
 
Methods inherited from class wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
newHeaderPartContainer, renderHeadFromAssociatedMarkupFile
 
Methods inherited from class wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage
 
Methods inherited from class wicket.MarkupContainer
add, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, internalAdd, internalAttach, internalDetach, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, visitChildren, visitChildren
 
Methods inherited from class wicket.Component
add, addStateChange, checkComponentTag, checkComponentTagAttribute, continueToOriginalDestination, debug, detachBehaviors, detachModel, detachModels, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getApplicationPages, getApplicationSettings, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getOutputMarkupId, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isBehaviorAccepted, isEnableAllowed, isEnabled, isHeadRendered, isIgnoreAttributeModifier, isRenderAllowed, isVersioned, isVisible, isVisibleInHierarchy, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeforeRender, onBeginRequest, onDetach, onEndRequest, onModelChanged, onModelChanging, onRender, redirectToInterceptPage, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderedBehaviors, replaceComponentTagBody, replaceWith, resetHeadRendered, sameRootModel, sameRootModel, setAuto, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMetaData, setModelObject, setOutputMarkupId, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JUNCTION_IMAGE_NAME

public static final java.lang.String JUNCTION_IMAGE_NAME
Name of the junction image component; value = 'junctionImage'.

See Also:
Constant Field Values

NODE_IMAGE_NAME

public static final java.lang.String NODE_IMAGE_NAME
Name of the node image component; value = 'nodeImage'.

See Also:
Constant Field Values
Constructor Detail

Tree

public Tree(java.lang.String id,
            javax.swing.tree.TreeModel model)
Constructor.

Parameters:
id - The id of this container
model - the underlying tree model

Tree

public Tree(java.lang.String id,
            TreeState treeState)
Construct using the given tree state that holds the model to be used as the tree model.

Parameters:
id - The id of this container
treeState - treeState that holds the underlying tree model
Method Detail

getOptimizeItemRemoval

public boolean getOptimizeItemRemoval()
Deprecated. Will be replaced by getReuseItems()

Gets whether item removal should be optimized. If true, re-rendering the tree is more efficient if the tree model doesn't get changed. However, if this is true, you need to push changes to this tree. This can easility be done by registering this tree as the listener for tree model events (TreeModelListener), but you should be carefull not to create a memory leak by doing this (e.g. when you store the tree model in your session, the tree you registered cannot be GC-ed). TRUE by default.

Returns:
whether item removal should be optimized

getReuseItems

public boolean getReuseItems()
Gets whether items should be reused. If true, re-rendering the tree is more efficient if the tree model doesn't get changed. However, if this is true, you need to push changes to this tree. This can easility be done by registering this tree as the listener for tree model events (TreeModelListener), but you should be carefull not to create a memory leak by doing this (e.g. when you store the tree model in your session, the tree you registered cannot be GC-ed). TRUE by default.

Returns:
whether items should be reused

setOptimizeItemRemoval

public void setOptimizeItemRemoval(boolean optimizeItemRemoval)
Deprecated. Will be replaced by setReuseItems(boolean)

Sets whether items should be reused. If true, re-rendering the tree is more efficient if the tree model doesn't get changed. However, if this is true, you need to push changes to this tree. This can easility be done by registering this tree as the listener for tree model events (TreeModelListener), but you should be carefull not to create a memory leak by doing this (e.g. when you store the tree model in your session, the tree you registered cannot be GC-ed). TRUE by default.

Parameters:
optimizeItemRemoval - whether the child items should be reused

setReuseItems

public Tree setReuseItems(boolean reuseItems)
Sets whether item removal should be optimized. If true, re-rendering the tree is more efficient if the tree model doesn't get changed. However, if this is true, you need to push changes to this tree. This can easility be done by registering this tree as the listener for tree model events (TreeModelListener), but you should be carefull not to create a memory leak by doing this (e.g. when you store the tree model in your session, the tree you registered cannot be GC-ed). TRUE by default.

Parameters:
reuseItems - whether the child items should be reused
Returns:
This

setTreeModel

public void setTreeModel(javax.swing.tree.TreeModel treeModel)
Sets the current tree model.

Overrides:
setTreeModel in class AbstractTree
Parameters:
treeModel - the tree model to set as the current one

setTreeState

public void setTreeState(TreeState treeState)
Sets the current tree state to the given tree state.

Overrides:
setTreeState in class AbstractTree
Parameters:
treeState - the tree state to set as the current one

treeNodesChanged

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

treeNodesInserted

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

treeNodesRemoved

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

treeStructureChanged

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

createJunctionLink

protected Link createJunctionLink(javax.swing.tree.DefaultMutableTreeNode node)
Creates a junction link.

Parameters:
node - the node
Returns:
link for expanding/ collapsing the tree

createNodeLink

protected Link createNodeLink(javax.swing.tree.DefaultMutableTreeNode node)
Creates a node link.

Parameters:
node - the model of the node
Returns:
link for selection

createTreePathsListView

protected final wicket.markup.html.tree.Tree.TreePathsListView createTreePathsListView()
Creates the tree paths list view.

Returns:
the tree paths list view

equals

protected boolean equals(javax.swing.tree.TreePath path,
                         javax.swing.tree.TreePath selectedPath)
Returns whether the path and the selected path are equal. This method is used by the AttributeModifierthat is used for setting the CSS class for the selected row.

Parameters:
path - the path
selectedPath - the selected path
Returns:
true if the path and the selected are equal, false otherwise

getCss

protected PackageResourceReference getCss()
Gets the stylesheet.

Returns:
the stylesheet

getJunctionImage

protected Image getJunctionImage(javax.swing.tree.DefaultMutableTreeNode node)
Get image for a junction; used by method createExpandCollapseLink. If you use the packaged panel (Tree.html), you must name the component using JUNCTION_IMAGE_NAME.

Parameters:
node - the tree node
Returns:
the image for the junction

getNodeImage

protected Image getNodeImage(javax.swing.tree.DefaultMutableTreeNode node)
Get image for a node; used by method createNodeLink. If you use the packaged panel (Tree.html), you must name the component using NODE_IMAGE_NAME.

Parameters:
node - the tree node
Returns:
the image for the node

getNodeLabel

protected java.lang.String getNodeLabel(javax.swing.tree.DefaultMutableTreeNode node)
Gets the label of the node that is used for the node link. Defaults to treeNodeModel.getUserObject().toString(); override to provide a custom label

Parameters:
node - the tree node
Returns:
the label of the node that is used for the node link

internalOnAttach

protected void internalOnAttach()
Description copied from class: Component
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL OR OVERRIDE. Called when a request begins.

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

junctionLinkClicked

protected void junctionLinkClicked(javax.swing.tree.DefaultMutableTreeNode node)
Handler that is called when a junction link is clicked; this implementation sets the expanded state to one that corresponds with the node selection.

Parameters:
node - the tree node

newNodePanel

protected Component newNodePanel(java.lang.String panelId,
                                 javax.swing.tree.DefaultMutableTreeNode node)
Create a new panel for a tree node. This method can be overriden to provide a custom panel. This way, you can effectively nest anything you want in the tree, like input fields, images, etc.

you must use the provide panelId as the id of your custom panel
for example, do:

 return new MyNodePanel(panelId, node);
 

You can choose to either let your own panel extend from DefaultNodePanel when you just want to provide different markup but want to reuse the default components on this panel, or extend from NodePanel directly, and provide any component structure you like.

Parameters:
panelId - the id that the panel MUST use
node - the tree node for the panel
Returns:
a new Panel

nodeLinkClicked

protected void nodeLinkClicked(javax.swing.tree.DefaultMutableTreeNode node)
Handler that is called when a node link is clicked; this implementation sets the expanded state just as a click on a junction would do. Override this for custom behavior.

Parameters:
node - the tree node model


Copyright © 2004-2007 Wicket developers. All Rights Reserved.