wicket.markup.html.tree
Class TreeState

java.lang.Object
  extended by wicket.markup.html.tree.TreeState
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.TreeModelListener, javax.swing.tree.RowMapper

public final class TreeState
extends java.lang.Object
implements java.io.Serializable, javax.swing.event.TreeModelListener, javax.swing.tree.RowMapper

Holder and handler for tree state. This class is largely based on FixedHeightLayoutCachefrom JDK 1.5_01. Using that class or VariableHeightLayoutCachegave problems when working in clustered environments. Hence, for this class most of the useful workings of FixedHeightLayoutCache were copied, while everything that is Swing/paint specific was removed.

Author:
Eelco Hillenius, Scott Violet (Sun, FixedHeightLayoutCache)
See Also:
Serialized Form

Constructor Summary
TreeState()
          Construct.
 
Method Summary
 boolean getExpandedState(javax.swing.tree.TreePath path)
          Returns true if the path is expanded, and visible.
 javax.swing.tree.TreeModel getModel()
          Returns the TreeModel that is providing the data.
 javax.swing.tree.TreePath getPathForRow(int row)
          Returns the path for passed in row.
 int getRowCount()
          Returns the number of visible rows.
 int getRowForPath(javax.swing.tree.TreePath path)
          Returns the row that the last item identified in path is visible at.
 int[] getRowsForPaths(javax.swing.tree.TreePath[] paths)
          Returns the rows that the TreePath instances in path are being displayed at.
 javax.swing.tree.TreePath getSelectedPath()
          Gets the currently selected path.
 javax.swing.tree.TreeSelectionModel getSelectionModel()
          Returns the model used to maintain the selection.
 int getVisibleChildCount(javax.swing.tree.TreePath path)
          Returns the number of visible children for row.
 java.util.Enumeration getVisiblePathsFrom(javax.swing.tree.TreePath path)
          Returns an Enumerator that increments over the visible paths starting at the passed in location.
 boolean isExpanded(javax.swing.tree.TreePath path)
          Returns true if the value identified by row is currently expanded.
 boolean isRootVisible()
          Returns true if the root node of the tree is displayed.
 void setExpandedState(javax.swing.tree.TreePath path, boolean isExpanded)
          Marks the path path expanded state to isExpanded.
 void setModel(javax.swing.tree.TreeModel newModel)
          Sets the TreeModel that will provide the data.
 void setRootVisible(boolean rootVisible)
          Determines whether or not the root node from the TreeModel is visible.
 void setSelectedPath(javax.swing.tree.TreePath selection)
          Expands the selected path and set selection to currently selected path.
 void setSelectionModel(javax.swing.tree.TreeSelectionModel selectionModel)
          Sets the TreeSelectionModel used to manage the selection to new LSM.
 void treeNodesChanged(javax.swing.event.TreeModelEvent e)
           Invoked after a node (or a set of siblings) has changed in some way.
 void treeNodesInserted(javax.swing.event.TreeModelEvent e)
           Invoked after nodes have been inserted into the tree.
 void treeNodesRemoved(javax.swing.event.TreeModelEvent e)
           Invoked after nodes have been removed from the tree.
 void treeStructureChanged(javax.swing.event.TreeModelEvent e)
           Invoked after the tree has drastically changed structure from a given node down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeState

public TreeState()
Construct.

Method Detail

setSelectedPath

public void setSelectedPath(javax.swing.tree.TreePath selection)
Expands the selected path and set selection to currently selected path.

Parameters:
selection - the new selection.

getSelectedPath

public javax.swing.tree.TreePath getSelectedPath()
Gets the currently selected path.

Returns:
the currently selected path

getModel

public javax.swing.tree.TreeModel getModel()
Returns the TreeModel that is providing the data.

Returns:
the TreeModel that is providing the data

isRootVisible

public boolean isRootVisible()
Returns true if the root node of the tree is displayed.

Returns:
true if the root node of the tree is displayed

setSelectionModel

public void setSelectionModel(javax.swing.tree.TreeSelectionModel selectionModel)
Sets the TreeSelectionModel used to manage the selection to new LSM.

Parameters:
selectionModel - the new TreeSelectionModel

getSelectionModel

public javax.swing.tree.TreeSelectionModel getSelectionModel()
Returns the model used to maintain the selection.

Returns:
the treeSelectionModel

getRowsForPaths

