JIDE 3.5.15

com.jidesoft.grid
Class DefaultPageTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.grid.AbstractPageTableModel
          extended by com.jidesoft.grid.DefaultPageTableModel
All Implemented Interfaces:
ColumnIdentifierTableModel, ContextSensitiveTableModel, IndexChangeEventGenerator, IndexedRowTableModelWrapper, ITreeTableModel, MultiTableModel, RowTableModelWrapper, TableModelWrapper, WrapperOfIndexdRowTableModelWrapper, PageNavigationSupport, Serializable, EventListener, TableModelListener, TableModel

public class DefaultPageTableModel
extends AbstractPageTableModel
implements IndexChangeEventGenerator, ColumnIdentifierTableModel, IndexedRowTableModelWrapper, ITreeTableModel, WrapperOfIndexdRowTableModelWrapper

DefaultPageTableModel extends AbstractPageTableModel to provide a default implementation for PageNavigationSupport. It uses the table model wrapper technique we used in JIDE Grids to provide a view into one page of the original table model. PageNavigationBar leverages this class to implement the page navigation for any table model.

To create a DefaultPageTableModel, you need the original table model.

 DefaultPageTableModel pageTableModel = new DefaultPageTableModel(originalTableModel);
 JTable table = new JTable(pageTableModel);
 
With this code above, JTable will display the first 10 rows of the original table model. You can call methods such as AbstractPageTableModel.setCurrentPage(int) to open other pages. You could add buttons to control this DefaultPageTableModel but that's exactly what PageNavigationBar is for. So in the other word, there is no need to use DefaultPageTableModel directly unless you want to control the page navigation yourself.

See Also:
PageNavigationBar, Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.jidesoft.grid.MultiTableModel
FOOTER_COLUMN, HEADER_COLUMN, REGULAR_COLUMN
 
Constructor Summary
DefaultPageTableModel(TableModel model)
          Creates a DefaultPageTableModel with 10 as the page size.
DefaultPageTableModel(TableModel model, int pageSize)
          Creates a DefaultPageTableModel with a page size.
 
Method Summary
 void addIndexChangeListener(IndexChangeListener l)
          Add IndexChangelistener.
 TableModel getActualModel()
          Gets the underlying table model.
 int getActualRowAt(int visualRow)
          Gets the actual row index in the underlying table that corresponds the specified row index.
 Class<?> getCellClassAt(int rowIndex, int columnIndex)
          Gets the type at cell (row, column).
 Class<?> getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 Object getColumnIdentifier(int columnIndex)
          Returns the identifier of the column in the model.
 String getColumnName(int column)
           
 int getColumnType(int columnIndex)
          Checks if the column at the columnIndex is a header column or footer column or just regular column.
 ConverterContext getConverterContextAt(int rowIndex, int columnIndex)
          Gets the converter context at cell (row, column).
 EditorContext getEditorContextAt(int rowIndex, int columnIndex)
          Gets the editor context at cell (row, column).
 IndexChangeListener[] getIndexChangeListeners()
          Returns an array of all the IndexChangeListeners
 IndexedRowTableModelWrapper getIndexedRowTableModelWrapper()
           
 int[] getIndexes()
          Gets the indexes that maps from the visual row index to the actual row index.
 Object getRoot()
          Gets the root expandable row which has the original rows as children.
 Row getRowAt(int rowIndex)
          Returns the row at row specified by row.
 int getRowIndex(Row row)
          Gets the index of the row.
 int getTableIndex(int columnIndex)
          Gets the table index that this column belongs to.
 int getTotalRecordCount()
          Gets the total record/row count.
 Object getValueAt(int rowIndex, int columnIndex)
           
 int getVisualRowAt(int actualRow)
          Gets the visual row index representing the specified actual row.
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 boolean isUpdatable()
           
protected  void pageCountChanged(int oldPageCount, int newPageCount)
           
protected  void pageIndexChanged(int oldPageIndex, int newPageIndex)
           
protected  void reallocateIndexes()
           
 void removeIndexChangeListener(IndexChangeListener l)
          Remove IndexChangelistener.
 void setIndexes(int[] indexes)
          Sets the indexes of the row mapping.
 void setTableModel(TableModel model)
          Sets the new table model for the DefaultPageTableModel.
 void setTotalRecordCount(int totalRecordCount)
          Sets the total record/row count.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
           
 
