com.ricebridge.xmlman.in
Class XmlTableModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended bycom.ricebridge.xmlman.in.XmlTableModel
All Implemented Interfaces:
Serializable, TableModel

public class XmlTableModel
extends AbstractTableModel
implements TableModel

Implementation of a TableModel to hold XML record 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.

See Also:
Serialized Form

Field Summary
protected  ArrayList iData
          Table data as a List of String[] arrays.
protected  boolean iDataHasHeaders
          The first line of the CSV file may contain headers.
protected  boolean iEditable
          The table may be editable.
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
XmlTableModel()
          Support Class.newInstance() object instantiation.
XmlTableModel(List pData)
          Create a new TableModel with specified a List of String[] arrays.
 
Method Summary
 void addRecord(String[] pRecord)
          Add a record to the internal data containers for this TableModel.
 void clear()
          Clear all data from table.
 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 XML record data.
 boolean isCellEditable(int pRow, int pColumn)
          Indicate that table cell value can be changed.
 void setDataHasHeaders(boolean pDataHasHeaders)
          The data provided via addRecord(java.lang.String[]) includes column headers.
 void setEditable(boolean pEditable)
          You can use this setting to make your JTable editable.
 void setHeaders(String[] pHeaders)
           
 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

iEditable

protected boolean iEditable
The table may be editable.


iDataHasHeaders

protected boolean iDataHasHeaders
The first line of the CSV file may contain headers.


iHeadersStored

protected boolean iHeadersStored
Flag to indicate that headers have been loaded.


iHeaders

protected List iHeaders
List of headers as Strings.


iData

protected ArrayList iData
Table data as a List of String[] arrays.


iMaxNumFields

protected int iMaxNumFields
Maximum number of fields encountered.

Constructor Detail

XmlTableModel

public XmlTableModel()
Support Class.newInstance() object instantiation.


XmlTableModel

public XmlTableModel(List pData)
Create a new TableModel with specified a List of String[] arrays.

Method Detail

init

public void init()
Initialise the internal data containers before loading new XML record data.


addRecord

public void addRecord(String[] pRecord)
Add a record to the internal data containers for this TableModel.

Parameters:
pRecord - data fields

setDataHasHeaders

public void setDataHasHeaders(boolean pDataHasHeaders)
The data provided via addRecord(java.lang.String[]) includes column headers.

When true, the first call to addRecord is assumed to be the list of column headers.

When false, the table has no headers.

You can access this setting like so:

  XmlSpec xmlspec = xmlManager.getXmlSpec();
  xmlSpec.setProperty( "TableModel.dataDataHasHeaders", true );
  

Parameters:
pDataHasHeaders - data has headers
See Also:
XmlManager.loadTableModel(File,RecordSpec)

setHeaders

public void setHeaders(String[] pHeaders)

setEditable

public void setEditable(boolean pEditable)
You can use this setting to make your JTable editable.

When true, the table cells can be edited.

When false, the table cell cannot be edited.

You can access this setting like so:

  XmlSpec xmlspec = xmlManager.getXmlSpec();
  xmlSpec.setProperty( "TableModel.editable", true );
  

Parameters:
pEditable - editable table

clear

public void clear()
Clear all data from table.


getColumnName

public String getColumnName(int pIndex)
Get the name of the column.

Specified by:
getColumnName in interface TableModel
Parameters:
pIndex - index of column (from zero)

getRowCount

public int getRowCount()
Get number of rows in table.

Specified by:
getRowCount in interface TableModel

getColumnCount

public int getColumnCount()
Get number of columns in table.

Specified by:
getColumnCount in interface TableModel

getValueAt

public Object getValueAt(int pRow,
                         int pColumn)
Get the value of a table cell.

Specified by:
getValueAt in interface TableModel
Parameters:
pRow - index of row (from zero)
pColumn - index of column (from zero)

isCellEditable

public boolean isCellEditable(int pRow,
                              int pColumn)
Indicate that table cell value can be changed.

Specified by:
isCellEditable in interface TableModel
Parameters:
pRow - index of row (from zero)
pColumn - index of column (from zero)

setValueAt

public void setValueAt(Object pValue,
                       int pRow,
                       int pColumn)
Set the value of a table cell.

Specified by:
setValueAt in interface TableModel
Parameters:
pValue - new value of cell
pRow - index of row (from zero)
pColumn - index of column (from zero)

toString

public String toString()
String description of object instance.



Copyright © 2004-2005 Ricebridge