JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util.treetable
Class TreeWithSortableChildren

java.lang.Object
  |
  +--com.klg.jclass.util.treetable.TreeWithSortableChildren
All Implemented Interfaces:
JCRowSortModel, JCTreeTableModel, Serializable, TreeModel

public class TreeWithSortableChildren
extends Object
implements JCTreeTableModel, JCRowSortModel, Serializable

Provides a sorted mapping for children of a given node.

See Also:
Serialized Form

Nested Class Summary
static class TreeWithSortableChildren.HashObject
          Guarantees that the object that you are hashing will compare uniquely only to the object being stored therein.
 
Field Summary
protected  boolean autoSort
           
protected  int[][] keyColumnsArray
           
protected  com.klg.jclass.util.treetable.TreeWithSortableChildren.Listener l
           
protected  com.klg.jclass.util.JCListenerList listeners
           
protected  boolean needsReordering
           
protected  boolean needsResorting
           
protected  HashMap nodeChildIndexMaps
           
protected  com.klg.jclass.util.swing.JCRowComparator rowComparator
           
protected  com.klg.jclass.util.treetable.TreeWithSortableChildren.RowIntComparator rowIntComparator
           
protected  int sortColumn
           
protected  int sortOrder
           
protected  com.klg.jclass.util.treetable.JCTreeTableModel treetable
           
 
Fields inherited from interface com.klg.jclass.util.swing.JCRowSortModel
FORWARD, REVERSE
 
Constructor Summary
TreeWithSortableChildren(com.klg.jclass.util.treetable.JCTreeTableModel treetable)
          Constructs a JCTreeTableModel that that wraps a given instance of a JCTreeTableModel and provides a sorted mapping of the children for any given leaf node.
TreeWithSortableChildren(com.klg.jclass.util.treetable.JCTreeTableModel treetable, com.klg.jclass.util.swing.JCRowComparator comparator)
          Constructs a JCTreeTableModel that wraps a given instance of a JCTreeTableModel and provides a sorted mapping of the children for any given leaf node.
 
Method Summary
 void addTreeModelListener(TreeModelListener l)
          Removes the specified treemodel listener.
 boolean getAutoSort()
          Returns whether the data is automatically sorted when it changes according the current comparator.
 Object getChild(Object parent, int index)
          Returns the "index"th non-leaf child of this node.
 int getChildCount(Object parent)
          Return the number of children.
 Class getColumnClass(int column)
          Returns the class of the given column index.
 int getColumnCount()
          Returns the number of columns.
 String getColumnName(int column)
          Returns the column name for the given column index.
 int getIndexOfChild(Object parent, Object child)
          Returns the non-leaf index of this child.
protected  int[] getIndices(Object parent)
          Gets the mapped indices; returns null if unsorted.
 int[] getKeyColumns(int column)
          Returns the key columns used to sort the table model when clicking on a specified column.
 com.klg.jclass.util.treetable.JCTreeTableModel getModel()
          Returns the JCTreeTable model this model wraps
protected static Object getNode(TreePath path)
          Given a TreePath, this method returns the last component or "node" of the TreePath.
 Object getRoot()
          Returns the root node of the tree.
 int getSortColumn()
          Gets the sorting column.
 int getSortOrder()
          Gets the sorting order to use the next time a sort is performed.
 Object getValueAt(Object node, int column)
          Returns the value of the specific node and column.
 boolean isCellEditable(Object node, int column)
          Returns whether a particular cell is editable given the node and column.
 boolean isDataSorted()
          Returns whether or not the data set is currently sorted.
 boolean isLeaf(Object node)
          Returns whether the child is a leaf.
protected  void postTreeStructureChanged(TreeModelEvent event)
          Invoked after the tree has drastically changed structure from a given node down.
