ix.iface.ui.table
Class AbstractTreeTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--ix.iface.ui.table.AbstractIXTableModel
              |
              +--ix.iface.ui.table.AbstractTreeTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel, TableMouseListener
Direct Known Subclasses:
ActionTreeTableModel, AgendaItemTableModel

public abstract class AbstractTreeTableModel
extends AbstractIXTableModel
implements TableMouseListener

An abstract class for tree table models. Requires data objects to be TreeTable objects. Creates IXTreeTableNode objects to wrap around the data objects. These IXTreeTableNode objects hold id information (base-object and parent line) and expansion information (indentation of the node and whether it is expanded or not). By default, the children of nodes are not displayed When clicking on the node, the following happens:

Multiple parents are no problem because by default nodes children are not displayed. When a child is displayed more than once, it has a different parent-line and different IXTreeTableNode obejcts are used.

As an example, see ix.iview.table.ActionTreeTableModel

See Also:
Serialized Form

Field Summary
static char CLOSEDC
          the character used to indicate an un-expanded node
static javax.swing.ImageIcon CLOSEDI
           
static java.lang.String imageDir
           
static int INDENT_STEP
          the indentation steps used to indent children
static char LEAFC
          the character used to indicate a leaf (no children)
static javax.swing.ImageIcon LEAFI
           
 java.util.HashMap nodeMap
          A map for looking up a TreeNode for a Object.
protected  java.util.ArrayList nodes
          a collection of IXTreeTableNodes that have been generated
static char OPENC
          the character used to indicate an expanded node
static javax.swing.ImageIcon OPENI
           
 
Fields inherited from class ix.iface.ui.table.AbstractIXTableModel
columnClasses, columnFields, columnNames, objectClass, rows
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
AbstractTreeTableModel()
          Makes an empty model.
AbstractTreeTableModel(javax.swing.tree.TreeNode[] theNodes)
          Makes a model that contains the given nodes at top level.
 
Method Summary
 void addData(java.lang.Object data)
          Adds the given TreeNode object to the table's rows and notifies listeners.
 void addTreeNode(java.lang.Object object, javax.swing.tree.TreeNode tNode)
          Associate the given TreeNode to the given AgendaItem
 void cellClicked(java.awt.event.MouseEvent me, int rowIndex, int columnIndex)
          If the left button was clicked on the tree-column, expand/collapse node.
 void clearData()
          Removes all data objects from the table's rows and notifies listeners.
 void clearTable()
           
 java.lang.String defaultGetNameString(javax.swing.tree.TreeNode node)
          Looks up the value in the first columnField.
protected  void deriveColumnFields()
          Collects usable fields from the objectClass
 void expandNode(IXTreeTableNode eNode, int rowIndex)
          Gathers the node's children and splices them into the table.
 void fireObjectChanged(java.lang.Object o)
          The given object changed - find its tree node, fire that and redo children
abstract  java.lang.Object getCellValueAt(java.lang.Object node, int columnIndex)
          Gets the object's value for the given column index.
abstract  java.lang.String getNameString(javax.swing.tree.TreeNode node)
          Gets the string to use for the tree-column (the name of the node).
 int getObjectRow(java.lang.Object object)
          Gets the row index of the given object
 java.lang.Object getRowNode(int rowIndex)
           
 java.lang.Object getRowObject(int rowIndex)
          Gets the object that is in the given row.
 javax.swing.tree.TreeNode getTreeNode(java.lang.Object object)
          Get the (possibly new) TreeNode that is associlated with the given Object.
 javax.swing.tree.TreeNode getTreeNode(java.lang.Object object, java.util.List parents, int indentation)
           
 java.lang.Object getTreeNodeType(IXTreeTableNode eNode)
          Gets a character or icon to use as a reflection of the node's tree-status.
