com.ricebridge.csvman
Class TableModelLineProvider

java.lang.Object
  extended bycom.ricebridge.csvman.LineProviderSupportImpl
      extended bycom.ricebridge.csvman.CustomLineProvider
          extended bycom.ricebridge.csvman.TableModelLineProvider
All Implemented Interfaces:
LineProvider

public class TableModelLineProvider
extends CustomLineProvider

An implementation of LineProvider that provides data lines for saving from a TableModel object.

The easiest way to save your CSV data using this format is to use the CsvManager.saveTableModel method. You can get a TableModel from a JTable using the JTable.getModel method.

TableModelLineProvider is designed to be subclassed. You can change the default implementation by calling the CsvManagerStore.setTableModelLineProviderClass method, and providing a subclass of TableModelLineProvider. CsvManagerStore can be accessed using CsvManager.getCsvManagerStore().

The Source Code of this Java class is available under a BSD-style license.

See Also:
LineProvider, CustomLineProvider, BasicLineProvider, AsListsLineProvider, ResultSetLineProvider, BeanLineProvider

Field Summary
static boolean DEFAULT_TableModel_saveHeaders
          Default value of TableModel.saveHeaders (false).
protected  int iFieldCount
          Number of data fields per line.
protected  boolean iFirstLine
          Flag to indicate processing of the first line.
protected  String[] iHeaders
          The column headers
protected  long iLineIndex
          Current line.
protected  boolean iSaveHeaders
          Save the column headers to the CSV file.
protected  TableModel iTableModel
          The TableModel that the data comes from.
static String PROP_TableModel_saveHeaders
          Save the TableModel column names as the first line of the CSV file.
 
Constructor Summary
TableModelLineProvider()
          Create uninitialised for use with setTableModel(javax.swing.table.TableModel, boolean).
TableModelLineProvider(TableModel pTableModel, boolean pSaveHeaders)
          Create initialised.
 
Method Summary
 boolean hasNextLineImpl()
          Return true if TableModel contains more rows.
 String[] nextLineImpl()
          Return the current row of the TableModel as a String[] array.
protected  void setCsvSpecImpl(CsvSpec pCsvSpec)
          Handle property settings for loading data from a TableModel.
 void setTableModel(TableModel pTableModel, boolean pSaveHeaders)
          Set the TableModel providing data to save.
 void startProcessImpl()
          Start the saving process.
 
Methods inherited from class com.ricebridge.csvman.CustomLineProvider
endProcessImpl, setLineSpecImpl
 
Methods inherited from class com.ricebridge.csvman.LineProviderSupportImpl
endProcess, hasNextLine, nextLine, setCsvSpec, setLineSpec, startProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_TableModel_saveHeaders

public static final String PROP_TableModel_saveHeaders
Save the TableModel column names as the first line of the CSV file. (name for CsvSpec.setProperty: TableModel.saveHeaders).

See Also:
Constant Field Values

DEFAULT_TableModel_saveHeaders

public static final boolean DEFAULT_TableModel_saveHeaders
Default value of TableModel.saveHeaders (false).

See Also:
Constant Field Values

iSaveHeaders

protected boolean iSaveHeaders
Save the column headers to the CSV file.


iTableModel

protected TableModel iTableModel
The TableModel that the data comes from.


iHeaders

protected String[] iHeaders
The column headers


iFirstLine

protected boolean iFirstLine
Flag to indicate processing of the first line.


iFieldCount

protected int iFieldCount
Number of data fields per line.


iLineIndex

protected long iLineIndex
Current line.

Constructor Detail

TableModelLineProvider

public TableModelLineProvider()
Create uninitialised for use with setTableModel(javax.swing.table.TableModel, boolean).


TableModelLineProvider

public TableModelLineProvider(TableModel pTableModel,
                              boolean pSaveHeaders)
Create initialised. See setTableModel(javax.swing.table.TableModel, boolean) for details.

Parameters:
pTableModel - TableModel providing data
pSaveHeaders - Save the TableModel headers as first line
Method Detail

setCsvSpecImpl

protected void setCsvSpecImpl(CsvSpec pCsvSpec)
                       throws Exception
Handle property settings for loading data from a TableModel.

You can change these using CsvSpec.

Compatibility note: the correct way to change the settings for a LineProvider is by using the CsvSpec.setProperty method. CSV Manager 1.1 also allowed you to set certain settings as save method parameters (for example: pHasHeaders in CsvManager.save(File, TableModel, boolean). These parameters will be removed in CSV Manager 2.0, so you should not use them anymore. They are only retained for compatibility with CSV Manager 1.1.

The property you can use here is: PROP_TableModel_saveHeaders.

Overrides:
setCsvSpecImpl in class CustomLineProvider
Parameters:
pCsvSpec - CsvSpec object
Throws:
Exception
See Also:
LineProvider.setCsvSpec(com.ricebridge.csvman.CsvSpec), PROP_TableModel_saveHeaders

startProcessImpl

public void startProcessImpl()
                      throws Exception
Start the saving process.

Overrides:
startProcessImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.startProcess()

hasNextLineImpl

public boolean hasNextLineImpl()
                        throws Exception
Return true if TableModel contains more rows.

Specified by:
hasNextLineImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.hasNextLine, nextLineImpl

nextLineImpl

public String[] nextLineImpl()
                      throws Exception
Return the current row of the TableModel as a String[] array.

Specified by:
nextLineImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.nextLine, hasNextLineImpl

setTableModel

public void setTableModel(TableModel pTableModel,
                          boolean pSaveHeaders)
Set the TableModel providing data to save.

The default number of fields per line is taken from TableModel.getColumnCount and the headers (output as the first line when PROP_TableModel_saveHeaders is true), are taken from TableModel.getColumnName.

Parameters:
pTableModel - TableModel providing data
pSaveHeaders - Save the TableModel headers as first line


Copyright © 2003-2006 Ricebridge