org.bibalex.daf.commongui.datamodels
Class TreeDataModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.bibalex.daf.handlers.dbhandler.DataTable
          extended by org.bibalex.daf.commongui.datamodels.TreeDataModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel, javax.swing.tree.TreeModel

public class TreeDataModel
extends DataTable
implements javax.swing.tree.TreeModel

This class is an implementation of the TreeModel, that also supports (extends) DataTable. Used as a DataModel for the JTree(s) that are filled through DataTables. This data model supports only a 3 levels tree a Root, parents and children.

Author:
Fadi.Edward
See Also:
Serialized Form

Nested Class Summary
 class TreeDataModel.TreeObject
          Represents an A tree Node object, maintains the node Type, DB ID representing this node, and value to be displayed.
protected static class TreeDataModel.TreeObjectTypes
          Defines the 3 Types of nodes (levels) suported by this tree model.
 
Field Summary
protected  DataTable childrenDataTable
          The DataTable of the last level of the tree.
protected  java.lang.String childrenSP
          The Stored Procedure used to compose and retrieve the 3rd level of the tree.
protected  int colID
          The Column indicating the ID in the DataTable.
protected  int colVisible
          The Column to be displayed in the tree.
protected  int lastElementID
          The last expanded element ID.
protected  TreeDataModel.TreeObject rootObject
          The root object of the tree.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TreeDataModel(java.lang.String rootName, DataTable dataTable, int colID, int colVisible, java.lang.String childrenSP)
          Constructor
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
          (not implemented)
 java.lang.Object getChild(java.lang.Object parent, int index)
          Retreives the child object for a given parent at a given index.
 int getChildCount(java.lang.Object parent)
          Retrieves the Child Count for a specific parent.
 TreeDataModel.TreeObject[] getChildren(javax.swing.tree.TreePath treePath)
          Returnd the children at a specific tree path.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          (not implemented)
 java.lang.Object getRoot()
          Retrieves the Root element of the tree.
 boolean isLeaf(java.lang.Object node)
          Indicates if this item is leaf or not.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
          (not implemented)
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
           
 
Methods inherited from class org.bibalex.daf.handlers.dbhandler.DataTable
addRow, addRow, addRowAt, addRowAt, deleteRow, elementAt, elementAt, ExportToExcel, getColumnCount, getColumnName, getDynamicColumnIndices, getNameOfColumn, getNoOfColumns, getNoOfRows, getRow, getRowCount, getValueAt, setArchivingMatrix, setDynamicColumnIndices, setDynamicTable, setNameOfColumn, setNoOfColumn, setValueAt
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootObject

protected TreeDataModel.TreeObject rootObject
The root object of the tree.


childrenDataTable

protected DataTable childrenDataTable
The DataTable of the last level of the tree.


colID

protected int colID
The Column indicating the ID in the DataTable.


colVisible

protected int colVisible
The Column to be displayed in the tree.


lastElementID

protected int lastElementID
The last expanded element ID.


childrenSP

protected java.lang.String childrenSP
The Stored Procedure used to compose and retrieve the 3rd level of the tree.

Constructor Detail

TreeDataModel

public TreeDataModel(java.lang.String rootName,
                     DataTable dataTable,
                     int colID,
                     int colVisible,
                     java.lang.String childrenSP)
Constructor

Parameters:
rootName - The tree Root name
dataTable - The DataTable representing the 2nd level of the tree.
colID - The Column indicating the ID in the DataTable.
colVisible - The Column to be displayed in the tree.
childrenSP - The Stored Procedure used to compose and retrieve the 3rd level of the tree.
Method Detail

getRoot

public java.lang.Object getRoot()
Retrieves the Root element of the tree.

Specified by:
getRoot in interface javax.swing.tree.TreeModel
Returns:
A TreeObject casted to Object.

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Retreives the child object for a given parent at a given index. If the parent was the root, retrieves the object from the 2nd level DataTable. If the parent was an element (2nd level), retreives the corresponding 3rd level item

Specified by:
getChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent TreeObject
index - The index within the children of the given parent.
Returns:
The designated child TreeObject casted to Object.

getChildCount

public int getChildCount(java.lang.Object parent)
Retrieves the Child Count for a specific parent.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent we need to get the child count for.
Returns:
The child count for the designated parent.

isLeaf

public boolean isLeaf(java.lang.Object node)
Indicates if this item is leaf or not. Returns always true if it is a 3rd level node and false otherwise.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Parameters:
node - The Object to check for if Leaf or not.
Returns:
true if it is a 3rd level node and false otherwise.

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel
See Also:
(not implemented)

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
(not implemented)

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent -
child - (not implemented)
Returns:
0 (not implemented)

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
(not implemented)

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l -

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
(not implemented)

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l -

getChildren

public TreeDataModel.TreeObject[] getChildren(javax.swing.tree.TreePath treePath)
Returnd the children at a specific tree path. Returns values only when the path contains 2 or 3 nodes.

Parameters:
treePath - The tree path used to find the children.
Returns:
A list of 3rd level TreeObject(s) representing the leafs of the given tree path.