Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.treetable.db
Class AbstractDatabaseTreeTableModel

java.lang.Object
  extended by com.sciapp.treetable.AbstractTreeTableModel
      extended by com.sciapp.treetable.db.AbstractDatabaseTreeTableModel
All Implemented Interfaces:
CacheableTreeTableModel, DatabaseTreeTableModel, TreeTableModel, Serializable, TreeModel
Direct Known Subclasses:
DefaultDatabaseTreeTableModel

public abstract class AbstractDatabaseTreeTableModel
extends AbstractTreeTableModel
implements DatabaseTreeTableModel, CacheableTreeTableModel

AbstractDatabaseTreeTableModel represents a sortable and filterable database treetable model that is also cached. Sorting is provided via an internal SortTableModel instance, whereas filtering through an internal FilterTableModel instance. Finally, caching is handled by a TreeTableCache object.

See Also:
Serialized Form

Nested Class Summary
 class AbstractDatabaseTreeTableModel.DefaultTreeTableAggregateRowCache
          This class represents a cache object for aggregate rows.
 
Field Summary
protected  TreeTableCache aggregateRowCache
          the cache for aggregate rows
protected  DatabaseAggregator aggregator
          the default database aggregator
protected  TreeTableCache cache
          the cache for NON-aggregate rows
protected  FilterTableModel dbFilter
          the internal filter tablemodel instance
protected  SortTableModel dbSorter
          the internal sort tablemodel instance
 
Fields inherited from class com.sciapp.treetable.AbstractTreeTableModel
listenerList, root
 
Fields inherited from interface com.sciapp.treetable.TreeTableModel
CHANGE_COLUMN_SOURCE
 
Fields inherited from interface com.sciapp.treetable.TreeTableModel
CHANGE_COLUMN_SOURCE
 
Constructor Summary
AbstractDatabaseTreeTableModel(Object root, TreeTableCache cache)
          Constructs an AbstractDatabaseTableModel.
 
Method Summary
protected abstract  DatabaseAggregator createDefaultAggregator()
          Creates and returns the default aggregator.
protected abstract  TreeTableRow createTableRow(TreeTableRow parent, int index)
          Creates and returns a TreeTableRow for the node parent at its child index identified by index.
 DatabaseAggregator getAggregator()
          Returns the default database aggregator.
 Object getChild(Object parent, int index)
          Returns the child of parent at index index in the parent's child array.
 int getChildCount(Object parent)
          Returns the number of children of parent.
 FilterTableModel getFilterTableModel()
          Returns the internal filter tablemodel instance.
 int getIndexOfChild(Object parent, Object child)
          Returns the index of child in parent.
 TreeNode[] getPathToRoot(TreeNode aNode)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
protected  TreeNode[] getPathToRoot(TreeNode aNode, int depth)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
 SortTableModel getSortTableModel()
          Returns the internal sort tablemodel instance.
 List getUncachedChildren(Object parent, int from, int to)
          Retrieves the leaf rows from the treetable model by specifying a row interval.
 int getUncachedGroupCount(Object node)
          Retrieves the children count for node.
 List getUncachedGroups(Object node, int from, int to)
          Retrieves the branch rows from the treetable model by specifying a row interval.
 Object getValueAt(Object node, int column)
          Returns the value to be displayed for node, at column index column.
 boolean isCellEditable(Object node, int column)
          Returns true if node at columnIndex is editable.
 boolean isCountCached(Object node)
          Determines whether the children count for node has been evaluated.
 boolean isLeaf(Object node)
          Returns true if node is a leaf.
 boolean isRangedModel()
          Determines whether the cache model can fetch data in ranges.
 boolean isValueCached(Object node, int column)
          Determines whether the value for node at index column has been evaluated.
 void nodeChanged(TreeNode node)
          This method should be invoked when the representation of node in the tree has changed.
 void nodesChanged(TreeNode node, int[] childIndices)
          This method should be invoked when the representation of the children identified by childIndices in the tree has changed.
 void nodeStructureChanged(TreeNode node)
          This method should be invoked when the children of node and its children children have completely changed.
 void nodesWereInserted(TreeNode node, int[] childIndices)
          This method should be invoked when some TreeNodes were inserted into node.
 void nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren)
          This method should be invoked when some TreeNodes were removed from node.
abstract  void orderByClause()
          This method is called whenever sorting is requested.
protected  Object retrieveFromDB(ResultSet rs, int column)
          Performs the binding from a database value to a java value using the supplied resultset and the column's index, and returns the result.
protected  Object retrieveFromDB(ResultSet rs, int column, Class c)
          Performs the binding from a database value to a java value using the supplied resultset and the column's class, and returns the result.
 void setAggregator(DatabaseAggregator aggregator)
          Sets the default database aggregator.
 void setCache(TreeTableCache newCache)
          Assigns a new cache for the NON-aggregate nodes.
 void setValueAt(Object aValue, Object node, int column)
          Sets the value for node at columnIndex to aValue.
 void valueForPathChanged(TreePath path, Object newValue)
          Messaged when the user has altered the value for the item identified by path to newValue.
abstract  void whereClause()
          This method is called whenever filtering is requested.
 
Methods inherited from class com.sciapp.treetable.AbstractTreeTableModel
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, fireTreeTableStructureChanged, fireTreeTableStructureChanged, getRoot, isAggregate, isFooter, isHeader, 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.db.DatabaseTreeTableModel
fetchChildren, fetchGroupCount, fetchGroups
 
Methods inherited from interface com.sciapp.treetable.TreeTableModel
getColumnClass, getColumnCount, getColumnName, isAggregate, isFooter, isHeader
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, getRoot, removeTreeModelListener
 
Methods inherited from interface com.sciapp.treetable.TreeTableModel
getColumnClass, getColumnCount, getColumnName, isAggregate, isFooter, isHeader
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, getRoot, removeTreeModelListener
 

Field Detail

dbSorter

protected SortTableModel dbSorter
the internal sort tablemodel instance


dbFilter

protected FilterTableModel dbFilter
the internal filter tablemodel instance


cache

protected TreeTableCache cache
the cache for NON-aggregate rows


aggregateRowCache

protected TreeTableCache aggregateRowCache
the cache for aggregate rows


aggregator

protected DatabaseAggregator aggregator
the default database aggregator

Constructor Detail

AbstractDatabaseTreeTableModel

public AbstractDatabaseTreeTableModel(Object root,
                                      TreeTableCache cache)
Constructs an AbstractDatabaseTableModel.

Method Detail

createDefaultAggregator

protected abstract DatabaseAggregator createDefaultAggregator()
Creates and returns the default aggregator. The aggregator will be used to retrieve values for the aggregate (DatabaseHeaderRows) rows of the model.

Returns:
the default database aggregator.

createTableRow

protected abstract TreeTableRow createTableRow(TreeTableRow parent,
                                               int index)
Creates and returns a TreeTableRow for the node parent at its child index identified by index.

Parameters:
parent - the parent node
index - the child index of parent that we want returned
Returns:
the child of parent at index

getAggregator

public DatabaseAggregator getAggregator()
Returns the default database aggregator.

Returns:
the default database aggregator.

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
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

getChildCount

public int getChildCount(Object parent)
Returns the number of children of parent. Returns 0 if the node is a leaf or if it has no children. parent must be a node previously obtained from this data source.

Specified by:
getChildCount in interface TreeModel
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the number of children of the node parent

getFilterTableModel

public FilterTableModel getFilterTableModel()
Returns the internal filter tablemodel instance.

Returns:
the filter table model instance.

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
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

getPathToRoot

public TreeNode[] getPathToRoot(TreeNode aNode)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.


getPathToRoot

protected TreeNode[] getPathToRoot(TreeNode aNode,
                                   int depth)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.


getSortTableModel

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

Returns:
the sort table model instance.

getUncachedChildren

public List getUncachedChildren(Object parent,
                                int from,
                                int to)
Retrieves the leaf rows from the treetable model by specifying a row interval. The following condition must be true: from >= to. The List returned must contain the row elements starting at from. However, the List may contain less elements than those specified in the range.

Specified by:
getUncachedChildren in interface CacheableTreeTableModel
Parameters:
parent - the parent node
from - the starting row
to - the ending row
Returns:
a list of objects, each element of which contains a row from the treetable model

getUncachedGroupCount

public int getUncachedGroupCount(Object node)
Retrieves the children count for node.

Specified by:
getUncachedGroupCount in interface CacheableTreeTableModel
Parameters:
node - the node for which the children count we want to retrieve.
Returns:
the node's children count.

getUncachedGroups

public List getUncachedGroups(Object node,
                              int from,
                              int to)
Retrieves the branch rows from the treetable model by specifying a row interval. The following condition must be true: from >= to. The List returned must contain the row elements starting at from. However, the List may contain less elements than those specified in the range.

