Class TableModel
- java.lang.Object
-
- org.onosproject.ui.table.TableModel
-
public class TableModel extends java.lang.Object
A simple model of table data.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
TableModel.Annot
Model of an annotation.class
TableModel.Row
Model of a row.static class
TableModel.SortDir
Designates sorting direction.
-
Constructor Summary
Constructors Constructor Description TableModel(java.lang.String... columnIds)
Constructs a table (devoid of data) with the given column IDs.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 rawTableModel.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.
-
-
-
Method Detail
-
rowCount
public int rowCount()
Returns the number of rows in this table model.- Returns:
- number of rows
-
columnCount
public int columnCount()
Returns the number of columns in this table model.- Returns:
- number of columns
-
getColumnIds
public java.lang.String[] getColumnIds()
Returns the array of column IDs for this table model.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!
- Returns:
- the column identifiers
-
getRows
public TableModel.Row[] getRows()
Returns the rawTableModel.Row
representation of the rows in this table.- Returns:
- raw table rows
-
addAnnotation
public void addAnnotation(java.lang.String key, java.lang.Object value)
Inserts a new annotation.- Parameters:
key
- key of annotationvalue
- value of annotation
-
getAnnotations
public java.util.Collection<TableModel.Annot> getAnnotations()
Returns the annotations in this table.- Returns:
- annotations
-
setComparator
public void setComparator(java.lang.String columnId, CellComparator comparator)
Sets a cell comparator for the specified column.- Parameters:
columnId
- column identifiercomparator
- comparator to use
-
setFormatter
public void setFormatter(java.lang.String columnId, CellFormatter formatter)
Sets a cell formatter for the specified column.- Parameters:
columnId
- column identifierformatter
- formatter to use
-
getFormatter
public CellFormatter getFormatter(java.lang.String columnId)
Returns the cell formatter to use on values in the specified column.- Parameters:
columnId
- column identifier- Returns:
- an appropriate cell formatter
-
addRow
public TableModel.Row addRow()
Adds a row to the table model.- Returns:
- the row, for chaining
-
sort
public 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. The second column is optional, and can be disregarded by passing null into id2 and dir2.- Parameters:
id1
- first column identifierdir1
- first column sort directionid2
- second column identifier (may be null)dir2
- second column sort direction (may be null)
-
sortDir
public static TableModel.SortDir sortDir(java.lang.String s)
Returns the appropriate sort direction for the given string.The expected strings are "asc" for
ascending
and "desc" fordescending
. Any other value will default to ascending.- Parameters:
s
- sort direction string encoding- Returns:
- sort direction
-
-