org.tentackle.ui
Class FormTableSorter

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.tentackle.ui.AbstractFormTableModel
          extended by org.tentackle.ui.FormTableMap
              extended by org.tentackle.ui.FormTableSorter
All Implemented Interfaces:
MouseListener, Serializable, EventListener, TableModelListener, TableModel

public class FormTableSorter
extends FormTableMap
implements MouseListener

A table model and mapper to sort rows.

Author:
harald
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.tentackle.ui.FormTableMap
model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
FormTableSorter(AbstractFormTableModel model)
          Create a form table sorter on top of a given table model.
 
Method Summary
 void addMouseListenerForHeaderOfTable()
          Installs a Mouse-Listener to the table header.
Mouse clicks on a column header will be treated as follows: single click: add column to sort criteria double click: add column and run the sort Pressing the shift key switches to descending order for the column.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a property change listener (used if sorting has changed)
 void addSortIndex(int column)
          Adds a sort index.
 void clearMapping()
          Clears the mapping.
 void clearSorting()
          Clears the sorting
 FormTableEntry getEntryAt(int rowIndex)
          Gets the form table entry at given row.
 int getMappedIndex(int mappedRow)
          Gets the mapped row index according to a given model row.
Inversion of getModelIndex().
 int[] getMappedIndex(int[] mappedRows)
          Gets the mapped row indexes according to given model rows.
Inversion of getModelIndex().
 int getModelIndex(int row)
          Gets the row in the original model according to the mapping.
The default implementation returns the same row.
 int[] getModelIndex(int[] rows)
          Gets the rows in the original model according to the mapping.
The default implementation returns the same rows.
 int getRowCount()
          Returns the number of rows in the model.
 int[] getSorting()
          Gets the sort indexes.
 String getSortNames()
          Gets a string containing the (displayed) field-names of the current sorting.
 FormTableEntry getSumEntry()
           
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns false.
 boolean isSorted()
          Determines whether the table is sorted.
 void mouseClicked(MouseEvent e)
          Invoked when the mouse button has been clicked (pressed and released) on a component.
 void mouseEntered(MouseEvent e)
          Invoked when the mouse enters a component.
 void mouseExited(MouseEvent e)
          Invoked when the mouse exits a component.
 void mousePressed(MouseEvent e)
          Invoked when a mouse button has been pressed on a component.
 void mouseReleased(MouseEvent e)
          Invoked when a mouse button has been released on a component.
 void removeMouseListenerForHeaderOfTable()
          Removes the mouse header listeners.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a property change listener.
 void setSorting(int[] sortby)
          Sets the sort indexes
 void setSumEntry(FormTableEntry sumEntry)
          Sets a table entry to sum up the rows.
 void setTable(FormTable table)
          Sets the table.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          This empty implementation is provided so users don't have to implement this method if their data model is not editable.
 void sort()
          Do the sort
 void tableChanged(TableModelEvent e)
          Table data has changed from unterlying tablemodel: sort data and redisplay.
 
Methods inherited from class org.tentackle.ui.FormTableMap
getColumnClass, getColumnCount, getColumnName, getDisplayedColumnName, getModel, getTemplate, isDataChanged, setDataChanged, setModel
 
Methods inherited from class org.tentackle.ui.AbstractFormTableModel
getMap, getTable, setEntryAt, setMap
 
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
 

Constructor Detail

FormTableSorter

public FormTableSorter(AbstractFormTableModel model)
Create a form table sorter on top of a given table model.

Parameters:
model - the chained table model
Method Detail

setTable

public void setTable(FormTable table)
Sets the table.

If the table is set the selections will be kept across sortings. Otherwise the selections will be cleared. A mouse listener will also be registered for the table.

Overrides:
setTable in class AbstractFormTableModel
Parameters:
table - the form table or null if this model is not the direct data model for the table (i.e. somewhere in a chain)
See Also:
addMouseListenerForHeaderOfTable()

setSumEntry

public void setSumEntry(FormTableEntry sumEntry)
Sets a table entry to sum up the rows. Will always be appended to the end of the table.

Parameters:
sumEntry - the summing table entry

getSumEntry

public FormTableEntry getSumEntry()
Returns:
the sumEntry, null if none

getRowCount

public int getRowCount()
Description copied from interface: javax.swing.table.TableModel
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Specified by:
getRowCount in interface TableModel
Overrides:
getRowCount in class FormTableMap
Returns:
the number of rows in the model
See Also:
TableModel.getColumnCount()

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Description copied from class: FormTableMap
Returns the value for the cell at columnIndex and rowIndex.

