table.model
Class EnvelopeTableModel

java.lang.Object
  |
  +--table.model.EnvelopeTableModel
All Implemented Interfaces:
java.util.EventListener, javax.swing.table.TableModel, javax.swing.event.TableModelListener

public class EnvelopeTableModel
extends java.lang.Object
implements javax.swing.table.TableModel, javax.swing.event.TableModelListener

EnvelopeTableModel incapsulates another TableModel and gives possibility to perform reordering and grouping of data without changing original data. It also allows to set group functions for grouped data.

Version:
1.0
Author:
Stanislav Lapitsky

Field Summary
static int GROUP_FUNCTION_AVG
           
static int GROUP_FUNCTION_COUNT
           
static int GROUP_FUNCTION_EMPTY
           
static int GROUP_FUNCTION_MAX
           
static int GROUP_FUNCTION_MIN
           
static int GROUP_FUNCTION_SUM
           
protected  int[] groupColumnIndexes
          Group columns.
protected  Grouper grouper
          Data grouper.
protected  int[] groupFunctions
          Group functions attached to columns.
protected  boolean[] groupOrders
          Sort orders for each column from groupColumnIndexes.
protected  java.util.ArrayList listenersList
          List of attached TableModelListeners.
protected  java.util.ArrayList modelData
          Containes model's rows.
protected  javax.swing.table.TableModel originalModel
          Original (incapsulated) model.
protected  int[] sortColumnIndexes
          Sort columns.
protected  Sorter sorter
          Data sorter.
protected  boolean[] sortOrders
          Sort orders for each column from sortColumnIndexes.
 
Constructor Summary
EnvelopeTableModel(javax.swing.table.TableModel source)
          Constructs a new instance with specified original TableModel.
 
Method Summary
 void addTableModelListener(javax.swing.event.TableModelListener l)
          Adds a listener to the list that is notified each time a change to the data model occurs.
 void fireTableDataChanged()
          Noifies all table model listeners about data changes.
 void fireTableModelEvent(javax.swing.event.TableModelEvent event)
          Noifies all table model listeners about data changes.
 java.lang.Class getColumnClass(int columnIndex)
          Returns the most specific superclass for all the cell values in the column.
 int getColumnCount()
          Returns the number of columns in the model.
 java.lang.String getColumnName(int columnIndex)
          Returns the name of the column at columnIndex.
 int[] getGroupColumns()
          Gets group columns.
 int getGroupFunction(int columnIndex)
          Gets group function assotiated with specified column.
 int getGroupLevel(int columnIndex)
          Gets level of grouped data.
 boolean[] getGroupOrders()
          Gets group orders.
 RowContainer getGroupRoot()
          Gets root of grouped data (the last row in grouped table).
 javax.swing.table.TableModel getOriginalModel()
          Gets original TableModel
protected  int getOriginalRowNumber(int rowNumber)
          Gets originnal row number for specified row.
 RowContainer getRow(int rowIndex)
          Gets row data for specified row index.
 int getRowCount()
          Returns the number of rows in the model.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the cell at rowIndex and columnIndex is editable.
 void refreshGroup()
          Refresh grouping.
 void refreshSort()
          Refresh sort.
 void removeTableModelListener(javax.swing.event.TableModelListener l)
          Removes a listener from the list that is notified each time a change to the data model occurs.
 void reset()
          Restores original data order.
 void setGroup(int[] groupColumnIndexes, boolean[] groupOrders)
          Sets group regim.
 void setGroupFunction(int columnIndex, int groupFunction)
          Sets group function for specified column.
protected  void setGroupFunctionAVG(int columnIndex)
          Sets group function AVG to specified column.
protected  void setGroupFunctionCOUNT(int columnIndex)
          Sets group function COUNT to specified column.
protected  void setGroupFunctionEMPTY(int columnIndex)
          Sets group function EMPTY to specified column.
protected  void setGroupFunctionMAX(int columnIndex)
          Sets group function MAX to specified column.
protected  void setGroupFunctionMIN(int columnIndex)
          Sets group function MIN to specified column.
protected  void setGroupFunctionSUM(int columnIndex)
          Sets group function SUM to specified column.
 void setSort(int[] sortColumnIndexes, boolean[] sortOrders)
          Sets sort regim.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets the value in the cell at columnIndex and rowIndex to aValue.
 void tableChanged(javax.swing.event.TableModelEvent e)
          When original model is changed we have to refresh data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUP_FUNCTION_EMPTY

public static final int GROUP_FUNCTION_EMPTY
See Also:
Constant Field Values

GROUP_FUNCTION_COUNT

public static final int GROUP_FUNCTION_COUNT
See Also:
Constant Field Values

GROUP_FUNCTION_MAX

public static final int GROUP_FUNCTION_MAX
See Also:
Constant Field Values

GROUP_FUNCTION_MIN

public static final int GROUP_FUNCTION_MIN
See Also:
Constant Field Values

GROUP_FUNCTION_SUM

public static final int GROUP_FUNCTION_SUM
See Also:
Constant Field Values

GROUP_FUNCTION_AVG

public static final int GROUP_FUNCTION_AVG
See Also:
Constant Field Values

originalModel

protected javax.swing.table.TableModel originalModel
Original (incapsulated) model.


listenersList

protected java.util.ArrayList listenersList
List of attached TableModelListeners.


sortColumnIndexes

protected int[] sortColumnIndexes
Sort columns.


sortOrders

protected boolean[] sortOrders
Sort orders for each column from sortColumnIndexes.


