public class TableModel
extends java.lang.Object
Note that this is not a full MVC type model; the expected usage pattern is to create an empty table, add rows (by consulting the business model), sort rows (based on client request parameters), and finally produce the sorted list of rows.
The table also provides a mechanism for defining how cell values for a particular column should be formatted into strings, to help facilitate the encoding of the table data into a JSON structure.
Note that it is expected that all values for a particular column will be the same class.
Modifier and Type | Class and Description |
---|---|
class |
TableModel.Annot
Model of an annotation.
|
class |
TableModel.Row
Model of a row.
|
static class |
TableModel.SortDir
Designates sorting direction.
|
Constructor and Description |
---|
TableModel(java.lang.String... columnIds)
Constructs a table (devoid of data) with the given column IDs.
|
Modifier and Type | Method and Description |
---|---|
void |
addAnnotation(java.lang.String key,
java.lang.Object value)
Inserts a new annotation.
|
TableModel.Row |
addRow()
Adds a row to the table model.
|
int |
columnCount()
Returns the number of columns in this table model.
|
java.util.Collection<TableModel.Annot> |
getAnnotations()
Returns the annotations in this table.
|
java.lang.String[] |
getColumnIds()
Returns the array of column IDs for this table model.
|
CellFormatter |
getFormatter(java.lang.String columnId)
Returns the cell formatter to use on values in the specified column.
|
TableModel.Row[] |
getRows()
Returns the raw
TableModel.Row representation of the rows in this table. |
int |
rowCount()
Returns the number of rows in this table model.
|
void |
setComparator(java.lang.String columnId,
CellComparator comparator)
Sets a cell comparator for the specified column.
|
void |
setFormatter(java.lang.String columnId,
CellFormatter formatter)
Sets a cell formatter for the specified column.
|
void |
sort(java.lang.String id1,
TableModel.SortDir dir1,
java.lang.String id2,
TableModel.SortDir dir2)
Sorts the table rows based on the specified columns, in the
specified directions.
|
static TableModel.SortDir |
sortDir(java.lang.String s)
Returns the appropriate sort direction for the given string.
|
public TableModel(java.lang.String... columnIds)
columnIds
- column identifierspublic int rowCount()
public int columnCount()
public java.lang.String[] getColumnIds()
Implementation note: we are knowingly passing you a reference to our internal array to avoid copying. Don't mess with it. It's your table you'll break if you do!
public TableModel.Row[] getRows()
TableModel.Row
representation of the rows in this table.public void addAnnotation(java.lang.String key, java.lang.Object value)
key
- key of annotationvalue
- value of annotationpublic java.util.Collection<TableModel.Annot> getAnnotations()
public void setComparator(java.lang.String columnId, CellComparator comparator)
columnId
- column identifiercomparator
- comparator to usepublic void setFormatter(java.lang.String columnId, CellFormatter formatter)
columnId
- column identifierformatter
- formatter to usepublic CellFormatter getFormatter(java.lang.String columnId)
columnId
- column identifierpublic TableModel.Row addRow()
public void sort(java.lang.String id1, TableModel.SortDir dir1, java.lang.String id2, TableModel.SortDir dir2)
id1
- first column identifierdir1
- first column sort directionid2
- second column identifier (may be null)dir2
- second column sort direction (may be null)public static TableModel.SortDir sortDir(java.lang.String s)
The expected strings are "asc" for ascending
and
"desc" for descending
. Any other value will
default to ascending.
s
- sort direction string encoding