Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.treetable
Class TreeTableModelMask

java.lang.Object
  extended by com.citra.treetable.AbstractTreeTableModel
      extended by com.citra.treetable.MutableTreeTableModel
          extended by com.citra.treetable.ComparableTreeTableModel
              extended by com.citra.treetable.DefaultMutableTreeTableModel
                  extended by com.citra.treetable.TreeTableModelMask
All Implemented Interfaces:
ReorderListener, ReorderModel, TreeTableModel, Serializable, EventListener, TreeModelListener, TreeModel
Direct Known Subclasses:
TreeTableColumnModelMask

public class TreeTableModelMask
extends DefaultMutableTreeTableModel
implements TreeModelListener, ReorderListener

TreeTableModelMask masks a TreeTableModel so that different values for a node can be returned, depending on the values of the underlying model. By default, TreeTableModelMask's behaviour and values are exactly the same as the underlying model. Usually, developers should subclass it and override the getValueAt method, in order to return a different value.

See Also:
Serialized Form

Field Summary
protected  TreeTableModel model
          the underlying treetable model
 
Fields inherited from class com.citra.treetable.DefaultMutableTreeTableModel
editable
 
Fields inherited from class com.citra.treetable.ComparableTreeTableModel
addChildForGroup, comparators, defaultComparatorsByColumnClass
 
Fields inherited from class com.citra.treetable.MutableTreeTableModel
classes, columns
 
Fields inherited from class com.citra.treetable.AbstractTreeTableModel
listenerList, root
 
Fields inherited from interface com.citra.treetable.TreeTableModel
CHANGE_COLUMN_SOURCE
 
Constructor Summary
TreeTableModelMask(TreeTableModel model)
          Constructs a TreeTableModelMask.
 
Method Summary
 Object createMaskedNode(Object node)
          Creates and returns a new node masking node.
 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.
 Class getColumnClass(int column)
          Returns the class of all the cells in the column.
 int getColumnCount()
          Returns the number of columns.
 String getColumnName(int column)
          Returns the name of the column at columnIndex as it will be displayed by the table
 Object getMaskedNode(Object node)
          Returns the enclosed node of the underlying model, that node represents.
 TreeTableModel getTreeTableModel()
          Returns the underlying treetable model.
 Object getValueAt(Object node, int column)
          Returns the value to be displayed for node, at column index column.
 void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
          Inserts a node at a specific location index in its parents children.
 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.
 boolean isMasking(Object node)
          Determines whether a node of the model is masking a node belonging to the underlying model.
protected  boolean nodeEquals(Object node1, Object node2)
          Checks for equality between two masking nodes.
protected  int nodeHashCode(Object node)
          Returns the hashcode for the masking node.
protected  void nodePrepared(Object parent)
          This method is called after a masked node encapsulating an underlying node has been prepared.
 void rowsReordered(ReorderEvent e)
          Called whenever the rows of a JTable have been restructured.
 void setMaskedNode(Object node, Object mask)
          Assigns a new masked node.
 void setTreeTableModel(TreeTableModel model)
          Assigns a new underlying treetable model
 void treeNodesChanged(TreeModelEvent e)
          

Invoked after a node (or a set of siblings) has changed in some way.

 void treeNodesInserted(TreeModelEvent e)
          

Invoked after nodes have been inserted into the tree.

 void treeNodesRemoved(TreeModelEvent e)
          

Invoked after nodes have been removed from the tree.

 void treeStructureChanged(TreeModelEvent e)
          

Invoked after the tree has drastically changed structure from a given node down.

 
Methods inherited from class com.citra.treetable.DefaultMutableTreeTableModel
createLeafNode, createNonLeafNode, getEditable, isCellEditable, replicateLeafNode, setEditable, setValueAt
 
Methods inherited from class com.citra.treetable.ComparableTreeTableModel
add, add, addNode, addRowComparator, clearComparators, comparatorsChanged, createDefaultComparators, findTreeNode, getAddChildForGroup, getDefaultComparator, getRowComparator, getRowComparators, getRowComparatorSize, insertRowComparator, loadComparators, refreshComparators, removeRowComparator, removeRowComparator, saveComparators, setAddChildForGroup, setDefaultComparator, setRowComparator
 
