Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.treetable
Class DefaultFilterTreeTableModel

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.DefaultFilterTreeTableModel
All Implemented Interfaces:
ReorderListener, CacheableTreeTableModel, ReorderModel, FilterTreeTableModel, TreeTableModel, Serializable, EventListener, TreeModelListener, TreeModel

public class DefaultFilterTreeTableModel
extends TreeTableModelMap
implements FilterTreeTableModel

DefaultFilterTreeTableModel provides filtering capabilities to a TreeTableModel. This class wraps around a TreeTableModel and uses an internal FilterTableModel instance to filter each group row of the model. You can use the filter tablemodel to control the filtering.

See Also:
Serialized Form

Field Summary
static int AND_FILTER
          the mode which defines an AND combination of a node and level filter
protected  TableFilter defaultFilter
          the current default filter
protected  EventListenerList filterListenerList
          the list of filter treemodel listeners.
protected  int filterMode
          the current filter mode
static int LEVEL_FILTER
          the mode which defines a single filter assigned per level
static int NODE_FILTER
          the mode which defines a single filter assigned per node
static int OR_FILTER
          the mode which defines an OR combination of a node and level filter
 
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
DefaultFilterTreeTableModel(TreeTableModel treeTableModel)
          Constructs a DefaultFilterTreeTableModel.
 
Method Summary
 void addFilterTreeTableModelListener(FilterTreeTableModelListener l)
          Adds a FilterTreeTableModelListener that is notified each time filters are added or removed.
 void clear()
          Clears the model of any filtering performed.
 void clearFilters()
          Removes all assigned filters.
protected  void fireApplyLevelFilter(FilterTreeTableModelEvent e)
          Notifies listeners that a filter has been assigned at a node level.
protected  void fireApplyNodeFilter(FilterTreeTableModelEvent e)
          Notifies listeners that a filter has been assigned at a node.
protected  void fireClearFilters()
          Notifies listeners that all filters have been removed.
 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 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.
 TableFilter getDefaultFilter()
          Determines the default filter.
 TableFilter getFilterAtLevel(int level)
          Retrieves the TableFilter that is assigned at the node level identified by level.
 TableFilter getFilterAtNode(Object node)
          Retrieves the TableFilter that is assigned for the node identified by node.
 int getFilterMode()
          Determines the filtering mode.
 FilterTableModel getFilterTableModel()
          Returns the internal filter tablemodel instance.
 int getIndexOfChild(Object parent, Object child)
          Returns the index of child in parent. If parent is null or child is null, returns -1.
 int getLevelForNode(Object node)
          Determines the level of the supplied node.
 int[] getMappedIndexes(Object node)
          Returns an array representing how the nodes' children have been transformed.
 TreeTableModel getUnfilteredTreeTableModel()
          Retrieves the TreeTableModel that holds the unfiltered data.
 void removeFilterTreeTableModelListener(FilterTreeTableModelListener l)
          Removes a FilterTreeTableModelListener that is notified each time filters are added or removed.
 TableFilter retrieveFilter(Object node)
          Determines the table filter to use for the node identified by node.
 void setDefaultFilter(TableFilter newDefaultFilter)
          Assigns a new default filter.
 void setFilterAtLevel(TableFilter filter, int level)
          Assigns a TableFilter at the node level identified by level.
 void setFilterAtNode(TableFilter filter, Object node)
          Assigns a TableFilter for the node identified by node.
 void setFilterMode(int filterMode)
          Assigns the filtering mode.
 boolean shouldFilter(Object node)
          Determines on which occasions the filter treetable model should apply the filter.
 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
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, getRoot, isLeaf, removeTreeModelListener, valueForPathChanged
 

Field Detail

defaultFilter

protected TableFilter defaultFilter
the current default filter


filterMode

protected int filterMode
the current filter mode


NODE_FILTER

public static final int NODE_FILTER
the mode which defines a single filter assigned per node

See Also:
Constant Field Values

LEVEL_FILTER

public static final int LEVEL_FILTER
the mode which defines a single filter assigned per level

See Also:
Constant Field Values

AND_FILTER

public static final int AND_FILTER
the mode which defines an AND combination of a node and level filter

See Also:
Constant Field Values

OR_FILTER

public static final int OR_FILTER
the mode which defines an OR combination of a node and level filter

See Also:
Constant Field Values

filterListenerList

protected EventListenerList filterListenerList
the list of filter treemodel listeners.

Constructor Detail

DefaultFilterTreeTableModel

public DefaultFilterTreeTableModel(TreeTableModel treeTableModel)
Constructs a DefaultFilterTreeTableModel.

Method Detail

addFilterTreeTableModelListener

public void addFilterTreeTableModelListener(FilterTreeTableModelListener l)
Adds a FilterTreeTableModelListener that is notified each time filters are added or removed.