Specified by:
getUncachedGroups in interface CacheableTreeTableModel
Parameters:
node - the parent node
from - the starting row
to - the ending row
Returns:
a list of objects, each element of which contains a row from the treetable model

getValueAt

public Object getValueAt(Object node,
                         int column)
Returns the value to be displayed for node, at column index column.

Specified by:
getValueAt in interface TreeTableModel
Parameters:
node - the node to query
column - the column index
Returns:
the value

isCellEditable

public boolean isCellEditable(Object node,
                              int column)
Returns true if node at columnIndex is editable.

Specified by:
isCellEditable in interface TreeTableModel
Parameters:
node - the node to consider
column - the column index
Returns:
true if the node at columnIndex is editable, false otherwise

isCountCached

public boolean isCountCached(Object node)
Determines whether the children count for node has been evaluated.

Specified by:
isCountCached in interface CacheableTreeTableModel
Returns:
true if the node's children count has already been evaluated.

isLeaf

public boolean isLeaf(Object node)
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.

Specified by:
isLeaf in interface TreeModel
Parameters:
node - a node in the tree, obtained from this data source
Returns:
true if node is a leaf

isRangedModel

public boolean isRangedModel()
Determines whether the cache model can fetch data in ranges.

Specified by:
isRangedModel in interface CacheableTreeTableModel
Returns:
true if the cache model can fetch ranged data.

isValueCached

public boolean isValueCached(Object node,
                             int column)
Determines whether the value for node at index column has been evaluated.

Specified by:
isValueCached in interface CacheableTreeTableModel
Parameters:
node - the node to consider
column - the cell's column index
Returns:
true if the value has already been evaluated

nodeChanged

public void nodeChanged(TreeNode node)
This method should be invoked when the representation of node in the tree has changed.


nodesChanged

public void nodesChanged(TreeNode node,
                         int[] childIndices)
This method should be invoked when the representation of the children identified by childIndices in the tree has changed.


nodeStructureChanged

public void nodeStructureChanged(TreeNode node)
This method should be invoked when the children of node and its children children have completely changed. This will post a treeStructureChanged event.


nodesWereInserted

public void nodesWereInserted(TreeNode node,
                              int[] childIndices)
This method should be invoked when some TreeNodes were inserted into node.


nodesWereRemoved

public void nodesWereRemoved(TreeNode node,
                             int[] childIndices,
                             Object[] removedChildren)
This method should be invoked when some TreeNodes were removed from node.


orderByClause

public abstract void orderByClause()
This method is called whenever sorting is requested. Preferrably, this method should reconstruct the sql select query according to the sorting columns of the internal SortTableModel instance.


retrieveFromDB

protected Object retrieveFromDB(ResultSet rs,
                                int column)
                         throws SQLException
Performs the binding from a database value to a java value using the supplied resultset and the column's index, and returns the result. This method will retrieve the class of the column using getColumnClass(column).

Parameters:
rs - the current result set
column - the column being fetched
Returns:
the java object that corresponds to the database value at column
Throws:
SQLException

retrieveFromDB

protected Object retrieveFromDB(ResultSet rs,
                                int column,
                                Class c)
                         throws SQLException
Performs the binding from a database value to a java value using the supplied resultset and the column's class, and returns the result. e.g. for the String.class, the value rs.getString(column + 1) is returned.

Parameters:
rs - the current result set
column - the column being fetched
c - the column's class
Returns:
the java object that corresponds to the database value at column
Throws:
SQLException

setAggregator

public void setAggregator(DatabaseAggregator aggregator)
Sets the default database aggregator.

Parameters:
aggregator - the default database aggregator to assign.

setCache

public void setCache(TreeTableCache newCache)
Assigns a new cache for the NON-aggregate nodes.

Parameters:
newCache - the new cache to assign.

setValueAt

public void setValueAt(Object aValue,
                       Object node,
                       int column)
Sets the value for node at columnIndex to aValue.

Specified by:
setValueAt in interface TreeTableModel
Parameters:
aValue - the new value
node - the node whose value is to be changed
column - the column whose value is to be changed

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.

Specified by:
valueForPathChanged in interface TreeModel
Parameters:
path - path to the node that the user has altered
newValue - the new value from the TreeCellEditor

whereClause

public abstract void whereClause()
This method is called whenever filtering is requested. Preferrably, this method should reconstruct the sql select query according to the table filter of the internal FilterTableModel instance.


Copyright © 2005 Scientific Applications. All Rights Reserved.