Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.treetable
Class DefaultSortTreeTableModel

java.lang.Object
  extended by com.sciapp.treetable.AbstractTreeTableModel
      extended by com.sciapp.treetable.TreeModelMap
          extended by com.sciapp.treetable.TreeTableModelMap
              extended by com.sciapp.treetable.DefaultSortTreeTableModel
All Implemented Interfaces:
ReorderListener, CacheableTreeTableModel, ReorderModel, SortTreeTableModel, TreeTableModel, Serializable, EventListener, TreeModelListener, TreeModel

public class DefaultSortTreeTableModel
extends TreeTableModelMap
implements SortTreeTableModel

DefaultSortTreeTableModel provides sorting capabilities to a TreeTableModel. This class wraps around a TreeTableModel and uses an internal SortTableModel instance to sort each group row of the model. You can use the sort tablemodel to control the sorting.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.sciapp.treetable.TreeTableModelMap
treeTableModel
 
Fields inherited from class com.sciapp.treetable.TreeModelMap
treeModel
 
Fields inherited from class com.sciapp.treetable.AbstractTreeTableModel
listenerList, root
 
Fields inherited from interface com.sciapp.treetable.TreeTableModel
CHANGE_COLUMN_SOURCE
 
Constructor Summary
DefaultSortTreeTableModel(TreeTableModel treeTableModel)
          Constructs a DefaultSortTreeTableModel.
 
Method Summary
 void clear()
          Clears the model of any sorting performed.
 Object getChild(Object parent, int index)
          Returns the child of parent at index index in the parent's child array. parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount(parent)).
 int getIndexOfChild(Object parent, Object child)
          Returns the index of child in parent. If parent is null or child is null, returns -1.
 int[] getMappedIndexes(Object node)
          Returns an array representing how the nodes' children have been transformed.
 SortTableModel getSortTableModel()
          Returns the internal sort tablemodel instance.
 boolean shouldSort(Object node)
          Determines on which occasions the sort treetable model should sort the supplied node.
 void treeNodesChanged(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.

To indicate the root has changed, childIndices and children will be null.

Use e.getPath() to get the parent of the changed node(s). e.getChildIndices() returns the index(es) of the changed node(s).

 void treeNodesInserted(TreeModelEvent e)
          

Invoked after nodes have been inserted into the tree.

Use e.getPath() to get the parent of the new node(s). e.getChildIndices() returns the index(es) of the new node(s) in ascending order.

 void treeNodesRemoved(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.

Use e.getPath() to get the former parent of the deleted node(s). e.getChildIndices() returns, in ascending order, the index(es) the node(s) had before being deleted.

 void treeStructureChanged(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.

Use e.getPath() to get the path to the node. e.getChildIndices() returns null.

 
Methods inherited from class com.sciapp.treetable.TreeTableModelMap
addReorderListener, fireRowsMapped, fireRowsReordered, getColumnClass, getColumnCount, getColumnName, getInnerTreeTableModel, getTreeTableModel, getUncachedChildren, getUncachedGroupCount, getUncachedGroups, getValueAt, isAggregate, isCellEditable, isCountCached, isFooter, isHeader, isRangedModel, isValueCached, removeReorderListener, rowsReordered, setTreeModel, setTreeTableModel, setValueAt
 
Methods inherited from class com.sciapp.treetable.TreeModelMap
getChildCount, getPathToRoot, getPathToRoot, getRoot, getTreeModel, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, valueForPathChanged
 
Methods inherited from class com.sciapp.treetable.AbstractTreeTableModel
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, fireTreeTableStructureChanged, fireTreeTableStructureChanged, removeTreeModelListener, setRoot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sciapp.treetable.TreeTableModel
getColumnClass, getColumnCount, getColumnName, getValueAt, isAggregate, isCellEditable, isFooter, isHeader, setValueAt
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, getChildCount, getRoot, isLeaf, removeTreeModelListener, valueForPathChanged
 

Constructor Detail

DefaultSortTreeTableModel

public DefaultSortTreeTableModel(TreeTableModel treeTableModel)
Constructs a DefaultSortTreeTableModel.

Method Detail

clear

public void clear()
Clears the model of any sorting performed.


getChild

public Object getChild(Object parent,
                       int index)
Returns the child of parent at index index in the parent's child array. parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount(parent)).

Specified by:
getChild in interface TreeModel
Overrides:
getChild in class TreeModelMap
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Returns the index of child in parent. If parent is null or child is null, returns -1.

Specified by:
getIndexOfChild in interface TreeModel
Overrides:
getIndexOfChild in class TreeModelMap
Parameters:
parent - a note in the tree, obtained from this data source
child - the node we are interested in
Returns:
the index of the child in the parent, or -1 if either child or parent are null

getMappedIndexes

public int[] getMappedIndexes(Object node)
Returns an array representing how the nodes' children have been transformed.

Overrides:
getMappedIndexes in class TreeTableModelMap
Parameters:
node - the tree node
Returns:
an array of integers showing how the nodes children transform to the original

getSortTableModel

public SortTableModel getSortTableModel()
Returns the internal sort tablemodel instance.

Returns:
the sort table model instance.

shouldSort

public boolean shouldSort(Object node)
Determines on which occasions the sort treetable model should sort the supplied node. By default, it returns true, implying that all nodes should be sorted.
You can override this method to define your own custom behaviour.

For example, for not sorting the root node:

return node != getRoot();

For not sorting the root node and its direct children nodes:

return node != getRoot() && super.getIndexOfChild(getRoot(), node) == -1;

To allow sorting only at a specific node level, and supposing node is a DefaultMutableTreeNode:

DefaultMutableTreeNode n = (DefaultMutableTreeNode) node;
int level = n.getLevel();
return level == 3;

You can also take the sort states currently installed in the sort tablemodel instance into consideration in your evaluation of this method:

SortState[] sortStates = getSortTableModel().getSortStates();
if (sortStates != null && sortStates.length > 0) {
int field = sortStates[0].getField();
if (field == 3 && node != getRoot()) return false;
}
return true;

Parameters:
node - the affected node
Returns:
true if the sorting should be applied

treeNodesChanged

public void treeNodesChanged(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.

To indicate the root has changed, childIndices and children will be null.

Use e.getPath() to get the parent of the changed node(s). e.getChildIndices() returns the index(es) of the changed node(s).

Specified by:
treeNodesChanged in interface TreeModelListener
Overrides:
treeNodesChanged in class TreeModelMap

treeNodesInserted

public void treeNodesInserted(TreeModelEvent e)

Invoked after nodes have been inserted into the tree.

Use e.getPath() to get the parent of the new node(s). e.getChildIndices() returns the index(es) of the new node(s) in ascending order.

Specified by:
treeNodesInserted in interface TreeModelListener
Overrides:
treeNodesInserted in class TreeModelMap

treeNodesRemoved

public void treeNodesRemoved(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.

Use e.getPath() to get the former parent of the deleted node(s). e.getChildIndices() returns, in ascending order, the index(es) the node(s) had before being deleted.

Specified by:
treeNodesRemoved in interface TreeModelListener
Overrides:
treeNodesRemoved in class TreeModelMap

treeStructureChanged

public void treeStructureChanged(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.

Use e.getPath() to get the path to the node. e.getChildIndices() returns null.

Specified by:
treeStructureChanged in interface TreeModelListener
Overrides:
treeStructureChanged in class TreeModelMap

Copyright © 2005 Scientific Applications. All Rights Reserved.