groupColumnIndexes

protected int[] groupColumnIndexes
Group columns.


groupOrders

protected boolean[] groupOrders
Sort orders for each column from groupColumnIndexes.


groupFunctions

protected int[] groupFunctions
Group functions attached to columns.


modelData

protected java.util.ArrayList modelData
Containes model's rows.


sorter

protected Sorter sorter
Data sorter.


grouper

protected Grouper grouper
Data grouper.

Constructor Detail

EnvelopeTableModel

public EnvelopeTableModel(javax.swing.table.TableModel source)
Constructs a new instance with specified original TableModel.

Parameters:
source - original TableModel.
Method Detail

getOriginalModel

public javax.swing.table.TableModel getOriginalModel()
Gets original TableModel

Returns:

getRowCount

public int getRowCount()
Returns the number of rows in the model.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
the number of rows in the model

getColumnCount

public int getColumnCount()
Returns the number of columns in the model.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
the number of columns in the model

getColumnName

public java.lang.String getColumnName(int columnIndex)
Returns the name of the column at columnIndex.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Parameters:
columnIndex - the index of the column
Returns:
the name of the column

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Parameters:
columnIndex - the index of the column
Returns:
the common ancestor class of the object values in the model.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, setValueAt on the cell will not change the value of that cell.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Parameters:
rowIndex - the row whose value to be queried
columnIndex - the column whose value to be queried
Returns:
true if the cell is editable

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried
Returns:
the value Object at the specified cell

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Parameters:
aValue - the new value
rowIndex - the row whose value is to be changed
columnIndex - the column whose value is to be changed

addTableModelListener

public void addTableModelListener(javax.swing.event.TableModelListener l)
Adds a listener to the list that is notified each time a change to the data model occurs.

Specified by:
addTableModelListener in interface javax.swing.table.TableModel
Parameters:
l - the TableModelListener

removeTableModelListener

public void removeTableModelListener(javax.swing.event.TableModelListener l)
Removes a listener from the list that is notified each time a change to the data model occurs.

Specified by:
removeTableModelListener in interface javax.swing.table.TableModel
Parameters:
l - the TableModelListener

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
When original model is changed we have to refresh data.

Specified by:
tableChanged in interface javax.swing.event.TableModelListener
Parameters:
e - change event.

getOriginalRowNumber

protected int getOriginalRowNumber(int rowNumber)
Gets originnal row number for specified row.

Parameters:
rowNumber - number of model's row.
Returns:
original model's row number.

setSort

public void setSort(int[] sortColumnIndexes,
                    boolean[] sortOrders)
             throws SortException
Sets sort regim.

Parameters:
sortColumnIndexes - sort column indexes.
sortOrders - sort orders.
Throws:
SortException

setGroup

public void setGroup(int[] groupColumnIndexes,
                     boolean[] groupOrders)
              throws GroupException
Sets group regim.

Parameters:
groupColumnIndexes - group column indexes.
groupOrders - orders for grouped columns.
Throws:
GroupException

getGroupFunction

public int getGroupFunction(int columnIndex)
Gets group function assotiated with specified column.

Parameters:
columnIndex - index of column.
Returns:
group function.

setGroupFunction

public void setGroupFunction(int columnIndex,
                             int groupFunction)
                      throws GroupException
Sets group function for specified column.

Parameters:
columnIndex - index of column.
groupFunction - group function.
Throws:
GroupException

setGroupFunctionEMPTY

protected void setGroupFunctionEMPTY(int columnIndex)
Sets group function EMPTY to specified column.

Parameters:
columnIndex - index of column.

setGroupFunctionCOUNT

protected void setGroupFunctionCOUNT(int columnIndex)
Sets group function COUNT to specified column.

Parameters:
columnIndex - index of column.

setGroupFunctionMAX

protected void setGroupFunctionMAX(int columnIndex)
Sets group function MAX to specified column.

Parameters:
columnIndex - index of column.

setGroupFunctionMIN

protected void setGroupFunctionMIN(int columnIndex)
Sets group function MIN to specified column.

Parameters:
columnIndex - index of column.

setGroupFunctionSUM

protected void setGroupFunctionSUM(int columnIndex)
Sets group function SUM to specified column.

Parameters:
columnIndex - index of column.

setGroupFunctionAVG

protected void setGroupFunctionAVG(int columnIndex)
Sets group function AVG to specified column.

Parameters:
columnIndex - index of column.

reset

public void reset()
Restores original data order.


refreshGroup

public void refreshGroup()
Refresh grouping.


refreshSort

public void refreshSort()
Refresh sort.


getGroupRoot

public RowContainer getGroupRoot()
Gets root of grouped data (the last row in grouped table).


getRow

public RowContainer getRow(int rowIndex)
Gets row data for specified row index.

Parameters:
rowIndex - index of row.
Returns:
row data.

getGroupColumns

public int[] getGroupColumns()
Gets group columns.

Returns:
column indexes array.

getGroupOrders

public boolean[] getGroupOrders()
Gets group orders.

Returns:
orders array.

getGroupLevel

public int getGroupLevel(int columnIndex)
Gets level of grouped data.

Parameters:
columnIndex - index of grouped column.
Returns:

fireTableDataChanged

public void fireTableDataChanged()
Noifies all table model listeners about data changes.


fireTableModelEvent

public void fireTableModelEvent(javax.swing.event.TableModelEvent event)
Noifies all table model listeners about data changes.

Parameters:
event - changes event.