|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.jdnc.DataLoader
org.jdesktop.jdnc.table.TableModelExtTextLoader
public class TableModelExtTextLoader
Data loader class which reads data from a text input stream and loads it into a DefaultTableModelExt instance. Common examples of tabular text data are comma-separated-values (CSV) and tab-separated-values (TSV) files.
Each line of text in the data stream is treated as a single row of data in
the tabular data model. A line is considered to be terminated by any one
of a line feed ('\n'), a carriage return ('\r'), or a carriage return
followed immediately by a linefeed. Within each row, column values are
delimited by a regular expression string, which is a configurable
"columnDelimiter" property on the Loader class. The default
column delimiter is a tab ('\t')
character.
Some text files encode the column names as the first row of data, thus this loader class supports a configurable "columnNamesInFirstRow" boolean property.
This class supports loading the data into the model in increments so that it may be displayed immediately, rather than waiting until the entire stream has been read. The number of rows in an increment can be specified via the "blockIncrementSize" property.
The following example configures a TableModelExtTextLoader to read CSV formatted data at the URL location, "http://myapp/employees.csv", and load the data by roughly 75 line increments:
DefaultTableModelExt data = new DefaultTableModelExt("http://myapp/employees.csv");
TableModelExtTextLoader loader = new TableModelExtTextLoader(",", false, 75);
data.setLoader(loader);
data.startLoading();
Note that properties on a TableModelExtTextLoader instance should not be modified while a load operation is executing, else synchronization errors will occur.
Field Summary |
---|
Fields inherited from class org.jdesktop.jdnc.DataLoader |
---|
READER_PRIORITY_KEY |
Constructor Summary | |
---|---|
TableModelExtTextLoader()
Creates a TableModelExtTextLoader object with a default tab ('\t') column delimeter, "columnNameInFirstRow" set to false , and
a default block increment size of 50. |
|
TableModelExtTextLoader(java.lang.String columnDelimiter,
boolean isFirstRowHeader,
int blockIncrementSize)
Creates a TableModelExtTextLoader object with the specified column delimiter, "columnNamesInFirstRow" value, and block increment size. |
Method Summary | |
---|---|
int |
getBlockIncrementSize()
|
java.lang.String |
getColumnDelimiter()
|
boolean |
isFirstRowHeader()
|
protected void |
loadData(java.lang.Object model)
Invoked internally once the readData method calls
scheduleLoad to schedule the loading of an increment of
data to the model. |
void |
loadMetaData(java.lang.Object model,
java.io.InputStream is)
Initializes the the number of columns in the tabular data model by reading the first line in the stream and counting the columns. |
protected void |
readData(java.io.InputStream is)
Invoked by the startLoading method. |
void |
setBlockIncrementSize(int blockIncrementSize)
Sets the "blockIncrementSize" property. |
void |
setColumnDelimiter(java.lang.String regex)
Sets the "columnDelimiter" property. |
void |
setFirstRowHeader(boolean isFirstRowHeader)
Sets the "isFirstRowHeader" property. |
void |
startLoading(java.lang.Object model,
java.io.InputStream is)
Starts the asynchronous load operation by spinning up a separate thread that will read the data from the input stream. |
Methods inherited from class org.jdesktop.jdnc.DataLoader |
---|
addMessageListener, addProgressListener, fireException, fireMessage, fireProgressEnded, fireProgressIncremented, fireProgressStarted, getMessageListeners, getProgressListeners, getReaderThreadPriority, removeMessageListener, removeProgressListener, scheduleLoad |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TableModelExtTextLoader()
false
, and
a default block increment size of 50.
public TableModelExtTextLoader(java.lang.String columnDelimiter, boolean isFirstRowHeader, int blockIncrementSize)
columnDelimiter
- regular expression string used to delimit column
values within a rowisFirstRowHeader
- boolean indicating whether the first row
should be treated as the column header namesblockIncrementSize
- integer indicating the number of rows to be read
between incremental load requestsMethod Detail |
---|
public java.lang.String getColumnDelimiter()
public void setColumnDelimiter(java.lang.String regex)
regex
- regular expression string used to delimit column
values within a rowpublic boolean isFirstRowHeader()
public void setFirstRowHeader(boolean isFirstRowHeader)
isFirstRowHeader
- boolean indicating whether the first row
should be treated as header column namespublic int getBlockIncrementSize()
public void setBlockIncrementSize(int blockIncrementSize)
blockIncrementSize
- integer indicating the number of rows to be read
between incremental load requestspublic void loadMetaData(java.lang.Object model, java.io.InputStream is) throws java.io.IOException
true
then this
method will also initialize the column names for the tabular data model
with the column values contained in the first line of the stream.
This method is synchronous and may be invoked from the event dispatch thread.
loadMetaData
in class DataLoader
model
- the tabular data model being loaded from the input streamis
- the input stream containing the meta-data
java.io.IOException
- if errors occur while reading from the stream
java.lang.ClassCastException
- if the model is not an instance of DefaultTableModelExtpublic void startLoading(java.lang.Object model, java.io.InputStream is)
startLoading
is called and must not be modified while the load operation executes,
otherwise synchronization errors will occur.
startLoading
in class DataLoader
model
- the data model being loaded from the input streamis
- the input stream containing the dataDataLoader.addProgressListener(org.jdesktop.swingx.event.ProgressListener)
protected void readData(java.io.InputStream is) throws java.io.IOException, ConversionException
startLoading
method. This method will be
called on a separate "reader" thread. This method will invoke
scheduleLoad
between reading each incremental block of rows.
This reader will use the "elementClass" and "Converter"
properties on a given column's meta-data object in order to convert the
data from string to object values.
readData
in class DataLoader
is
- the input stream containing the data
java.io.IOException
- if errors occur while reading data from the input stream
ConversionException
- if errors occur while converting data values from
string to objectDataLoader.scheduleLoad()
protected void loadData(java.lang.Object model)
readData
method calls
scheduleLoad
to schedule the loading of an increment of
data to the model. This method is called on the event dispatch
thread, therefore it will add the current list of rows read to the
tabular data model. After the data is added to the model, it will
fire a progress event to indicate whether the load operation is complete.
loadData
in class DataLoader
model
- the data model being loaded from the input stream
java.lang.ClassCastException
- if model is not an instance of DefaultTableModelExtDataLoader.fireProgressStarted(int, int)
,
DataLoader.fireProgressEnded()
,
DataLoader.fireException(java.lang.Throwable)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |