org.bibalex.daf.handlers.dbhandler
Class DataTable

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

public class DataTable
extends javax.swing.table.AbstractTableModel

Represents an in memory database table.

Author:
shehab.kamal
See Also:
Serialized Form

Field Summary
private  java.util.Vector<java.lang.String> columnNames
          Holds the names of the columns
private static java.util.ArrayList<java.lang.Integer> DynamicColumnIndices
           
private  java.util.Vector<java.lang.Object> table
          Holds the table of the data
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DataTable()
          Creates a new DataTable with empty column names and no data.
DataTable(DataTable dataTable)
          Copy Constructor
DataTable(int columns)
          Creates a new DataTable with the specifeid number of columns and empty data.
DataTable(java.sql.ResultSet result)
          Creates a new DataTable based on the given result set.
 
Method Summary
 void addRow(DataTable row)
          Adds a data table row to the table.
 void addRow(java.lang.Object[] row)
          Adds a row to the table.
 void addRowAt(DataTable row, int index)
          Adds a row to the table with index.
 void addRowAt(java.lang.Object[] row, int index)
          Adds a row to the table with index.
 void deleteRow(int rowIndex)
          Deletes the row at the specified index.
 java.lang.Object elementAt(int row, int column)
          Gets the element at the specified row and column.
 java.lang.Object elementAt(int row, java.lang.String columnName)
          Gets the element at the specified row and column.
static void ExportToExcel(DataTable model)
          Exports the table to excel sheet
 int getColumnCount()
           
 java.lang.String getColumnName(int column)
           
static java.util.ArrayList getDynamicColumnIndices()
           
 java.lang.String getNameOfColumn(int column)
          Gets the column name.
 int getNoOfColumns()
          Gets the number of columns in the DataTable.
 int getNoOfRows()
          Gets the number of rows in the DataTable.
 DataTable getRow(int index)
          Retrieves the row from the dataTable for the selected index
 int getRowCount()
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 DataTable setArchivingMatrix(DataTable dataTable, DataTable columnDataTable)
           
static void setDynamicColumnIndices(java.util.ArrayList<java.lang.Integer> indices)
           
 DataTable setDynamicTable(DataTable dataTable, DataTable columnDataTable, int[] usersIDs, java.lang.String[] usersNames)
           
 void setNameOfColumn(int column, java.lang.String name)
          Sets the column name.
 void setNoOfColumn(int size)
          Sets the number of columns in the DataTable.
 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 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

table

private java.util.Vector<java.lang.Object> table
Holds the table of the data


columnNames

private java.util.Vector<java.lang.String> columnNames
Holds the names of the columns


DynamicColumnIndices

private static java.util.ArrayList<java.lang.Integer> DynamicColumnIndices
Constructor Detail

DataTable

public DataTable()
Creates a new DataTable with empty column names and no data.


DataTable

public DataTable(DataTable dataTable)
Copy Constructor

Parameters:
dataTable - The DataTable to copy.

DataTable

public DataTable(int columns)
Creates a new DataTable with the specifeid number of columns and empty data.

Parameters:
columns - The number of columns in the DataTable.

DataTable

public DataTable(java.sql.ResultSet result)
Creates a new DataTable based on the given result set.

Parameters:
result - A result set used to populate the DataTable.
Method Detail

setNoOfColumn

public void setNoOfColumn(int size)
Sets the number of columns in the DataTable.

Parameters:
size - The number of columns.

setDynamicTable

public DataTable setDynamicTable(DataTable dataTable,
                                 DataTable columnDataTable,
                                 int[] usersIDs,
                                 java.lang.String[] usersNames)

setArchivingMatrix

public DataTable setArchivingMatrix(DataTable dataTable,
                                    DataTable columnDataTable)

getNoOfColumns

public int getNoOfColumns()
Gets the number of columns in the DataTable.

Returns:
The number of columns.

getDynamicColumnIndices

public static java.util.ArrayList getDynamicColumnIndices()

getNoOfRows

public int getNoOfRows()
Gets the number of rows in the DataTable.

Returns:
The number of rows.

setNameOfColumn

public void setNameOfColumn(int column,
                            java.lang.String name)
Sets the column name.

Parameters:
column - The column index (0 - based).
name - The name of the column.

getNameOfColumn

public java.lang.String getNameOfColumn(int column)
Gets the column name.

Parameters:
column - The column index (0 - based).
Returns:
The name of the specified column or empty string if the specified index doesn't exist.

addRow

public void addRow(java.lang.Object[] row)
Adds a row to the table.

Parameters:
row - An array holding the values to be added.

addRow

public void addRow(DataTable row)
Adds a data table row to the table.

Parameters:
row - a data table row.

addRowAt

public void addRowAt(DataTable row,
                     int index)
Adds a row to the table with index.

Parameters:
row - a DataTable to be added.
index - is the location of the row

addRowAt

public void addRowAt(java.lang.Object[] row,
                     int index)
Adds a row to the table with index.

Parameters:
row - An array holding the values to be added.
index - is the location of the row

deleteRow

public void deleteRow(int rowIndex)
Deletes the row at the specified index.

Parameters:
rowIndex - The index of the row to delete.

elementAt

public java.lang.Object elementAt(int row,
                                  int column)
Gets the element at the specified row and column.

Parameters:
row - The row index (0 - based).
column - The column index (0 - based).
Returns:
The element at the specified row and column.

elementAt

public java.lang.Object elementAt(int row,
                                  java.lang.String columnName)
Gets the element at the specified row and column.

Parameters:
row - The row index (0 - based).
columnName - The column name.
Returns:
The element at the specified row and column.

getRowCount

public int getRowCount()

getColumnCount

public int getColumnCount()

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)

getColumnName

public java.lang.String getColumnName(int column)
Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

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

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

getRow

public DataTable getRow(int index)
Retrieves the row from the dataTable for the selected index

Parameters:
index - the row to retreive
Returns:
DataTable representing the selected Row

ExportToExcel

public static void ExportToExcel(DataTable model)
Exports the table to excel sheet

Parameters:
model - The DataTable to export to excel.

setDynamicColumnIndices

public static void setDynamicColumnIndices(java.util.ArrayList<java.lang.Integer> indices)