org.bsf.remoteIterator.client.tableModel
Class DefaultRemoteIteratorTableModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended byorg.bsf.remoteIterator.client.tableModel.DefaultRemoteIteratorTableModel
All Implemented Interfaces:
RemoteIteratorTableModel, java.io.Serializable, javax.swing.table.TableModel

public class DefaultRemoteIteratorTableModel
extends javax.swing.table.AbstractTableModel
implements RemoteIteratorTableModel

A default implementation of a RemoteIteratorTableModel. You can look at it (or extend it) to build your own TableModel. A smart move is to add a static method that, when called, removes all the RI that are still active when called.

See Also:
Serialized Form

Field Summary
private  int _defaultBlockSize
           
private  int _delayBetweenRetrieval
           
private  int _initialBlockSize
           
private  BackgroundLoadingThread _loadingThread
           
private  java.util.Vector _rows
          Holds the rows returned by the RI.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DefaultRemoteIteratorTableModel()
          Creates a DefaultRemoteIteratorTableModel with a default estimated size of 1000 rows.
DefaultRemoteIteratorTableModel(int p_estimatedSize)
          Creates a DefaultRemoteIteratorTableModel with the given int as the size of the underlying List storing the rows.
DefaultRemoteIteratorTableModel(RemoteIteratorClient p_remoteIteratorClient)
          Creates a DefaultRemoteIteratorTableModel with a default estimated size of 1000 rows.
DefaultRemoteIteratorTableModel(RemoteIteratorClient p_remoteIteratorClient, int p_estimatedSize)
          Creates a DefaultRemoteIteratorTableModel with the given estimated size of rows.
 
Method Summary
 void addRows(java.util.Iterator p_rowIterator)
           