protected  java.lang.Object getTreeValueAt(IXTreeTableNode eNode)
          Gets the value that indicates the tree-position (indented name).
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Get the value for a cell in the table defined by the parameters.
abstract  IXTreeTableNode makeIXTreeTableNode(java.lang.Object node)
           
 IXTreeTableNode makeIXTreeTableNode(java.lang.Object node, java.util.List parents, int indentation)
          indentation is number of blanks to put in front of node (n*INDENT_STEP)
 void removeData(java.lang.Object data)
          Removes the given TreeNode object from the table's rows and notifies listeners.
 void removeNodes(int number, int place)
          Removes the given number of nodes from the given index place in the table.
 void setColumnFields(java.lang.Class objectClass, java.lang.String[] fieldNames)
          Sets the fields to be used as columns in the table
 void setColumnNames(java.lang.String[] fieldNames)
          Sets the column titles to be used in the table
 void setData(java.util.Collection theNodes)
          Sets the table's rows to the given TreeNode objects and notifies listeners.
 void setData(java.lang.Object[] theNodes)
          Sets the table's rows to the given TreeNode objects and notifies listeners.
 void unexpandNode(IXTreeTableNode eNode, int index)
          Removes the node's children from the table and notes it as unexpanded.
 
Methods inherited from class ix.iface.ui.table.AbstractIXTableModel
defaultGetCellValueAt, defaultSetColumnFields, getColumnClass, getColumnCount, getColumnName, getColumnNames, getRowCount, setColumnClasses
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDENT_STEP

public static final int INDENT_STEP
the indentation steps used to indent children

LEAFC

public static final char LEAFC
the character used to indicate a leaf (no children)

OPENC

public static final char OPENC
the character used to indicate an expanded node

CLOSEDC

public static final char CLOSEDC
the character used to indicate an un-expanded node

imageDir

public static final java.lang.String imageDir

LEAFI

public static final javax.swing.ImageIcon LEAFI

OPENI

public static final javax.swing.ImageIcon OPENI

CLOSEDI

public static final javax.swing.ImageIcon CLOSEDI

nodes

protected java.util.ArrayList nodes
a collection of IXTreeTableNodes that have been generated

nodeMap

public java.util.HashMap nodeMap
A map for looking up a TreeNode for a Object. Use: put(Object, TreeNode)
Constructor Detail

AbstractTreeTableModel

public AbstractTreeTableModel()
Makes an empty model.

AbstractTreeTableModel

public AbstractTreeTableModel(javax.swing.tree.TreeNode[] theNodes)
Makes a model that contains the given nodes at top level.
Method Detail

setData

public void setData(java.util.Collection theNodes)
Sets the table's rows to the given TreeNode objects and notifies listeners. Creates a top-level IXTreeTableNode object for each data object. Overwrites the super method.

setData

public void setData(java.lang.Object[] theNodes)
Sets the table's rows to the given TreeNode objects and notifies listeners. Creates a top-level IXTreeTableNode object for each data object. Overwrites the super method.
Overrides:
setData in class AbstractIXTableModel

clearData

public void clearData()
Description copied from class: AbstractIXTableModel
Removes all data objects from the table's rows and notifies listeners.
Overrides:
clearData in class AbstractIXTableModel

clearTable

public void clearTable()

addData

public void addData(java.lang.Object data)
Adds the given TreeNode object to the table's rows and notifies listeners. Creates a top-level IXTreeTableNode object for the data object. Overwrites the super method.
Overrides:
addData in class AbstractIXTableModel

removeData

public void removeData(java.lang.Object data)
Removes the given TreeNode object from the table's rows and notifies listeners. Creates a top-level IXTreeTableNode object for the data object. Overwrites the super method.
Overrides:
removeData in class AbstractIXTableModel

removeNodes

public void removeNodes(int number,
                        int place)
Removes the given number of nodes from the given index place in the table. Also notifies listeners. This happens when nodes are collapsed.

setColumnNames

public void setColumnNames(java.lang.String[] fieldNames)
Sets the column titles to be used in the table
Overrides:
setColumnNames in class AbstractIXTableModel

setColumnFields