public int[] getRowsForPaths(javax.swing.tree.TreePath[] paths)
Returns the rows that the TreePath instances in path are being displayed at. This method should return an array of the same length as that passed in, and if one of the TreePaths in path is not valid its entry in the array should be set to -1.

Specified by:
getRowsForPaths in interface javax.swing.tree.RowMapper
Parameters:
paths - the array of TreePath s being queried
Returns:
an array of the same length that is passed in containing the rows that each corresponding where each TreePath is displayed; if paths is null, null is returned

setModel

public void setModel(javax.swing.tree.TreeModel newModel)
Sets the TreeModel that will provide the data.

Parameters:
newModel - the TreeModel that is to provide the data

setRootVisible

public void setRootVisible(boolean rootVisible)
Determines whether or not the root node from the TreeModel is visible.

Parameters:
rootVisible - true if the root node of the tree is to be displayed

getRowCount

public int getRowCount()
Returns the number of visible rows.

Returns:
the number of visible rows

isExpanded

public boolean isExpanded(javax.swing.tree.TreePath path)
Returns true if the value identified by row is currently expanded.

Parameters:
path - the row
Returns:
true if the value identified by row is currently expanded

getPathForRow

public javax.swing.tree.TreePath getPathForRow(int row)
Returns the path for passed in row. If row is not visible null is returned.

Parameters:
row - the row
Returns:
the path for passed in row

getRowForPath

public int getRowForPath(javax.swing.tree.TreePath path)
Returns the row that the last item identified in path is visible at. Will return -1 if any of the elements in path are not currently visible.

Parameters:
path - the path
Returns:
the row that the last item identified in path is visible at

getVisibleChildCount

public int getVisibleChildCount(javax.swing.tree.TreePath path)
Returns the number of visible children for row.

Parameters:
path - the path
Returns:
the number of visible children for row

getVisiblePathsFrom

public java.util.Enumeration getVisiblePathsFrom(javax.swing.tree.TreePath path)
Returns an Enumerator that increments over the visible paths starting at the passed in location. The ordering of the enumeration is based on how the paths are displayed.

Parameters:
path - the path
Returns:
an Enumerator that increments over the visible paths

setExpandedState

public void setExpandedState(javax.swing.tree.TreePath path,
                             boolean isExpanded)
Marks the path path expanded state to isExpanded.

Parameters:
path - the path
isExpanded - whether the path is expanded

getExpandedState

public boolean getExpandedState(javax.swing.tree.TreePath path)
Returns true if the path is expanded, and visible.

Parameters:
path - the path
Returns:
true if the path is expanded, and visible

treeNodesChanged

public void treeNodesChanged(javax.swing.event.TreeModelEvent e)

Invoked after a node (or a set of siblings) has changed in some way. The node(s) have not changed locations in the tree or altered their children arrays, but other attributes have changed and may affect presentation. Example: the name of a file has changed, but it is in the same location in the file system.

e.path() returns the path the parent of the changed node(s).

e.childIndices() returns the index(es) of the changed node(s).

Specified by:
treeNodesChanged in interface javax.swing.event.TreeModelListener
Parameters:
e - the tree model event

treeNodesInserted

public void treeNodesInserted(javax.swing.event.TreeModelEvent e)

Invoked after nodes have been inserted into the tree.

e.path() returns the parent of the new nodes

e.childIndices() returns the indices of the new nodes in ascending order.

Specified by:
treeNodesInserted in interface javax.swing.event.TreeModelListener
Parameters:
e - the tree model event

treeNodesRemoved

public void treeNodesRemoved(javax.swing.event.TreeModelEvent e)

Invoked after nodes have been removed from the tree. Note that if a subtree is removed from the tree, this method may only be invoked once for the root of the removed subtree, not once for each individual set of siblings removed.

e.path() returns the former parent of the deleted nodes.

e.childIndices() returns the indices the nodes had before they were deleted in ascending order.

Specified by:
treeNodesRemoved in interface javax.swing.event.TreeModelListener
Parameters:
e - the tree model event

treeStructureChanged

public void treeStructureChanged(javax.swing.event.TreeModelEvent e)

Invoked after the tree has drastically changed structure from a given node down. If the path returned by e.getPath() is of length one and the first element does not identify the current root node the first element should become the new root of the tree.

e.path() holds the path to the node.

e.childIndices() returns null.

Specified by:
treeStructureChanged in interface javax.swing.event.TreeModelListener
Parameters:
e - the tree model event


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