This method must be overridden for another mapping than 1:1.

Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class FormTableMap
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(Object aValue,
                       int rowIndex,
                       int columnIndex)
Description copied from class: FormTableMap
This empty implementation is provided so users don't have to implement this method if their data model is not editable.

This method must be overridden for another mapping than 1:1.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class FormTableMap
Parameters:
aValue - value to assign to cell
rowIndex - row of cell
columnIndex - column of cell
See Also:
TableModel.getValueAt(int, int), TableModel.isCellEditable(int, int)

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Description copied from class: javax.swing.table.AbstractTableModel
Returns false. This is the default implementation for all cells.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class FormTableMap
Parameters:
rowIndex - the row being queried
columnIndex - the column being queried
Returns:
false
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

getEntryAt

public FormTableEntry getEntryAt(int rowIndex)
Description copied from class: AbstractFormTableModel
Gets the form table entry at given row.

Overrides:
getEntryAt in class FormTableMap
Parameters:
rowIndex - the row of the table entry
Returns:
the table entry, null if rowIndex out of range

getMappedIndex

public int getMappedIndex(int mappedRow)
Description copied from class: AbstractFormTableModel
Gets the mapped row index according to a given model row.
Inversion of getModelIndex(). The default implementation returns the same row. Must be overridden for another mapping than 1:1.

Overrides:
getMappedIndex in class FormTableMap
Parameters:
mappedRow - the original row
Returns:
the mapped row index

getMappedIndex

public int[] getMappedIndex(int[] mappedRows)
Description copied from class: AbstractFormTableModel
Gets the mapped row indexes according to given model rows.
Inversion of getModelIndex(). The default implementation returns the same rows. Must be overridden for another mapping than 1:1.

Overrides:
getMappedIndex in class FormTableMap
Parameters:
mappedRows - the original rows
Returns:
the mapped row indexes

getModelIndex

public int getModelIndex(int row)
Description copied from class: AbstractFormTableModel
Gets the row in the original model according to the mapping.
The default implementation returns the same row. Must be overridden for another mapping than 1:1.

Overrides:
getModelIndex in class FormTableMap
Parameters:
row - the row of this model
Returns:
the row of the mapped model

getModelIndex

public int[] getModelIndex(int[] rows)
Description copied from class: AbstractFormTableModel
Gets the rows in the original model according to the mapping.
The default implementation returns the same rows. Must be overridden for another mapping than 1:1.

Overrides:
getModelIndex in class FormTableMap
Parameters:
rows - the array of rows of this model
Returns:
the rows of the mapped model

addSortIndex

public void addSortIndex(int column)
Adds a sort index.

Parameters:
column - the column index to add

sort

public void sort()
Do the sort


clearMapping

public void clearMapping()
Clears the mapping. Sets a 1:1 mapping for the table.


clearSorting

public void clearSorting()
Clears the sorting


getSorting

public int[] getSorting()
Gets the sort indexes.

Returns:
the array of column indexes, null if no sorting

setSorting

public void setSorting(int[] sortby)
Sets the sort indexes

Parameters:
sortby - the array of column indexes, null to clear sorting

isSorted

public boolean isSorted()
Determines whether the table is sorted.

Returns:
true if sorted

getSortNames

public String getSortNames()
Gets a string containing the (displayed) field-names of the current sorting.

Returns:
fieldnames seperated by colons, null if no sorting.

tableChanged

public void tableChanged(TableModelEvent e)
Table data has changed from unterlying tablemodel: sort data and redisplay.

This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.

Event handler for TableModelListener: table data has changed.
This method must be overridden for another mapping than 1:1. The default implementation just invokes fireTableChanged.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class FormTableMap
Parameters:
e - the table model event

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a property change listener (used if sorting has changed)

Parameters:
listener - the listener to add

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener.

Parameters:
listener - the listener to remove

addMouseListenerForHeaderOfTable

public void addMouseListenerForHeaderOfTable()
Installs a Mouse-Listener to the table header.
Mouse clicks on a column header will be treated as follows: Pressing the shift key switches to descending order for the column.


removeMouseListenerForHeaderOfTable

public void removeMouseListenerForHeaderOfTable()
Removes the mouse header listeners.


mouseClicked

public void mouseClicked(MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
Invoked when the mouse button has been clicked (pressed and released) on a component.

Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
Invoked when the mouse enters a component.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
Invoked when the mouse exits a component.

Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
Invoked when a mouse button has been pressed on a component.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
Invoked when a mouse button has been released on a component.

Specified by:
mouseReleased in interface MouseListener


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de