001 package com.sptci.rwt.webui;
002
003 import java.util.List;
004
005 import com.sptci.echo2.Dimensions;
006 import com.sptci.rwt.Row;
007 import com.sptci.rwt.Rows;
008
009 /**
010 * A custom table model used to display {@link com.sptci.rwt.Rows} object.
011 * This is used by the {@link BatchQueryExecutorView} to display each result
012 * obtained by executing a statement in the batch specified.
013 *
014 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
015 * @author Rakesh Vidyadharan 2007-10-12
016 * @version $Id: RowsTableModel.java 4123 2008-05-25 21:49:01Z rakesh $
017 */
018 public class RowsTableModel extends RowTableModel
019 {
020 /**
021 * The list used as the backing store for this model.
022 *
023 * @since Version 1.2
024 */
025 private final List<Row> rows;
026
027 /**
028 * Create a new instance of the table model using the specified model
029 * object.
030 *
031 * @see #setPageSize
032 * @see #processColumns
033 * @param rows The data backing this table model.
034 */
035 public RowsTableModel( final Rows rows )
036 {
037 super();
038 this.rows = rows.getRows();
039 totalRows = rows.getTotalRows();
040 setPageSize( Dimensions.getInt( this, "pageSize" ) );
041 processColumns();
042 }
043
044 /**
045 * Update the {@link #data} with the current page of data from {@link
046 * #rows}.
047 *
048 * @since Version 1.2
049 * @see nextapp.echo2.app.table.AbstractTableModel#fireTableDataChanged
050 * @see com.sptci.rwt.QueryExecutor
051 */
052 @Override
053 protected void fetchData()
054 {
055 final int start = ( page * pageSize );
056 int end = start + pageSize;
057 if ( end > totalRows ) end = (int) totalRows;
058 data.clear();
059
060 for ( int i = start; i < end; ++i )
061 {
062 data.add( rows.get( i ) );
063 }
064
065 fireTableDataChanged();
066 }
067 }