SPT Core API

com.sptci.echo2.table
Class JDOTableModel<D>

java.lang.Object
  extended by nextapp.echo2.app.table.AbstractTableModel
      extended by com.sptci.echo2.table.AbstractTableModel<D>
          extended by com.sptci.echo2.table.TableModel<D>
              extended by com.sptci.echo2.table.DefaultPageableTableModel<D>
                  extended by com.sptci.echo2.table.JDOTableModel<D>
Type Parameters:
D - The class name of the model object backing this table model.
All Implemented Interfaces:
PageableTableModel, SortableTableModel, Serializable, TableModel
Direct Known Subclasses:
TransactionalJDOTableModel

public class JDOTableModel<D>
extends DefaultPageableTableModel<D>
implements SortableTableModel

A generic table model used to display all instances of a specified PersistenceCapable object. Provides generic implementation of pagination and sorting algorithms.

Note This model assumes that the ApplicationInstance.getActive() returns an instance of NonTransactionalJDOApplication. The PersistenceManager to use to interact with the data store is fetched from this application instance.

.

The following shows sample usage of this class:

   import nextapp.echo2.app.Column;

   import com.sptci.echo2.table.JDOTable;
   import com.sptci.echo2.table.JDOTableModel;
   import com.sptci.echo2.table.TableNavigation;

     ...
     final MyJDOObject obj = new MyJDOObject();
     JDOTableModel<MyJDOObject> model = new JDOTableModel<MyJDOObject>( obj );
     model.init(); // This is mandatory
     JDOTable<MyJDOObject> table = new JDOTable<MyJDOObject>( model );
     Column column = new Column();
     column.add( new TableNavigation<MyJDOObject>( model ) );
     column.add( table );
 

© Copyright 2008 Sans Pareil Technologies, Inc.

Version:
$Id: JDOTableModel.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2008-04-14
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sptci.echo2.table.SortableTableModel
SortableTableModel.Direction
 
Field Summary
protected  boolean initialised
          A flag used to indicate whether this model has been initialised or not.
protected  D model
          A dummy object maintained to introspect and fetch persistent instances
protected  javax.jdo.PersistenceManager pm
          The persistence manager instance to use.
 
Fields inherited from class com.sptci.echo2.table.DefaultPageableTableModel
page, pageSize, totalRows
 
Fields inherited from class com.sptci.echo2.table.TableModel
columns, data
 
Fields inherited from class com.sptci.echo2.table.AbstractTableModel
sortDirection, sortIndex
 
Constructor Summary
protected JDOTableModel()
          Default constructor.
  JDOTableModel(D model)
          Create a new table model for objects of the specified type.
 
Method Summary
 void addRow(D row)
          Add the specified object to the end of the model.
 void deleteRow(int row)
          Delete the specified row from the model.
protected  void fetchData()
          Fetch the data for the current DefaultPageableTableModel.page from the data store.
protected  Object fetchRepository()
          Fetch the repository class for the model.
protected  void fetchSortedData()
          Fetch the data for the current DefaultPageableTableModel.page from the data store sorted by AbstractTableModel.sortIndex in AbstractTableModel.sortDirection.
protected  void fetchUnsortedData()
          Fetch the data for the current DefaultPageableTableModel.page from the data store.
 void init()
          Initialise the table model.
protected  void initTotalRows()
          Initialise the DefaultPageableTableModel.totalRows field with the total number of persistent instances of model.
 void insertRow(int row, D rowData)
          Insert the specified object at the specified row index into the model.
 void setPage(int page)
          Sets the value of DefaultPageableTableModel.page.
 void setPageSize(int pageSize)
          Sets the value of DefaultPageableTableModel.pageSize.
 void sort(int column)
          Sort the data by the values in the specified column index.
 void sort(int column, SortableTableModel.Direction direction)
          Sort the data by the values in the specified column index.
protected  void sortData()
          Perform a default sort of the displayable data since the column selected cannot be sorted through the data store.
 
Methods inherited from class com.sptci.echo2.table.DefaultPageableTableModel
getPage, getPageSize, getTotalPages
 
Methods inherited from class com.sptci.echo2.table.TableModel
deleteRow, getColumnAnnotations, getColumnClass, getColumnCount, getColumnName, getObjectAt, getRowCount, getValueAt, processColumnAnnotations, processColumns, processColumnsAnnotation, processFields, updateRow
 
Methods inherited from class com.sptci.echo2.table.AbstractTableModel
getSortDirection
 
Methods inherited from class nextapp.echo2.app.table.AbstractTableModel
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getEventListenerList, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sptci.echo2.table.SortableTableModel
getSortDirection
 

Field Detail

model

protected final D model
A dummy object maintained to introspect and fetch persistent instances


pm