Specified by:
addFilterTreeTableModelListener in interface FilterTreeTableModel
Parameters:
l - the listener to add

clearFilters

public void clearFilters()
Removes all assigned filters.

Specified by:
clearFilters in interface FilterTreeTableModel

fireApplyLevelFilter

protected void fireApplyLevelFilter(FilterTreeTableModelEvent e)
Notifies listeners that a filter has been assigned at a node level.

Parameters:
e - the event

fireApplyNodeFilter

protected void fireApplyNodeFilter(FilterTreeTableModelEvent e)
Notifies listeners that a filter has been assigned at a node.

Parameters:
e - the event

fireClearFilters

protected void fireClearFilters()
Notifies listeners that all filters have been removed.


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

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
Overrides:
getChildCount in class TreeModelMap
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the number of children of the node parent

getDefaultFilter

public TableFilter getDefaultFilter()
Determines the default filter. Having a default filter will override any filters that were previously assigned with the setFilterAtLevel(com.sciapp.filter.TableFilter, int) and setFilterAtNode(com.sciapp.filter.TableFilter, java.lang.Object) methods.

Returns:
the default filter assigned or null if there is no default filter

getFilterAtLevel

public TableFilter getFilterAtLevel(int level)
Retrieves the TableFilter that is assigned at the node level identified by level.

Specified by:
getFilterAtLevel in interface FilterTreeTableModel
Returns:
the table filter for level

getFilterAtNode

public TableFilter getFilterAtNode(Object node)
Retrieves the TableFilter that is assigned for the node identified by node.

Specified by:
getFilterAtNode in interface FilterTreeTableModel
Returns:
the table filter for node

getFilterMode

public int getFilterMode()
Determines the filtering mode. This value is taken into account in the retrieveFilter method.

The mode can be:
NODE_FILTER: single filter assigned per node
LEVEL_FILTER: single filter assigned per level
AND_FILTER: AND combination of node and level filters
OR_FILTER: OR combination of node and level filters

Returns:
the filter mode

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

getLevelForNode

public int getLevelForNode(Object node)
Determines the level of the supplied node.

Parameters:
node - the node we want to retrieve the level for
Returns:
the node's level

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

getUnfilteredTreeTableModel

public TreeTableModel getUnfilteredTreeTableModel()
Retrieves the TreeTableModel that holds the unfiltered data.

Specified by:
getUnfilteredTreeTableModel in interface FilterTreeTableModel
Returns:
the unfiltered treetable model

removeFilterTreeTableModelListener

public void removeFilterTreeTableModelListener(FilterTreeTableModelListener l)
Removes a FilterTreeTableModelListener that is notified each time filters are added or removed.

Specified by:
removeFilterTreeTableModelListener in interface FilterTreeTableModel
Parameters:
l - the listener to remove

retrieveFilter

public TableFilter retrieveFilter(Object node)
Determines the table filter to use for the node identified by node.

Specified by:
retrieveFilter in interface FilterTreeTableModel
Parameters:
node - the node for which the filter is evaluated
Returns:
the table filter

setDefaultFilter

public void setDefaultFilter(TableFilter newDefaultFilter)
Assigns a new default filter. Having a default filter will override any filters that were previously assigned with the setFilterAtLevel(com.sciapp.filter.TableFilter, int) and setFilterAtNode(com.sciapp.filter.TableFilter, java.lang.Object) methods.

Parameters:
newDefaultFilter - the default filter to assign

setFilterAtLevel

public void setFilterAtLevel(TableFilter filter,
                             int level)
Assigns a TableFilter at the node level identified by level.

Specified by:
setFilterAtLevel in interface FilterTreeTableModel
Parameters:
filter - the table filter to assign
level - the level to assign the filter at

setFilterAtNode

public void setFilterAtNode(TableFilter filter,
                            Object node)
Assigns a TableFilter for the node identified by node.

Specified by:
setFilterAtNode in interface FilterTreeTableModel
Parameters:
filter - the table filter to assign
node - the node for which the filter is assigned

setFilterMode

public void setFilterMode(int filterMode)
Assigns the filtering mode. This value is taken into account in the retrieveFilter method.

The mode can be:
NODE_FILTER: single filter assigned per node
LEVEL_FILTER: single filter assigned per level
AND_FILTER: AND combination of node and level filters
OR_FILTER: OR combination of node and level filters

Parameters:
filterMode - the filter mode

shouldFilter

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

For example, for not filtering the root node:

return node != getRoot();

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

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

To allow filtering 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 filters currently installed in the filter tablemodel instance into consideration in your evaluation of this method:

TableFilter filter = getFilterTableModel().getTableFilter();
if (filter != null) {
int column = filter.getColumn();
if (column == 3 && node != getRoot()) return false;
}
return true;

Parameters:
node - the affected node
Returns:
true if the filter 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

clear

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


Copyright © 2005 Scientific Applications. All Rights Reserved.