protected  void postTreeStructureChanged(TreeModelEvent event, boolean external)
          Invoked after the tree has drastically changed structure from a given node down.
 void removeTreeModelListener(TreeModelListener l)
          Removes the specified treemodel listener.
 void setAutoSort(boolean autoSort)
          Sets whether the data should be automatically sorted when it changes.
 void setDataSorted(boolean sorted)
          Sorts data by current column if set to true and the data needs sorting; or, if set to false, it returns the data in its native unsorted state.
 void setKeyColumns(int column, int[] keyColumns)
          Sets the key columns used to sort the table model when clicking on a specified column.
 void setModel(com.klg.jclass.util.treetable.JCTreeTableModel newModel)
          Sets the tree table model wrapped by this model.
 void setSortColumn(int column)
          Sets the column to use the next time a sort is performed.
 void setSortOrder(int order)
          Sets the sorting order.
 void setValueAt(Object value, Object node, int column)
          Sets the value at a particular node and column.
 void toggleSortOrder()
          Toggles the sorting order.
 void valueForPathChanged(TreePath path, Object newValue)
          Calls the underling trees valueForPathChanged method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

treetable

protected com.klg.jclass.util.treetable.JCTreeTableModel treetable

sortColumn

protected int sortColumn

sortOrder

protected int sortOrder

rowComparator

protected com.klg.jclass.util.swing.JCRowComparator rowComparator

keyColumnsArray

protected int[][] keyColumnsArray

rowIntComparator

protected com.klg.jclass.util.treetable.TreeWithSortableChildren.RowIntComparator rowIntComparator

nodeChildIndexMaps

protected HashMap nodeChildIndexMaps

autoSort

protected boolean autoSort

needsResorting

protected boolean needsResorting

needsReordering

protected boolean needsReordering

listeners

protected com.klg.jclass.util.JCListenerList listeners

l

protected com.klg.jclass.util.treetable.TreeWithSortableChildren.Listener l
Constructor Detail

TreeWithSortableChildren

public TreeWithSortableChildren(com.klg.jclass.util.treetable.JCTreeTableModel treetable,
                                com.klg.jclass.util.swing.JCRowComparator comparator)
Constructs a JCTreeTableModel that wraps a given instance of a JCTreeTableModel and provides a sorted mapping of the children for any given leaf node. The sort order is defined by the configurable Comparator property.


TreeWithSortableChildren

public TreeWithSortableChildren(com.klg.jclass.util.treetable.JCTreeTableModel treetable)
Constructs a JCTreeTableModel that that wraps a given instance of a JCTreeTableModel and provides a sorted mapping of the children for any given leaf node. The sort order is defined by the configurable Comparator property.

Method Detail

getModel

public com.klg.jclass.util.treetable.JCTreeTableModel getModel()
Returns the JCTreeTable model this model wraps


setModel

public void setModel(com.klg.jclass.util.treetable.JCTreeTableModel newModel)
Sets the tree table model wrapped by this model.


getAutoSort

public boolean getAutoSort()
Returns whether the data is automatically sorted when it changes according the current comparator.

Specified by:
getAutoSort in interface JCRowSortModel
Returns:
whether data is automatically sorted

setAutoSort

public void setAutoSort(boolean autoSort)
Sets whether the data should be automatically sorted when it changes.

Specified by:
setAutoSort in interface JCRowSortModel
Parameters:
autoSort -

setKeyColumns

public void setKeyColumns(int column,
                          int[] keyColumns)
Sets the key columns used to sort the table model when clicking on a specified column.

Specified by:
setKeyColumns in interface JCRowSortModel
Parameters:
column - index of column in TableModel
keyColumns - columns to use as keys to sort when sorting on the specified column.

getKeyColumns

public int[] getKeyColumns(int column)
Returns the key columns used to sort the table model when clicking on a specified column. If the user has not set the key columns, this returns an array of length 1 with the specified column as the only member.

Specified by:
getKeyColumns in interface JCRowSortModel
Parameters:
column -
Returns:
key columns

isDataSorted

public boolean isDataSorted()
Returns whether or not the data set is currently sorted.

Specified by:
isDataSorted in interface JCRowSortModel
Returns:
whether or not the data set is currently sorted

setDataSorted

public void setDataSorted(boolean sorted)
Sorts data by current column if set to true and the data needs sorting; or, if set to false, it returns the data in its native unsorted state.

Specified by:
setDataSorted in interface JCRowSortModel
Parameters:
sorted -

getSortColumn

public int getSortColumn()
Gets the sorting column. This should return -1 if the data is unsorted.

Specified by:
getSortColumn in interface JCRowSortModel
Returns:
sorting column

