public class TableModel extends 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.Row
Model of a row.
|
static class |
TableModel.SortDir
Designates sorting direction.
|
| Constructor and Description |
|---|
TableModel(String... columnIds)
Constructs a table (devoid of data) with the given column IDs.
|
| Modifier and Type | Method and Description |
|---|---|
TableModel.Row |
addRow()
Adds a row to the table model.
|
int |
columnCount()
Returns the number of columns in this table model.
|
String[] |
getColumnIds()
Returns the array of column IDs for this table model.
|
CellFormatter |
getFormatter(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(String columnId,
CellComparator comparator)
Sets a cell comparator for the specified column.
|
void |
setFormatter(String columnId,
CellFormatter formatter)
Sets a cell formatter for the specified column.
|
void |
sort(String columnId,
TableModel.SortDir dir)
Sorts the table rows based on the specified column, in the
specified direction.
|
static TableModel.SortDir |
sortDir(String s)
Returns the appropriate sort direction for the given string.
|
public TableModel(String... columnIds)
columnIds - column identifierspublic int rowCount()
public int columnCount()
public 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 setComparator(String columnId, CellComparator comparator)
columnId - column identifiercomparator - comparator to usepublic void setFormatter(String columnId, CellFormatter formatter)
columnId - column identifierformatter - formatter to usepublic CellFormatter getFormatter(String columnId)
columnId - column identifierpublic TableModel.Row addRow()
public void sort(String columnId, TableModel.SortDir dir)
columnId - column identifierdir - sort directionpublic static TableModel.SortDir sortDir(String s)
The expected strings are "asc" for ascending and
"desc" for descending. Any other value will
default to ascending.
s - sort direction string encodingCopyright © 2015. All rights reserved.