com.quadrique.jbuildingblocks.gui
Class TableSorterModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.quadrique.jbuildingblocks.gui.TableSorterModel
All Implemented Interfaces:
Serializable, Comparator<Object>, TableModel

public abstract class TableSorterModel
extends AbstractTableModel
implements Comparator<Object>

This class implements a generic table model that also supports sorting by clicking on a column header

Author:
Hervé Rivere
See Also:
Serialized Form

Constructor Summary
TableSorterModel(String[] zColumnNames)
          constructor
 
Method Summary
abstract  int compare(Object zObject1, Object zObject2)
          Comparison mtheod that is used to sort the rows, has to be implemented in each derived class
 boolean equals(Object zObj)
           
 int getColumnCount()
           
 String getColumnName(int zColumn)
           
 ArrayList<? extends Object> getData()
           
 int getRowCount()
           
 int getSortingColumn()
           
abstract  Object getValueAt(int zRow, int zColumn)
          To retrieve each individual cell, has to be implemented in each derived class
 boolean isAcendingSort()
           
 void setData(ArrayList<? extends Object> zData)
          Set the data model
 void setSortingParameters(int zSortColumn, boolean zIsAcendingSort)
          To set the current sorting paramters
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableSorterModel

public TableSorterModel(String[] zColumnNames)
constructor

Parameters:
zColumnNames - an array that contains the name of the columns
Method Detail

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel
Returns:
the number of rows in the table

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel
Returns:
the number of columns in the table

getColumnName

public String getColumnName(int zColumn)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
zColumn - the column index
Returns:
the column header name

getValueAt

public abstract Object getValueAt(int zRow,
                                  int zColumn)
To retrieve each individual cell, has to be implemented in each derived class

Specified by:
getValueAt in interface TableModel
Parameters:
zRow - the row index
zColumn - the column index
Returns:
the object to be used for this cell

getSortingColumn

public int getSortingColumn()
Returns:
the column that has been used to sort the columns

isAcendingSort

public boolean isAcendingSort()
Returns:
true if the sorting order is ascending, false if descending

setSortingParameters

public void setSortingParameters(int zSortColumn,
                                 boolean zIsAcendingSort)
To set the current sorting paramters

Parameters:
zSortColumn - the index of the column that is used to sort
zIsAcendingSort - true if the ascending order is to be used, false otherwise

compare

public abstract int compare(Object zObject1,
                            Object zObject2)
Comparison mtheod that is used to sort the rows, has to be implemented in each derived class

Specified by:
compare in interface Comparator<Object>
Parameters:
zObject1 - the first object
zObject2 - the second object
Returns:
0 if the objects are equal, strictly less than 0 if zObject1 is before zObject2

equals

public boolean equals(Object zObj)
Specified by:
equals in interface Comparator<Object>
Overrides:
equals in class Object
Parameters:
zObj - the TableSorterModel instance
Returns:
true if the comparison match
See Also:
Comparator

getData

public ArrayList<? extends Object> getData()
Returns:
the data model

setData

public void setData(ArrayList<? extends Object> zData)
Set the data model

Parameters:
zData - the data model


Copyright © 2001-2009 Quadrique Corporation. All Rights Reserved.