Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 1 (11.1.1.1.0)

E10653-02

oracle.jbo.uicli.jui
Class JUTableSortModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by oracle.jbo.uicli.jui.JUTableSortModel
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.TableModelListener, javax.swing.table.TableModel

public class JUTableSortModel
extends javax.swing.table.AbstractTableModel
implements javax.swing.event.TableModelListener

Implements a sorting filter over JUTableBinding's TableModel such that when a user clicks (or Shift_click) on a column header of the Table, the display of rows from the JUTableBinding (and hence BC4J), is sorted by that column.

This class is a customization of TableSorter in Sun's JFC example that can also be found at (JDEVELOPER_HOME)/jdk/demo/jfc/TableExample. For details on how the basic TableSorter works, please see this JFC example.

This class implements the following enhancements over the base Sun's TableSorter:

  • preserves sort-column. So when in a master detail scenario, if the master changes, the next detail set is still sorted by the desired column.
  • provides additional compare logic for oracle.jbo.domain.Number and oracle.jbo.domain.Date objects.
  • provides reset feature. Resets the sorted display to the default order on a click on the sorted column header.

    See Also:
    Serialized Form

    Field Summary
     
    Fields inherited from class javax.swing.table.AbstractTableModel
    listenerList
     
    Constructor Summary
    JUTableSortModel()
              Default Constructor just coz, base class has it.
    JUTableSortModel(JUTableBinding model)
              Constructor that sets up this sorting model on top of the existing Table model.
     
    Method Summary
     void addMouseListenerToHeaderInTable(javax.swing.JTable table)
              Override to add an action by which to reset the sorting order to the fetch order If one clicks on the same column again (or the Shift+click if the current sorting order is descending), then the Table resorts to the default row order as returned by BC4J.
    protected  void checkModel()
              If no sorting is to be done or when the base model has different row count, resets the indices map so that sorting is done again.
    protected  int compareObjectTypes(java.lang.Object obj1, java.lang.Object obj2)
              Converts unknown Object types to String and compares the Strings.
    protected  int compareRows(int row1, int row2)
              Compares the sort-column values in two rows.
    protected  int compareRowsByColumn(int row1, int row2, int column)
              Compares the values in two rows at the given column.
    static javax.swing.table.TableModel enableColumnSorting(javax.swing.JTable table, JUTableBinding tableBinding, JUTableSortModel sorter)
              JClient method to attach column-sorting model over a Table that's bound to a JUTableBinding.
     java.lang.Class getColumnClass(int aColumn)
               
     int getColumnCount()
               
     java.lang.String getColumnName(int aColumn)
               
     int getRowCount()
               
     JUTableBinding getTableBinding()
              Returns the TableModel that this class is sorting.
     java.lang.Object getValueAt(int aRow, int aColumn)
               
    protected  void initType()
              Initializes the java type that this class is sorting on.
     boolean isCellEditable(int aRow, int aColumn)
               
    protected  void reallocateIndexes()
              If sort-column is greater than -1 (when no sorting should be done), sorts the data from the base model for display.
    protected  void resetIndices()
              Initializes the mapping between indices of this model versus the base model.
    protected  void setTableBinding(JUTableBinding mdl)
              Sets the TableModel on top of which this sorter works.
     void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
               
    protected  void shuttlesort(int[] from, int[] to, int low, int high)
               
     void sortByColumn(int column, boolean ascending)
              Stores the mSortColIndex if it has changed.
    protected  void swap(int i, int j)
              Swaps the index map between two given indices.
     void tableChanged(javax.swing.event.TableModelEvent e)
               
     
    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

    JUTableSortModel

    public JUTableSortModel()
    Default Constructor just coz, base class has it.


    JUTableSortModel

    public JUTableSortModel(JUTableBinding model)
    Constructor that sets up this sorting model on top of the existing Table model.

    Method Detail

    setTableBinding

    protected void setTableBinding(JUTableBinding mdl)
    Sets the TableModel on top of which this sorter works.


    checkModel

    protected void checkModel()
    If no sorting is to be done or when the base model has different row count, resets the indices map so that sorting is done again.


    compareRows

    protected int compareRows(int row1,
                              int row2)
    Compares the sort-column values in two rows.

    Returns:
  • a positive number when column value in row1 is greater than row1,
  • 0 when the two values match
  • a negative number when column value in row1 is less than row2.

  • resetIndices

    protected void resetIndices()
    Initializes the mapping between indices of this model versus the base model.


    reallocateIndexes

    protected void reallocateIndexes()
    If sort-column is greater than -1 (when no sorting should be done), sorts the data from the base model for display. Otherwise, simply resets this class' index map.


    tableChanged

    public void tableChanged(javax.swing.event.TableModelEvent e)
    Specified by:
    tableChanged in interface javax.swing.event.TableModelListener

    initType

    protected void initType()
    Initializes the java type that this class is sorting on. This implementation special cases the following types:
  • oracle.jbo.domain.Number
  • oracle.jbo.domain.Date
  • java.lang.Number
  • java.lang.Date
  • java.lang.Boolean


  • sortByColumn

    public void sortByColumn(int column,
                             boolean ascending)
    Stores the mSortColIndex if it has changed. Also resets the sorted indices if mSortColIndex is changed.


    shuttlesort

    protected void shuttlesort(int[] from,
                               int[] to,
                               int low,
                               int high)

    swap

    protected void swap(int i,
                        int j)
    Swaps the index map between two given indices.


    compareRowsByColumn

    protected final int compareRowsByColumn(int row1,
                                            int row2,
                                            int column)
    Compares the values in two rows at the given column. For types other than listed for method initType(), this implementation calls compareObjectTypes() method where appliacations can handle custom or other types.


    compareObjectTypes

    protected int compareObjectTypes(java.lang.Object obj1,
                                     java.lang.Object obj2)
    Converts unknown Object types to String and compares the Strings. Applications should override this method to provide custom comparisions of specific types that are not handled by this Sorter by default.


    addMouseListenerToHeaderInTable

    public void addMouseListenerToHeaderInTable(javax.swing.JTable table)
    Override to add an action by which to reset the sorting order to the fetch order If one clicks on the same column again (or the Shift+click if the current sorting order is descending), then the Table resorts to the default row order as returned by BC4J.


    getTableBinding

    public JUTableBinding getTableBinding()
    Returns the TableModel that this class is sorting.


    getValueAt

    public java.lang.Object getValueAt(int aRow,
                                       int aColumn)
    Specified by:
    getValueAt in interface javax.swing.table.TableModel

    setValueAt

    public void setValueAt(java.lang.Object aValue,
                           int aRow,
                           int aColumn)
    Specified by:
    setValueAt in interface javax.swing.table.TableModel
    Overrides:
    setValueAt in class javax.swing.table.AbstractTableModel

    getRowCount

    public int getRowCount()
    Specified by:
    getRowCount in interface javax.swing.table.TableModel

    getColumnCount

    public int getColumnCount()
    Specified by:
    getColumnCount in interface javax.swing.table.TableModel

    getColumnName

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

    getColumnClass

    public java.lang.Class getColumnClass(int aColumn)
    Specified by:
    getColumnClass in interface javax.swing.table.TableModel
    Overrides:
    getColumnClass in class javax.swing.table.AbstractTableModel

    isCellEditable

    public boolean isCellEditable(int aRow,
                                  int aColumn)
    Specified by:
    isCellEditable in interface javax.swing.table.TableModel
    Overrides:
    isCellEditable in class javax.swing.table.AbstractTableModel

    enableColumnSorting

    public static javax.swing.table.TableModel enableColumnSorting(javax.swing.JTable table,
                                                                   JUTableBinding tableBinding,
                                                                   JUTableSortModel sorter)
    JClient method to attach column-sorting model over a Table that's bound to a JUTableBinding.

    Parameters:
    table - to be bound to a sortable model
    tableBinding - JClient table binding for the above table
    sorter - the JUTableSortModel instance providing custom sorting capabilities.

    Oracle Fusion Middleware Java API Reference for Oracle ADF Model
    11g Release 1 (11.1.1.1.0)

    E10653-02

    Copyright © 1997, 2009, Oracle. All rights reserved.