Methods inherited from class com.citra.treetable.MutableTreeTableModel
addColumn, addColumn, addReorderListener, clear, fireRowsMapped, fireRowsReordered, getChild, getIndexOfChild, getPathToRoot, getPathToRoot, moveNode, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, removeNodeFromParent, removeReorderListener, setColumnClasses, setColumnNames, valueForPathChanged
 
Methods inherited from class com.citra.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
 

Field Detail

model

protected TreeTableModel model
the underlying treetable model

Constructor Detail

TreeTableModelMask

public TreeTableModelMask(TreeTableModel model)
Constructs a TreeTableModelMask.

Method Detail

createMaskedNode

public Object createMaskedNode(Object node)
Creates and returns a new node masking node.

Parameters:
node - the node to mask
Returns:
the masked node

nodeEquals

protected boolean nodeEquals(Object node1,
                             Object node2)
Checks for equality between two masking nodes.

Parameters:
node1 - the first masking node
node2 - the second masking node
Returns:
true, if the two nodes are equal, false otherwise

nodeHashCode

protected int nodeHashCode(Object node)
Returns the hashcode for the masking node.

Parameters:
node - the masking node
Returns:
the masking's node hashcode

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

getColumnClass

public Class getColumnClass(int column)
Returns the class of all the cells in the column.

Specified by:
getColumnClass in interface TreeTableModel
Overrides:
getColumnClass in class MutableTreeTableModel
Parameters:
column - the index of the column
Returns:
the class of all the cells in the column.

getColumnCount

public int getColumnCount()
Returns the number of columns.

Specified by:
getColumnCount in interface TreeTableModel
Overrides:
getColumnCount in class MutableTreeTableModel
Returns:
the number of columns.

getColumnName

public String getColumnName(int column)
Returns the name of the column at columnIndex as it will be displayed by the table

Specified by:
getColumnName in interface TreeTableModel
Overrides:
getColumnName in class MutableTreeTableModel
Parameters:
column - the index of the column
Returns:
the name of the column

getMaskedNode

public Object getMaskedNode(Object node)
Returns the enclosed node of the underlying model, that node represents.

Parameters:
node - a node of TreeTableModelMask
Returns:
the masked node - referring to a node of the underlying model

getTreeTableModel

public TreeTableModel getTreeTableModel()
Returns the underlying treetable model.

Returns:
the underlying 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
Overrides:
getValueAt in class DefaultMutableTreeTableModel
Parameters:
node - the node to query
column - the column index
Returns:
the value

insertNodeInto

public void insertNodeInto(MutableTreeNode newChild,
                           MutableTreeNode parent,
                           int index)
Inserts a node at a specific location index in its parents children. The appropriate event is also created.

Overrides:
insertNodeInto in class MutableTreeTableModel
Parameters:
newChild - the node to insert
parent - the parent node to remove node from
index - the location in the parent node's childrens

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
Overrides:
isLeaf in class MutableTreeTableModel
Parameters:
node - a node in the tree, obtained from this data source
Returns:
true if node is a leaf

nodePrepared

protected void nodePrepared(Object parent)
This method is called after a masked node encapsulating an underlying node has been prepared.

Parameters:
parent - the masked node that was prepared

rowsReordered

public void rowsReordered(ReorderEvent e)
Called whenever the rows of a JTable have been restructured.

Specified by:
rowsReordered in interface ReorderListener
Parameters:
e - the ReorderEvent object

setMaskedNode

public void setMaskedNode(Object node,
                          Object mask)
Assigns a new masked node.

Parameters:
node - the node to mask
mask - the masked node to set

setTreeTableModel

public void setTreeTableModel(TreeTableModel model)
Assigns a new underlying treetable model

Parameters:
model - the new treetablemodel to assign

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

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

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

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

isMasking

public boolean isMasking(Object node)
Determines whether a node of the model is masking a node belonging to the underlying model. A value of false implies that the node is owned by the mask model, with no connection to any nodes of the underlying model whatsoever.

Parameters:
node - the masking node
Returns:
true, if the node is masking an underlying node, false otherwise

Copyright © 2011 Citra Technologies. All Rights Reserved.