setSortColumn

public void setSortColumn(int column)
Sets the column to use the next time a sort is performed.

Specified by:
setSortColumn in interface JCRowSortModel
Parameters:
column - only valid column indicies are allowed

getSortOrder

public int getSortOrder()
Gets the sorting order to use the next time a sort is performed.

Specified by:
getSortOrder in interface JCRowSortModel
Returns:
sorting order

setSortOrder

public void setSortOrder(int order)
Sets the sorting order.

Specified by:
setSortOrder in interface JCRowSortModel
Parameters:
order -

toggleSortOrder

public void toggleSortOrder()
Toggles the sorting order.

Specified by:
toggleSortOrder in interface JCRowSortModel

getIndices

protected int[] getIndices(Object parent)
Gets the mapped indices; returns null if unsorted. Sorts children "on the fly" as they are requested and stores the sorted results in a hash table that is thrown away each time a new sort is invoked.


addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Removes the specified treemodel listener.

Specified by:
addTreeModelListener in interface TreeModel

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Removes the specified treemodel listener.

Specified by:
removeTreeModelListener in interface TreeModel

getChild

public Object getChild(Object parent,
                       int index)
Returns the "index"th non-leaf child of this node.

Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(Object parent)
Return the number of children.

Specified by:
getChildCount in interface TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Returns the non-leaf index of this child.

Specified by:
getIndexOfChild in interface TreeModel

getRoot

public Object getRoot()
Returns the root node of the tree.

Specified by:
getRoot in interface TreeModel

isLeaf

public boolean isLeaf(Object node)
Returns whether the child is a leaf.

Specified by:
isLeaf in interface TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Calls the underling trees valueForPathChanged method.

Specified by:
valueForPathChanged in interface TreeModel

getValueAt

public Object getValueAt(Object node,
                         int column)
Returns the value of the specific node and column.

Specified by:
getValueAt in interface JCTreeTableModel
Parameters:
node - the node to be queried
column - the index of the column
Returns:
the value at the given node and column
See Also:
JCTreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int)

isCellEditable

public boolean isCellEditable(Object node,
                              int column)
Returns whether a particular cell is editable given the node and column.

Specified by:
isCellEditable in interface JCTreeTableModel
Parameters:
node - the node to be checked for editabiltily
column - the index of the column
Returns:
whether the cell at the given node and column is editable
See Also:
JCTreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int)

setValueAt

public void setValueAt(Object value,
                       Object node,
                       int column)
Sets the value at a particular node and column.

Specified by:
setValueAt in interface JCTreeTableModel
Parameters:
value - the new value
node - the node whose value is to be changed
column - the column whose value is to be changed
See Also:
JCTreeTableModel.getValueAt(java.lang.Object, int), JCTreeTableModel.isCellEditable(java.lang.Object, int)

getColumnClass

public Class getColumnClass(int column)
Returns the class of the given column index.

Specified by:
getColumnClass in interface JCTreeTableModel
Parameters:
column - the index of the column
Returns:
the class used to determine a renderer and editor for the column

getColumnCount

public int getColumnCount()
Returns the number of columns.

Specified by:
getColumnCount in interface JCTreeTableModel
Returns:
the current number of columns

getColumnName

public String getColumnName(int column)
Returns the column name for the given column index.

Specified by:
getColumnName in interface JCTreeTableModel
Parameters:
column - the index of the column whose name is required
Returns:
the name of the column at the given column index

getNode

protected static Object getNode(TreePath path)
Given a TreePath, this method returns the last component or "node" of the TreePath.


postTreeStructureChanged

protected void postTreeStructureChanged(TreeModelEvent event)

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.

Parameters:
event - The event generated by the change. If a null event is passed, an "all changed" event is generated.

postTreeStructureChanged

protected void postTreeStructureChanged(TreeModelEvent event,
                                        boolean external)

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.

Parameters:
event - The event generated by the change. If a null event is passed, an "all changed" event is generated.
external - If true, this method is called externally thru the Listener. In this case we need to reset the internal index maps. If false, this method is called internally and is meant to inform listeners of an internal change. In this case the index maps are already updated and should not be reset.

Copyright © 2004 Quest Software Inc..
All rights reserved.