|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
com.ricebridge.csvman.CsvTableModel
Implementation of a TableModel to hold CSV data.
This TableModel can be used directly with a
JTable.
Data is represented by String objects, and can be editable.
Missing data is represented by an empty String in the table cell. You may subclass this class to provide
more functionality.
The Source Code of this Java class is available under a BSD-style license.
| Field Summary | |
protected ArrayList |
iData
Table data as a List of String[] arrays. |
protected boolean |
iEditable
The table may be editable. |
protected boolean |
iHasHeaders
The first line of the CSV file may contain headers. |
protected List |
iHeaders
List of headers as Strings. |
protected boolean |
iHeadersStored
Flag to indicate that headers have been loaded. |
protected int |
iMaxNumFields
Maximum number of fields encountered. |
| Fields inherited from class javax.swing.table.AbstractTableModel |
listenerList |
| Constructor Summary | |
CsvTableModel()
Support Class.newInstance object instantiation. |
|
CsvTableModel(List pData)
Create a new TableModel with specified a List of String[] arrays. |
|
| Method Summary | |
void |
addLine(String[] pLine,
int pNumFields)
Add a data line to the internal data containers for this TableModel. |
int |
getColumnCount()
Get number of columns in table. |
String |
getColumnName(int pIndex)
Get the name of the column. |
int |
getRowCount()
Get number of rows in table. |
Object |
getValueAt(int pRow,
int pColumn)
Get the value of a table cell. |
void |
init()
Initialise the internal data containers before loading new CSV data. |
boolean |
isCellEditable(int pRow,
int pColumn)
Indicate that table cell value can be changed. |
void |
setEditable(boolean pEditable)
You can use this setting to make your JTable editable. |
void |
setHasHeaders(boolean pHasHeaders)
The data provided via addLine(java.lang.String[], int) includes column headers. |
void |
setValueAt(Object pValue,
int pRow,
int pColumn)
Set the value of a table cell. |
String |
toString()
String description of object instance. |
| Methods inherited from class javax.swing.table.AbstractTableModel |
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface javax.swing.table.TableModel |
addTableModelListener, getColumnClass, removeTableModelListener |
| Field Detail |
protected boolean iEditable
protected boolean iHasHeaders
protected boolean iHeadersStored
protected List iHeaders
Strings.
protected ArrayList iData
List of String[] arrays.
protected int iMaxNumFields
| Constructor Detail |
public CsvTableModel()
public CsvTableModel(List pData)
TableModel with specified a List of String[] arrays.
| Method Detail |
public void init()
CsvManager object and
hence the same TableModelLineListener, the same CsvTableModel instance
will be used, so that this method must be called prior to loading new data.
TableModelLineListener calls this method in TableModelLineListener.startProcessImpl().
If you subclass this class to provide your own TableModel, you should provide your
own implementation of this method.
public void addLine(String[] pLine,
int pNumFields)
TableModel.
The parameter pNumFields indicates the number of actual data fields
found on the current line, which may be less that the number expected, thus pNumFields <= pLine.length.
The remaining members of pLine will be empty Strings.
pLine - data fieldspNumFields - number of actual data fieldspublic void setHasHeaders(boolean pHasHeaders)
addLine(java.lang.String[], int) includes column headers.
When true, the first call to addLine is assumed to be the list of column headers.
When false, the table has no headers.
pHasHeaders - data has headersTableModelLineListener.startProcessImpl(),
HeadersListenerSupport.setHasHeaders(boolean),
CsvManager.loadTableModel(File,boolean)public void setEditable(boolean pEditable)
You will need to access this object first, like so:
TableModelLineListener tmln
= csvManager.getCsvManagerStore().getTableModelLineListener();
tmln.setEditable( true );
pEditable - editable tablepublic String getColumnName(int pIndex)
getColumnName in interface TableModelpIndex - index of column (from zero)public int getRowCount()
getRowCount in interface TableModelpublic int getColumnCount()
getColumnCount in interface TableModel
public Object getValueAt(int pRow,
int pColumn)
getValueAt in interface TableModelpRow - index of row (from zero)pColumn - index of column (from zero)
public boolean isCellEditable(int pRow,
int pColumn)
isCellEditable in interface TableModelpRow - index of row (from zero)pColumn - index of column (from zero)
public void setValueAt(Object pValue,
int pRow,
int pColumn)
setValueAt in interface TableModelpValue - new value of cellpRow - index of row (from zero)pColumn - index of column (from zero)public String toString()
String description of object instance.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||