org.bibalex.daf.commongui.datamodels
Class UIDataTable

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.bibalex.daf.handlers.dbhandler.DataTable
          extended by org.bibalex.daf.commongui.datamodels.UIDataTable
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel
Direct Known Subclasses:
AppendedUIDataTable

public class UIDataTable
extends DataTable

This class extends the DataTable class to be able to display its contents in a proper way through a JTable, this class is used as a DataModel for the JTable. It also extracts the displayed data from a DataTable with the minimum duplication possible.

Author:
Fadi.Edward
See Also:
Serialized Form

Field Summary
protected  int colID
          The Column representing the ID in the DataTable.
private  int column
           
private  java.lang.Class columnClass
           
protected  boolean[] isColumnEditable
          Boolean Array to indicate which columns are visible and wich are not.
protected  boolean[] isColumnVisible
          Boolean Array to indicate which columns are visible and wich are not.
protected  java.lang.String[] uiColumnsNames
          String Array to hold the displayed Column names on the JTable Header.
protected  int visibleColumnsCount
          A member to indicate the count of the columns with visible state = true.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
UIDataTable(DataTable dataTable)
          Constructor.
UIDataTable(DataTable dataTable, int colID)
          Constructor
 
Method Summary
protected  int getActualColumnIndex(int column)
          This method translate visual column index (relative to only visible columns) to the actual one in the DataTable.
 java.lang.Class getColumnClass(int col)
          Retreives the specified Column Class.
 int getColumnCount()
          Retreives the diplayed columns count.
 java.lang.String getColumnName(int column)
          Retreives the column Name, if this column had a UI Column it is returned, elsewise the Original DataTable Column name is returned.
 int getIDAt(int index)
          Retreives the ID from the DataTable representing the row at the given index.
 int getIndexOf(int value, int colID)
          Parses the DataTable to find the equivalent index for the given Object in the metioned colID.
 int getIndexOfID(int id)
          Parses the DataTable to find the equivalent index for the given id in the default index column.
 int getRowCount()
          Retreives the diplayed rows count.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Retreives the value (as Object) of a specific cell.
 boolean isCellEditable(int row, int col)
          Indicates whether the specified cell is editable or not, used by the JTable drawing methods.
 void setColumnClass(int col, java.lang.Class columnClass)
           
 void setColumnEditable(int col, boolean columnIsEditable)
          Sets the specified column to be either editable or not.
 void setColumnVisible(int col, boolean columnIsVisible)
          Sets the specified column to be either visible or not.
 void setUIColumnName(int col, java.lang.String columnName)
          Sets a different displayed name to the specified column, if not set the one from the DataTable is used.
 void setValueAt(java.lang.Object value, int row, int col)
          Set the value of an object in the data table given the row and col.
 
Methods inherited from class org.bibalex.daf.handlers.dbhandler.DataTable
addRow, addRow, addRowAt, addRowAt, deleteRow, elementAt, elementAt, ExportToExcel, getDynamicColumnIndices, getNameOfColumn, getNoOfColumns, getNoOfRows, getRow, setArchivingMatrix, setDynamicColumnIndices, setDynamicTable, setNameOfColumn, setNoOfColumn
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

column

private int column

columnClass

private java.lang.Class columnClass

isColumnVisible

protected boolean[] isColumnVisible
Boolean Array to indicate which columns are visible and wich are not. All Items are defaulted to visible.


isColumnEditable

protected boolean[] isColumnEditable
Boolean Array to indicate which columns are visible and wich are not. All Items are defaulted to non-editable.


uiColumnsNames

protected java.lang.String[] uiColumnsNames
String Array to hold the displayed Column names on the JTable Header. If it was not set, then the actual column names are used.


visibleColumnsCount

protected int visibleColumnsCount
A member to indicate the count of the columns with visible state = true. Instead of recalculating it each time.


colID

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

Constructor Detail

UIDataTable

public UIDataTable(DataTable dataTable)
Constructor. The ColID is considered = 0.

Parameters:
dataTable - The DataTable to extract the displayed data from.

UIDataTable

public UIDataTable(DataTable dataTable,
                   int colID)
Constructor

Parameters:
dataTable - The DataTable to extract the displayed data from.
colID - The Column representing the ID in the DataTable.
Method Detail

setColumnEditable

public void setColumnEditable(int col,
                              boolean columnIsEditable)
Sets the specified column to be either editable or not.

Parameters:
col - The index of the column to be set.
columnIsEditable - true to set as Editable and false otherwise.

setColumnVisible

public void setColumnVisible(int col,
                             boolean columnIsVisible)
Sets the specified column to be either visible or not.

Parameters:
col - The index of the column to be set.
columnIsVisible - true to set as Visible and false otherwise.

setUIColumnName

public void setUIColumnName(int col,
                            java.lang.String columnName)
Sets a different displayed name to the specified column, if not set the one from the DataTable is used.

Parameters:
col - The index of the column to be set.
columnName - The new displayed column name.

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Indicates whether the specified cell is editable or not, used by the JTable drawing methods.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
row - The row coordinate of the cell.
col - The column coordinate of the cell.
Returns:
true if the cell is editable, false otherwise.

getRowCount

public int getRowCount()
Retreives the diplayed rows count.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Overrides:
getRowCount in class DataTable
Returns:
The displayed Rows count.

getColumnCount

public int getColumnCount()
Retreives the diplayed columns count.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Overrides:
getColumnCount in class DataTable
Returns:
The displayed Columns count.

getColumnClass

public java.lang.Class getColumnClass(int col)
Retreives the specified Column Class. This method helps modifying the way things are drawn, for example for a boolean Column, instead of displaying "true" or "false" this method allows the JTable to recognize that such column is of boolean type and therfore display CheckBoxs instead.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
col - The index of the Column in question.
Returns:
The Class Type of the Column items.

setColumnClass

public void setColumnClass(int col,
                           java.lang.Class columnClass)

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Retreives the value (as Object) of a specific cell. Used by the JTable drawing methods.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Overrides:
getValueAt in class DataTable
Parameters:
rowIndex - The row coordinate of the cell.
columnIndex - The column coordinate of the cell.
Returns:
The cell value as Object (Make sure that the object has a correct toString method).

getColumnName

public java.lang.String getColumnName(int column)
Retreives the column Name, if this column had a UI Column it is returned, elsewise the Original DataTable Column name is returned.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class DataTable
Parameters:
column - The index of the column.
Returns:
The displayed column name.

getActualColumnIndex

protected int getActualColumnIndex(int column)
This method translate visual column index (relative to only visible columns) to the actual one in the DataTable.

Parameters:
column - The index of the visual column index.
Returns:
The actual column index in the DataTable.

setValueAt

public void setValueAt(java.lang.Object value,
                       int row,
                       int col)
Set the value of an object in the data table given the row and col. This function is used only if the table is editable.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class DataTable
Parameters:
value - The value to be set
row - The row index (0 - based).
col - The column index.

getIDAt

public int getIDAt(int index)
Retreives the ID from the DataTable representing the row at the given index.

Parameters:
index - The row index.
Returns:
The DataTable row ID.

getIndexOf

public int getIndexOf(int value,
                      int colID)
Parses the DataTable to find the equivalent index for the given Object in the metioned colID.

Parameters:
value - the value to search for.
colID - the Column identifier to search in.
Returns:
the index of the matching row if found, -1 otherwise.

getIndexOfID

public int getIndexOfID(int id)
Parses the DataTable to find the equivalent index for the given id in the default index column.

Parameters:
id - the id to search for.
Returns:
the index of the matching id if found, -1 otherwise.