Methods inherited from class com.jidesoft.grid.AbstractPageTableModel
addPageNavigationListener, createCompoundTableModelEvent, firePageNavigationEvent, fireTableCellsUpdated, fireTableChanged, firstPage, getCurrentPage, getPageCount, getPageNavigationListeners, getPageSize, getRowCount, lastPage, nextPage, pageSizeChanged, previousPage, removePageNavigationListener, setCurrentPage, setPageCount, setPageSize, tableCellsUpdated, tableChanged, tableDataChanged, tableRowsDeleted, tableRowsInserted, tableRowsUpdated, tableStructureChanged
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, 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
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Constructor Detail

DefaultPageTableModel

public DefaultPageTableModel(TableModel model)
Creates a DefaultPageTableModel with 10 as the page size.

Parameters:
model - the original table model.

DefaultPageTableModel

public DefaultPageTableModel(TableModel model,
                             int pageSize)
Creates a DefaultPageTableModel with a page size.

Parameters:
model - the original table model.
pageSize - the page size.
Method Detail

setTableModel

public void setTableModel(TableModel model)
Sets the new table model for the DefaultPageTableModel.

Parameters:
model - the new table model
Since:
3.5.5

getActualRowAt

public int getActualRowAt(int visualRow)
Description copied from interface: RowTableModelWrapper
Gets the actual row index in the underlying table that corresponds the specified row index.

Specified by:
getActualRowAt in interface RowTableModelWrapper
Parameters:
visualRow - the visual row index.
Returns:
the actual row. If the actual row doesn't exist, return -1.

getVisualRowAt

public int getVisualRowAt(int actualRow)
Description copied from interface: RowTableModelWrapper
Gets the visual row index representing the specified actual row.

Specified by:
getVisualRowAt in interface RowTableModelWrapper
Parameters:
actualRow - the actual row index.
Returns:
the visual row index. -1 if there is no visual row representing it.

getActualModel

public TableModel getActualModel()
Description copied from interface: TableModelWrapper
Gets the underlying table model.

Specified by:
getActualModel in interface TableModelWrapper
Returns:
the underlying table model.

addIndexChangeListener

public void addIndexChangeListener(IndexChangeListener l)
Description copied from interface: IndexChangeEventGenerator
Add IndexChangelistener.

Specified by:
addIndexChangeListener in interface IndexChangeEventGenerator
Parameters:
l - the listener

removeIndexChangeListener

public void removeIndexChangeListener(IndexChangeListener l)
Description copied from interface: IndexChangeEventGenerator
Remove IndexChangelistener.

Specified by:
removeIndexChangeListener in interface IndexChangeEventGenerator
Parameters:
l - the listener

getIndexChangeListeners

public IndexChangeListener[] getIndexChangeListeners()
Description copied from interface: IndexChangeEventGenerator
Returns an array of all the IndexChangeListeners

Specified by:
getIndexChangeListeners in interface IndexChangeEventGenerator
Returns:
all of the IndexChangeListeners added or an empty array if no listeners have been added
See Also:
IndexChangeEventGenerator.addIndexChangeListener(com.jidesoft.grid.IndexChangeListener)

pageCountChanged

protected void pageCountChanged(int oldPageCount,
                                int newPageCount)
Specified by:
pageCountChanged in class AbstractPageTableModel

pageIndexChanged

protected void pageIndexChanged(int oldPageIndex,
                                int newPageIndex)
Specified by:
pageIndexChanged in class AbstractPageTableModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Specified by:
getValueAt in interface TableModel

getColumnClass

public Class<?> getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

getConverterContextAt

public ConverterContext getConverterContextAt(int rowIndex,
                                              int columnIndex)
Description copied from interface: ContextSensitiveTableModel
Gets the converter context at cell (row, column).

For a special row index like -1, please return the default converter context for the entire column if there is any.

Specified by:
getConverterContextAt in interface ContextSensitiveTableModel
Overrides:
getConverterContextAt in class AbstractPageTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
converter context

getEditorContextAt

public EditorContext getEditorContextAt(int rowIndex,
                                        int columnIndex)
Description copied from interface: ContextSensitiveTableModel
Gets the editor context at cell (row, column).

For a special row index like -1, please return the default editor context for the entire column if there is any.

Specified by:
getEditorContextAt in interface ContextSensitiveTableModel
Overrides:
getEditorContextAt in class AbstractPageTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
editor context