public void setColumnFields(java.lang.Class objectClass,
                            java.lang.String[] fieldNames)
Sets the fields to be used as columns in the table
Overrides:
setColumnFields in class AbstractIXTableModel

getRowObject

public java.lang.Object getRowObject(int rowIndex)
Description copied from class: AbstractIXTableModel
Gets the object that is in the given row.
Overrides:
getRowObject in class AbstractIXTableModel
Following copied from class: ix.iface.ui.table.AbstractIXTableModel
Returns:
the object or null if there is no such row.

getRowNode

public java.lang.Object getRowNode(int rowIndex)

getObjectRow

public int getObjectRow(java.lang.Object object)
Description copied from class: AbstractIXTableModel
Gets the row index of the given object
Overrides:
getObjectRow in class AbstractIXTableModel
Following copied from class: ix.iface.ui.table.AbstractIXTableModel
Returns:
the object's index or -1 if there is no such object.

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Get the value for a cell in the table defined by the parameters. only the node name is different from normal node tables, so the other cells can be done by any old table model.
Overrides:
getValueAt in class AbstractIXTableModel

getTreeValueAt

protected java.lang.Object getTreeValueAt(IXTreeTableNode eNode)
Gets the value that indicates the tree-position (indented name).
Returns:
an object that can be rendered by the table.

expandNode

public void expandNode(IXTreeTableNode eNode,
                       int rowIndex)
Gathers the node's children and splices them into the table.

unexpandNode

public void unexpandNode(IXTreeTableNode eNode,
                         int index)
Removes the node's children from the table and notes it as unexpanded.

getTreeNodeType

public java.lang.Object getTreeNodeType(IXTreeTableNode eNode)
Gets a character or icon to use as a reflection of the node's tree-status. E.g. + for collapsed with children, - for expanded with children, empty for no children.

cellClicked

public void cellClicked(java.awt.event.MouseEvent me,
                        int rowIndex,
                        int columnIndex)
If the left button was clicked on the tree-column, expand/collapse node.
Specified by:
cellClicked in interface TableMouseListener
Following copied from interface: ix.iface.ui.table.TableMouseListener
Parameters:
me - the original MouseEvent.
rowIndex - the index of the row that has been clicked
columnIndex - the index of the column that has been clicked

getCellValueAt

public abstract java.lang.Object getCellValueAt(java.lang.Object node,
                                                int columnIndex)
Gets the object's value for the given column index.
Overrides:
getCellValueAt in class AbstractIXTableModel
Returns:
an object that can be rendered by the table.

getNameString

public abstract java.lang.String getNameString(javax.swing.tree.TreeNode node)
Gets the string to use for the tree-column (the name of the node).

fireObjectChanged

public void fireObjectChanged(java.lang.Object o)
The given object changed - find its tree node, fire that and redo children

defaultGetNameString

public java.lang.String defaultGetNameString(javax.swing.tree.TreeNode node)
Looks up the value in the first columnField.
Returns:
the value object or null if something goes wrong.

deriveColumnFields

protected void deriveColumnFields()
Collects usable fields from the objectClass
Overrides:
deriveColumnFields in class AbstractIXTableModel

getTreeNode

public javax.swing.tree.TreeNode getTreeNode(java.lang.Object object)
Get the (possibly new) TreeNode that is associlated with the given Object.

getTreeNode

public javax.swing.tree.TreeNode getTreeNode(java.lang.Object object,
                                             java.util.List parents,
                                             int indentation)

addTreeNode

public void addTreeNode(java.lang.Object object,
                        javax.swing.tree.TreeNode tNode)
Associate the given TreeNode to the given AgendaItem

makeIXTreeTableNode

public abstract IXTreeTableNode makeIXTreeTableNode(java.lang.Object node)

makeIXTreeTableNode

public IXTreeTableNode makeIXTreeTableNode(java.lang.Object node,
                                           java.util.List parents,
                                           int indentation)
indentation is number of blanks to put in front of node (n*INDENT_STEP)