Class DefaultTreeTableModel

java.lang.Object
javax.swing.tree.DefaultTreeModel
com.portal.pfc.ui.DefaultTreeTableModel
All Implemented Interfaces:
SortableTableModel, TreeTableModel, Serializable, TreeModel

public class DefaultTreeTableModel extends DefaultTreeModel implements TreeTableModel, SortableTableModel
A simple tree table data model that uses TreeTableNodes. Also supports sorting the tree table.
See Also:
  • Field Details

    • columnIdentifiers

      protected ArrayList columnIdentifiers
      The list of column identifiers.
    • sortComparators

      protected HashMap sortComparators
      The set of comparators used for sorting.
  • Constructor Details

    • DefaultTreeTableModel

      public DefaultTreeTableModel(TreeTableNode root, Object[] columnNames)
      Creates a DefaultTreeTableModel in which any node can have children and with as many columns as there are elements in columnNames
      Parameters:
      root - - a TreeTableNode object that is the root of the tree
      columnNames - - array containing the names of the new columns; if this is null then the model has no columns
    • DefaultTreeTableModel

      public DefaultTreeTableModel(TreeTableNode root, ArrayList columnNames)
      Creates a DefaultTreeTableModel in which any node can have children and with as many columns as there are elements in columnNames
      Parameters:
      root - - a TreeTableNode object that is the root of the tree
      columnNames - - list containing the names of the new columns; if this is null then the model has no columns
    • DefaultTreeTableModel

      public DefaultTreeTableModel(TreeTableNode root, boolean asksAllowsChildren, Object[] columnNames)
      Creates a DefaultTreeTableModel specifying whether any node can have children, or whether only certain nodes can have children. The tree table has as many columns as there are elements in columnNames
      Parameters:
      root - - a TreeTableNode object that is the root of the tree
      asksAllowsChildren - - if false, any node without children is a leaf
      columnNames - - array containing the names of the new columns; if this is null then the model has no columns
    • DefaultTreeTableModel

      public DefaultTreeTableModel(TreeTableNode root, boolean asksAllowsChildren, ArrayList columnNames)
      Creates a DefaultTreeTableModel specifying whether any node can have children, or whether only certain nodes can have children. The tree table has as many columns as there are elements in columnNames
      Parameters:
      root - - a TreeTableNode object that is the root of the tree
      asksAllowsChildren - - if false, any node without children is a leaf
      columnNames - - list containing the names of the new columns; if this is null then the model has no columns
  • Method Details

    • getColumnCount

      public int getColumnCount()
      Returns the number of columns in the tree table.
      Specified by:
      getColumnCount in interface TreeTableModel
    • getColumnName

      public String getColumnName(int column)
      Returns the name for column number column.
      Specified by:
      getColumnName in interface TreeTableModel
    • getColumnClass

      public Class getColumnClass(int column)
      Returns the type for column number column.
      Specified by:
      getColumnClass in interface TreeTableModel
    • getValueAt

      public Object getValueAt(Object node, int column)
      Returns the value to be displayed for node node, at column number column.
      Specified by:
      getValueAt in interface TreeTableModel
    • setAllCellsEditable

      public void setAllCellsEditable(boolean editable)
      Set all cells in the model editable or not editable.
      Parameters:
      editable -
    • isCellEditable

      public boolean isCellEditable(Object node, int column)
      Indicates whether the the value for node node, at column number column is editable.
      Specified by:
      isCellEditable in interface TreeTableModel
    • setValueAt

      public void setValueAt(Object aValue, Object node, int row, int column)
      Sets the value for node node, at row number row. at column number column.
      Specified by:
      setValueAt in interface TreeTableModel
    • valueForPathChanged

      public void valueForPathChanged(TreePath path, Object newValue)
      Specified by:
      valueForPathChanged in interface TreeModel
      Overrides:
      valueForPathChanged in class DefaultTreeModel
    • setColumnIdentifiers

      public void setColumnIdentifiers(Object[] newIdentifiers)
      Replaces the column identifiers in the model. If the number of newIdentifiers is greater than the current number of columns, new columns are added to the end of each row in the model. If the number of newIdentifiers is less than the current number of columns, all the extra columns at the end of a row are discarded.

      Parameters:
      newIdentifiers - array of column identifiers. If null, set the model to zero columns
      See Also:
      • invalid reference
        #setNumRows
    • setColumnIdentifiers

      public void setColumnIdentifiers(ArrayList newIdentifiers)
      Replaces the column identifiers in the model. If the number of newIdentifiers is greater than the current number of columns, new columns are added to the end of each row in the model. If the number of newIdentifiers is less than the current number of columns, all the extra columns at the end of a row are discarded.

      Parameters:
      newIdentifiers - vector of column identifiers. If null, set the model to zero columns
      See Also:
      • invalid reference
        #setNumRows
    • addNodeInto

      public void addNodeInto(TreeTableNode newChild, TreeTableNode parent)
      Invoke this to insert newChild at a specific location in parents children. The location will be normally be at the end of the child list. However, if parent is sorted then a location will be determined that is consistent with the current ordering. This method is the preferred mechanism for adding nodes to a sorted tree. This method will then message nodesWereInserted to create the appropriate event. This is the preferred way to add children as it will create the appropriate event.
    • insertNodeInto

      public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
      Overrides:
      insertNodeInto in class DefaultTreeModel
    • setSortComparatorForColumn

      public void setSortComparatorForColumn(TreeTableNodeComparator comparator, int column)
      Specify a comparator to use when sorting the tree table based on column. The comparator will be used to compare the values at the specified column within the nodes, not to compare the nodes themselves.
    • sort

      public void sort(int column, boolean ascending)
      Sort the entire tree model according to the values of the specified column. A comparator can be specified for comparing these values by calling setSortComparatorForColumn prior to calling this method.
      Specified by:
      sort in interface SortableTableModel
      Parameters:
      column - - specifies the column identifier used to compare the nodes
      ascending - - whether to sort in ascending order as opposed to descending order
    • nodesSorted

      public void nodesSorted()
      Invoke this method if you've sorted the entire tree model
    • nodeSorted

      public void nodeSorted(TreeNode node)
      Invoke this method if you've sorted the node
    • fireTreeTableSorted

      protected void fireTreeTableSorted(Object source, Object[] path)
      Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
      See Also:
    • convertToArrayList

      protected static ArrayList convertToArrayList(Object[] anArray)
      Returns an array list that contains the same objects as the array.
      Parameters:
      anArray - the array to be converted
      Returns:
      the new vector; if anArray is null, returns null