|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.ricebridge.csvman.LineListenerSupportImpl
com.ricebridge.csvman.CustomLineListener
com.ricebridge.csvman.HeadersListenerSupport
com.ricebridge.csvman.TableModelLineListener
An implementation of LineListener that inserts loaded data lines
into a TableModel.
You can then use this TableModel directly with a
JTable to create a tabular display of your data..
The easiest way to get your CSV data as a TableModel is to use the
CsvManager.loadTableModel method.
You can find more information about the TableModel implementation here: CsvTableModel.
TableModelLineListener is designed to be subclassed. You can change
the default implementation by calling the
CsvManagerStore.setTableModelLineListenerClass
method, and providing a subclass of
TableModelLineListener. CsvManagerStore can be accessed
using CsvManager.getCsvManagerStore().
The Source Code of this Java class is available under a BSD-style license.
LineListener,
CustomLineListener,
BasicLineListener,
AsListsLineListener,
ResultSetLineListener,
BeanLineListener| Field Summary | |
static boolean |
DEFAULT_TableModel_dataHasHeaders
Default value of TableModel.dataHasHeaders). |
static boolean |
DEFAULT_TableModel_editable
Default value of TableModel.editable). |
protected CsvTableModel |
iCsvTableModel
TableModel instance to hold CSV data |
protected Class |
iCsvTableModelClass
TableModel implementation class used to create new instances. |
protected boolean |
iDataHasHeaders
When true, the first line of CSV data should be a header line specifying the data field names. |
protected boolean |
iEditable
Make the TableModel editable. |
protected int |
iNumFields
Number of data fields. |
protected boolean |
iPropEditable
When true, the TableModel returned will be editable. |
static String |
PROP_TableModel_dataHasHeaders
Specify that the first row of data is a header line containing the names of the data fields (name for CsvSpec.setProperty: TableModel.dataHasHeaders). |
static String |
PROP_TableModel_editable
Specify that table cells can be edited (name for CsvSpec.setProperty: TableModel.editable). |
| Fields inherited from class com.ricebridge.csvman.HeadersListenerSupport |
iHasHeaders |
| Constructor Summary | |
TableModelLineListener()
|
|
| Method Summary | |
CsvTableModel |
getCsvTableModel()
Get the new CsvTableModel instance containing the CSV data. |
protected BadLine |
handleLineImpl(String[] pLine,
int pNumFields,
long pLineNumber,
String pOriginalLine)
Add the data line String[] array to the list of TableModel rows. |
protected void |
setCsvSpecImpl(CsvSpec pCsvSpec)
Handle property settings for loading data into TableModel. |
void |
setCsvTableModelClass(Class pCsvTableModelClass)
Use your own subclass of CsvTableModel for loading CSV data. |
void |
setEditable(boolean pEditable)
Make the TableModel editable. |
void |
setHasHeaders(boolean pHasHeaders)
The data cells of the first line of the CSV file may be column headers. |
protected void |
startProcessImpl()
Start the load process. |
| Methods inherited from class com.ricebridge.csvman.HeadersListenerSupport |
getHasHeaders |
| Methods inherited from class com.ricebridge.csvman.CustomLineListener |
endProcessImpl, handleBadLineImpl, setLineSpecImpl |
| Methods inherited from class com.ricebridge.csvman.LineListenerSupportImpl |
endProcess, handleBadLine, handleLine, setCsvSpec, setLineSpec, startProcess |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final String PROP_TableModel_dataHasHeaders
CsvSpec.setProperty: TableModel.dataHasHeaders).
public static final boolean DEFAULT_TableModel_dataHasHeaders
TableModel.dataHasHeaders).
public static final String PROP_TableModel_editable
CsvSpec.setProperty: TableModel.editable).
public static final boolean DEFAULT_TableModel_editable
TableModel.editable).
protected Class iCsvTableModelClass
TableModel implementation class used to create new instances.
protected CsvTableModel iCsvTableModel
TableModel instance to hold CSV data
protected boolean iEditable
TableModel editable. See setEditable(boolean).
protected int iNumFields
protected boolean iDataHasHeaders
true, the first line of CSV data should be a header line specifying the data field names.
protected boolean iPropEditable
true, the TableModel returned will be editable.
| Constructor Detail |
public TableModelLineListener()
| Method Detail |
protected void setCsvSpecImpl(CsvSpec pCsvSpec)
throws Exception
TableModel.
You can change these using CsvSpec.
Compatibility note: the correct way to change the settings for a LineListener is by using the
CsvSpec.setProperty method. CSV Manager 1.1 also allowed you to set certain
settings as load method parameters (for example: pHasHeaders
in CsvManager.loadTableModel(File, 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 properties you can use here are: PROP_TableModel_dataHasHeaders and
PROP_TableModel_editable.
setCsvSpecImpl in class CustomLineListenerpCsvSpec - CsvSpec object
ExceptionLineListener.setCsvSpec(com.ricebridge.csvman.CsvSpec),
PROP_TableModel_dataHasHeaders
protected void startProcessImpl()
throws Exception
startProcessImpl in class CustomLineListenerExceptionLineListener.startProcess()
protected BadLine handleLineImpl(String[] pLine,
int pNumFields,
long pLineNumber,
String pOriginalLine)
throws Exception
String[] array to the list of TableModel rows.
handleLineImpl in class CustomLineListenerpLine - String values of data fields in linepNumFields - Number of data fields actually found on the current linepLineNumber - Count of lines processed so far.pOriginalLine - Text of original data line from data source
null if line is OK, BadLine object if line was bad in some way
ExceptionLineListener.handleLine,
BadLine,
handleBadLineImplpublic void setHasHeaders(boolean pHasHeaders)
When pHasHeaders is true, the first line of the CSV file
is considered to consist of column header names rather than normal data.
When pHasHeaders is false, the first line of the CSV file
is considered to be normal data and default column names are used.
In the case where there are no column names, or not enough column names, the default form Column X is used, where X is the number of the column, counting from 1.
Compatibility note: please use CsvSpec.setProperty to set
this setting instead of this method, which will be remove in CSV Manager 1.2. See
setCsvSpecImpl for more details.
setHasHeaders in class HeadersListenerSupportpHasHeaders - first line is header namesCsvTableModel.setHasHeaders,
setCsvSpecImplpublic void setEditable(boolean pEditable)
TableModel editable.
When true, the method TableModel interface method
TableModel.isCellEditable(int, int)
returns true for every table cell. This makes the JTable editable.
When false, the JTable is not editable.
pEditable - make the JTable editableCsvTableModel.setEditable(boolean)public void setCsvTableModelClass(Class pCsvTableModelClass)
CsvTableModel for loading CSV data.
You may subclass CsvTableModel so that the CSV data is loaded into your own TableModel.
You will need to provide an empty constructor so that the newInstance method will work. You
must also provide, via this method, the class of your TableModel. Do this like so:
csvManager.getCsvManagerStore()
.getTableModelLineListener().setCsvTableModelClass( MyCsvTableModel.class );
If subclassing does not fit with your requirements, consider implementing your own variation of
CsvTableModel (source) and
TableModelLineListener (source)
based on the source code provided as part of this API documentation.
pCsvTableModelClass - class of CsvTableModel subclassCsvTableModelpublic CsvTableModel getCsvTableModel()
CsvTableModel instance containing the CSV data.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||