static void cleanUp()
          Removes all the remaining RI.
 int getColumnCount()
           
 int getDefaultBlockSize()
           
 int getDelayBetweenRetrieval()
           
 int getInitialBlockSize()
           
 int getRowCount()
           
 java.lang.Object getValueAt(int p_rowIndex, int p_columnIndex)
           
 boolean isLoadingData()
           
 void releaseResources()
          Releases the resources (RemoteIterator is first among them but the Threads used (if any) by the implementing model should be released as well.
 void setDefaultBlockSize(int p_defaultBlockSize)
           
 void setDelayBetweenRetrieval(int p_delayBetweenRetrieval)
          Sets the delay between each call to the RI (could be used when multiple models are accessing various RI to prevent locks because some model are calling next() all the time...).
 void setInitialBlockSize(int p_initialBlockSize)
           
 void setRemoteIteratorClient(RemoteIteratorClient p_remoteIteratorClient)
          Specifies what RemoteIteratorClient is to be used by the implementing TableModel.
 void startLoadingData()
          Request this model to start loading the data.
 void stopLoadingData()
          Request this model to stop loading data.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
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, getColumnClass, getColumnName, isCellEditable, removeTableModelListener, setValueAt
 

Field Detail

_initialBlockSize

private int _initialBlockSize

_defaultBlockSize

private int _defaultBlockSize

_delayBetweenRetrieval

private int _delayBetweenRetrieval

_loadingThread

private BackgroundLoadingThread _loadingThread

_rows

private java.util.Vector _rows
Holds the rows returned by the RI.

Constructor Detail

DefaultRemoteIteratorTableModel

public DefaultRemoteIteratorTableModel()
Creates a DefaultRemoteIteratorTableModel with a default estimated size of 1000 rows. Anyway, the underlying container will be trimmed to size when all the rows will have been loaded.

See Also:
DefaultRemoteIteratorTableModel( int p_estimatedSize )

DefaultRemoteIteratorTableModel

public DefaultRemoteIteratorTableModel(RemoteIteratorClient p_remoteIteratorClient)
Creates a DefaultRemoteIteratorTableModel with a default estimated size of 1000 rows. Anyway, the underlying container will be trimmed to size when all the rows will have been loaded. The provided RemoteIteratorClient is used and the loading is started.

Parameters:
p_remoteIteratorClient - The RemoteIteratorClient to use for data loading.
See Also:
DefaultRemoteIteratorTableModel( int p_estimatedSize ), RemoteIteratorClient

DefaultRemoteIteratorTableModel

public DefaultRemoteIteratorTableModel(int p_estimatedSize)
Creates a DefaultRemoteIteratorTableModel with the given int as the size of the underlying List storing the rows. The increase value will use the given int as well. Anyway, the underlying container will be trimmed to size when all the rows will have been loaded.

Parameters:
p_estimatedSize - The size and the increase number to use for the underlying List storing the* rows. Should be used to prevent on-going resize of the List. No check is done on this value which, obviously, should be greater than 0.

DefaultRemoteIteratorTableModel

public DefaultRemoteIteratorTableModel(RemoteIteratorClient p_remoteIteratorClient,
                                       int p_estimatedSize)
Creates a DefaultRemoteIteratorTableModel with the given estimated size of rows. Anyway, the underlying container will be trimmed to size when all the rows will have been loaded. The provided RemoteIteratorClient is used and the loading is started.

Parameters:
p_remoteIteratorClient - The RemoteIteratorClient to use for data loading.
p_estimatedSize - The size and the increase number to use for the underlying List storing the* rows. Should be used to prevent on-going resize of the List. No check is done on this value which, obviously, should be greater than 0.
See Also:
DefaultRemoteIteratorTableModel( int p_estimatedSize ), RemoteIteratorClient
Method Detail

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

getValueAt

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

setRemoteIteratorClient

public void setRemoteIteratorClient(RemoteIteratorClient p_remoteIteratorClient)
Description copied from interface: RemoteIteratorTableModel
Specifies what RemoteIteratorClient is to be used by the implementing TableModel.

Specified by:
setRemoteIteratorClient in interface RemoteIteratorTableModel
Parameters:
p_remoteIteratorClient - The RemoteIteratorClient to use.

startLoadingData

public void startLoadingData()
Description copied from interface: RemoteIteratorTableModel
Request this model to start loading the data.

Specified by:
startLoadingData in interface RemoteIteratorTableModel

stopLoadingData

public void stopLoadingData()
Description copied from interface: RemoteIteratorTableModel
Request this model to stop loading data.

Specified by:
stopLoadingData in interface RemoteIteratorTableModel

isLoadingData

public boolean isLoadingData()
Specified by:
isLoadingData in interface RemoteIteratorTableModel
Returns:
true if the model is loading data in the background, false otherwise.

releaseResources

public void releaseResources()
Description copied from interface: RemoteIteratorTableModel
Releases the resources (RemoteIterator is first among them but the Threads used (if any) by the implementing model should be released as well.

Specified by:
releaseResources in interface RemoteIteratorTableModel

getDefaultBlockSize

public int getDefaultBlockSize()
Returns:
the default block size (the size of the returned block, but the first one).
See Also:
setDefaultBlockSize(int), setInitialBlockSize(int)

setDefaultBlockSize

public void setDefaultBlockSize(int p_defaultBlockSize)
See Also:
getDefaultBlockSize()

getInitialBlockSize

public int getInitialBlockSize()
Returns:
the initialBlockSize (the size of the first returned block, should be small to accelerate data display to the user...).
See Also:
setInitialBlockSize(int)

setInitialBlockSize

public void setInitialBlockSize(int p_initialBlockSize)
See Also:
getInitialBlockSize()

getDelayBetweenRetrieval

public int getDelayBetweenRetrieval()
Returns:
The delay, in ms, between two calls to next() on the RemoteIterator. Default value is 0.
See Also:
setDelayBetweenRetrieval(int)

setDelayBetweenRetrieval

public void setDelayBetweenRetrieval(int p_delayBetweenRetrieval)
Sets the delay between each call to the RI (could be used when multiple models are accessing various RI to prevent locks because some model are calling next() all the time...).

Parameters:
p_delayBetweenRetrieval - in ms.

addRows

public void addRows(java.util.Iterator p_rowIterator)
Parameters:
p_rowIterator - should not be null... Used by the background loading thread to add rows to the model.

cleanUp

public static void cleanUp()
Removes all the remaining RI. Usually called when the application is exiting because, even though a stop is requested, some threads might be sleeping and the application will quit BEFORE the RI are removed (it might give some troubles to the server).