protected final javax.jdo.PersistenceManager pm
The persistence manager instance to use.


initialised

protected boolean initialised
A flag used to indicate whether this model has been initialised or not. Data is fetched only once the model has been initialised.

Constructor Detail

JDOTableModel

protected JDOTableModel()
Default constructor. Cannot be directly instantiated.


JDOTableModel

public JDOTableModel(D model)
Create a new table model for objects of the specified type. Note that callers must invoke init() for table model to be initialised.

Parameters:
model - A dummy object used to initialise the table model. Note that the dummy object need not be a persistent instance.
See Also:
init()
Method Detail

init

public void init()
Initialise the table model. This method must be invoked by callers. This is enforced so enable callers to initialise the various properties such as DefaultPageableTableModel.pageSize, DefaultPageableTableModel.page etc. initially without forcing the model to refresh data from the data store.

Overrides:
init in class TableModel<D>
See Also:
TableModel.processColumns(), initTotalRows(), fetchData()

fetchRepository

protected Object fetchRepository()
                          throws Throwable
Fetch the repository class for the model.

Returns:
The repository class used to manage interactions with the data store.
Throws:
Throwable - If any errors are encountered while fetch the repository instance.

initTotalRows

protected void initTotalRows()
Initialise the DefaultPageableTableModel.totalRows field with the total number of persistent instances of model.


fetchData

protected void fetchData()
Fetch the data for the current DefaultPageableTableModel.page from the data store.

See Also:
setPageSize(int), setPage(int), sort( int ), fetchSortedData(), fetchUnsortedData(), AbstractTableModel.fireTableDataChanged()

fetchUnsortedData

protected void fetchUnsortedData()
Fetch the data for the current DefaultPageableTableModel.page from the data store. Note that this method assumes that clearing TableModel.data and firing table update events are handled by fetchData().

See Also:
setPageSize(int), setPage(int)

fetchSortedData

protected void fetchSortedData()
Fetch the data for the current DefaultPageableTableModel.page from the data store sorted by AbstractTableModel.sortIndex in AbstractTableModel.sortDirection. Note that this method assumes that clearing TableModel.data and firing table update events are handled by fetchData(). If the data store throws an exception when sorting using this method (complex sorting requires special JDOQL that is not supported by this method), then sorting is done through the sortData() method after refreshing the data using fetchUnsortedData().

See Also:
sort( int ), SortableTableModel.sort( int, Direction )

sortData

protected void sortData()
Perform a default sort of the displayable data since the column selected cannot be sorted through the data store.


setPage

public void setPage(int page)
Sets the value of DefaultPageableTableModel.page.

Specified by:
setPage in interface PageableTableModel
Parameters:
page - The current page of data to load in the model.
See Also:
PageableTableModel.setPage(int), fetchData()

setPageSize

public void setPageSize(int pageSize)
Sets the value of DefaultPageableTableModel.pageSize.

Specified by:
setPageSize in interface PageableTableModel
Parameters:
pageSize - The number of rows to display in the model.
Throws:
RuntimeException - If SQLException is raised by fetchData().
See Also:
PageableTableModel.setPageSize(int), fetchData()

sort

public void sort(int column)
Sort the data by the values in the specified column index. Fetch the data sorted by the specified column and set to the first page.

Specified by:
sort in interface SortableTableModel
Parameters:
column - The index of the column by which the data is to be sorted.
See Also:
AbstractTableModel.getSortDirection(int), SortableTableModel.sort( int, Direction )

sort

public void sort(int column,
                 SortableTableModel.Direction direction)
Sort the data by the values in the specified column index. Fetch the data sorted by the specified column and set to the first page.

Specified by:
sort in interface SortableTableModel
Parameters:
column - The index of the column by which the data is to be sorted.
direction - The direction of sorting to be applied.
See Also:
AbstractTableModel.fireTableDataChanged()

addRow

public void addRow(D row)
Add the specified object to the end of the model. Over-ridden to update DefaultPageableTableModel.totalRows.

Overrides:
addRow in class TableModel<D>
Parameters:
row - The data object that is to be added to the model.
See Also:
TableModel.addRow(D)

insertRow

public void insertRow(int row,
                      D rowData)
Insert the specified object at the specified row index into the model. Over-ridden to update DefaultPageableTableModel.totalRows.

Overrides:
insertRow in class TableModel<D>
Parameters:
row - The index at which the object is to be inserted.
rowData - The object that is to be added to the model.
See Also:
TableModel.insertRow(int, D)

deleteRow

public void deleteRow(int row)
Delete the specified row from the model. Over-ridden to properly update the pagination control data.

Overrides:
deleteRow in class TableModel<D>
Parameters:
row - The index of the row that is to be deleted.
See Also:
TableModel.deleteRow( int ), initTotalRows(), fetchData()

SPT Core API