getCellClassAt

public Class<?> getCellClassAt(int rowIndex,
                               int columnIndex)
Description copied from interface: ContextSensitiveTableModel
Gets the type at cell (row, column).

For a special row index like -1, please return the default column class for the entire column if there is any.

Specified by:
getCellClassAt in interface ContextSensitiveTableModel
Overrides:
getCellClassAt in class AbstractPageTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
type

getColumnName

public String getColumnName(int column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnIdentifier

public Object getColumnIdentifier(int columnIndex)
Description copied from interface: ColumnIdentifierTableModel
Returns the identifier of the column in the model. A JideTable uses this method to get the unique identifier of this column.

Specified by:
getColumnIdentifier in interface ColumnIdentifierTableModel
Parameters:
columnIndex - the index of the column
Returns:
the unique identifier of the column.

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

getTotalRecordCount

public int getTotalRecordCount()
Description copied from interface: PageNavigationSupport
Gets the total record/row count.

Specified by:
getTotalRecordCount in interface PageNavigationSupport
Returns:
the total record/row count.

setTotalRecordCount

public void setTotalRecordCount(int totalRecordCount)
Description copied from interface: PageNavigationSupport
Sets the total record/row count.

Specified by:
setTotalRecordCount in interface PageNavigationSupport
Parameters:
totalRecordCount - the new total row count.

getIndexes

public int[] getIndexes()
Description copied from interface: IndexedRowTableModelWrapper
Gets the indexes that maps from the visual row index to the actual row index. It should return a clone of the index array, not the actual array that is being used.

Specified by:
getIndexes in interface IndexedRowTableModelWrapper
Returns:
the indexes.

setIndexes

public void setIndexes(int[] indexes)
Description copied from interface: IndexedRowTableModelWrapper
Sets the indexes of the row mapping. We exposed this method to allow quick access to the underlying indexes. The method won't fire any table events. So once you change the indexes, you need to fire corresponding table event so that table can update itself.

Specified by:
setIndexes in interface IndexedRowTableModelWrapper
Parameters:
indexes - the new index array.

reallocateIndexes

protected void reallocateIndexes()

isUpdatable

public boolean isUpdatable()

getColumnType

public int getColumnType(int columnIndex)
Description copied from interface: MultiTableModel
Checks if the column at the columnIndex is a header column or footer column or just regular column. Header columns will be displayed at the left side of the table. Footer columns will be on the right side. Regular columns will in the middle and will have horizontal scroll bar if there are a lot of columns.

Specified by:
getColumnType in interface MultiTableModel
Overrides:
getColumnType in class AbstractPageTableModel
Parameters:
columnIndex - the column index
Returns:
column type. The possible values are REGULAR_COLUMN, HEADER_COLUMN, or FOOTER_COLUMN.

getTableIndex

public int getTableIndex(int columnIndex)
Description copied from interface: MultiTableModel
Gets the table index that this column belongs to. As convention, the table index starts from 0. So all columns that return 0 in this method will be grouped into the first table. Those return 1 will be on the second table, and so on.

Specified by:
getTableIndex in interface MultiTableModel
Overrides:
getTableIndex in class AbstractPageTableModel
Parameters:
columnIndex - the column index
Returns:
the table index.

getRowAt

public Row getRowAt(int rowIndex)
Description copied from interface: ITreeTableModel
Returns the row at row specified by row.

Specified by:
getRowAt in interface ITreeTableModel
Parameters:
rowIndex - the row whose row is to be queried
Returns:
the row at the specified row index

getRowIndex

public int getRowIndex(Row row)
Description copied from interface: ITreeTableModel
Gets the index of the row.

Specified by:
getRowIndex in interface ITreeTableModel
Parameters:
row - row
Returns:
the index of the row. If the row is displayed in the table, it will return the index. Otherwise, it will return -1. So -1 could mean two things - the row is not displayed or the row is not in the tree hierarchy at all.

getRoot

public Object getRoot()
Description copied from interface: ITreeTableModel
Gets the root expandable row which has the original rows as children.

Specified by:
getRoot in interface ITreeTableModel
Returns:
the root expandable row.

getIndexedRowTableModelWrapper

public IndexedRowTableModelWrapper getIndexedRowTableModelWrapper()
Specified by:
getIndexedRowTableModelWrapper in interface WrapperOfIndexdRowTableModelWrapper

JIDE 3.5.15