Class AdapterBasicTableModel
- java.lang.Object
-
- com.github.bordertech.wcomponents.AdapterBasicTableModel
-
- All Implemented Interfaces:
WTable.TableModel
,Serializable
public class AdapterBasicTableModel extends Object implements WTable.TableModel, Serializable
Adapter to allow classes that implement theAdapterBasicTableModel.BasicTableModel
interface to be used as the model forWTable
.AdapterBasicTableModel.BasicTableModel
provides a basic interface for data that does not have a tree like structure (ie not expandable). Therefore, for data that is not expandable, it is recommended to use this adapter andAdapterBasicTableModel.BasicTableModel
interface.- Since:
- 1.0.0
- Author:
- Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AdapterBasicTableModel.BasicTableModel
BasicTableModel provides a basic interface that can be adapted viaAdapterBasicTableModel
forWTable
.
-
Constructor Summary
Constructors Constructor Description AdapterBasicTableModel(AdapterBasicTableModel.BasicTableModel model)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AdapterBasicTableModel.BasicTableModel
getBacking()
int
getChildCount(List<Integer> row)
Retrieves the number of children a row has.Class<? extends WComponent>
getRendererClass(List<Integer> row)
Retrieves the custom renderer for this row.int
getRowCount()
Retrieves the number of rows for the root (ie top) level.Object
getRowKey(List<Integer> row)
Retrieves the key (ie bean) used to uniquely identify this row.Object
getValueAt(List<Integer> row, int col)
Retrieves the value at the given row and column.boolean
hasChildren(List<Integer> row)
Allows the model to report if the row has children without actually having to determine the number of children (as it might not be known).boolean
isCellEditable(List<Integer> row, int col)
Indicates whether the given cell is editable.boolean
isDisabled(List<Integer> row)
Indicates whether the given row is disabled.boolean
isExpandable(List<Integer> row)
Indicates whether the given row is expandable.boolean
isSelectable(List<Integer> row)
Indicates whether the given row is selectable.boolean
isSortable(int col)
Indicates whether the model supports sorting by the given column.void
setValueAt(Object value, List<Integer> row, int col)
Sets the value at the given row and column.int[]
sort(int col, boolean ascending)
Sorts the data by the given column.
-
-
-
Constructor Detail
-
AdapterBasicTableModel
public AdapterBasicTableModel(AdapterBasicTableModel.BasicTableModel model)
- Parameters:
model
- the basic table model to adapt for theWTable
-
-
Method Detail
-
getBacking
public AdapterBasicTableModel.BasicTableModel getBacking()
- Returns:
- the basic table model to adapt for the
WTable
-
getValueAt
public Object getValueAt(List<Integer> row, int col)
Retrieves the value at the given row and column.- Specified by:
getValueAt
in interfaceWTable.TableModel
- Parameters:
row
- - the row index.col
- - the column index. Column of -1 indicates row has a renderer.- Returns:
- the value at the given row and column.
-
isCellEditable
public boolean isCellEditable(List<Integer> row, int col)
Indicates whether the given cell is editable.- Specified by:
isCellEditable
in interfaceWTable.TableModel
- Parameters:
row
- - the row index.col
- - the column index. Column of -1 indicates row has a renderer.- Returns:
- true if the given cell is editable, false otherwise.
-
setValueAt
public void setValueAt(Object value, List<Integer> row, int col)
Sets the value at the given row and column.- Specified by:
setValueAt
in interfaceWTable.TableModel
- Parameters:
value
- the value to set.row
- - the row index.col
- - the column index.
-
isSortable
public boolean isSortable(int col)
Indicates whether the model supports sorting by the given column.- Specified by:
isSortable
in interfaceWTable.TableModel
- Parameters:
col
- the column index.- Returns:
- true if the model is sortable by the given column, false otherwise.
-
sort
public int[] sort(int col, boolean ascending)
Sorts the data by the given column. Any previous sorting should be disregarded.
Data models must implement sorting in one of two ways.
-
If the data is accessible locally by the data model (ie. a sort won't result in a service call to obtain sorted data), then this method should not sort the actual data, but return a row-index mapping which the table will use to access the data. Row selection and expansion will be updated to use the new row indices.
For example, if the data for the column is {"a", "b", "d", "c"}, then an ascending sort should return {0, 1, 3, 2}, and a descending sort {2, 3, 1, 0}.
-
If the data is not accessible locally by the data model, or the model is otherwise unable to perform a mapping between old and new row indices, then the model should sort the actual data, and return null. In this case, the table will reset any row selection or expansion.
- Specified by:
sort
in interfaceWTable.TableModel
- Parameters:
col
- the column to sort onascending
- true for an ascending sort, false for descending.- Returns:
- the row indices in sort order, or null if row mappings can not be determined.
-
-
isDisabled
public boolean isDisabled(List<Integer> row)
Indicates whether the given row is disabled.- Specified by:
isDisabled
in interfaceWTable.TableModel
- Parameters:
row
- the row index- Returns:
- true if the row is disabled, false otherwise.
-
isSelectable
public boolean isSelectable(List<Integer> row)
Indicates whether the given row is selectable.- Specified by:
isSelectable
in interfaceWTable.TableModel
- Parameters:
row
- the row index- Returns:
- true if the row is selectable, false otherwise.
-
isExpandable
public boolean isExpandable(List<Integer> row)
Description copied from interface:WTable.TableModel
Indicates whether the given row is expandable.- Specified by:
isExpandable
in interfaceWTable.TableModel
- Parameters:
row
- the row index- Returns:
- false as data is not expandable
-
getRowCount
public int getRowCount()
Retrieves the number of rows for the root (ie top) level.- Specified by:
getRowCount
in interfaceWTable.TableModel
- Returns:
- the number of rows in the model for the root (ie top) level.
-
hasChildren
public boolean hasChildren(List<Integer> row)
Description copied from interface:WTable.TableModel
Allows the model to report if the row has children without actually having to determine the number of children (as it might not be known).- Specified by:
hasChildren
in interfaceWTable.TableModel
- Parameters:
row
- ignored- Returns:
- false as data is not expandable
-
getChildCount
public int getChildCount(List<Integer> row)
Description copied from interface:WTable.TableModel
Retrieves the number of children a row has.- Specified by:
getChildCount
in interfaceWTable.TableModel
- Parameters:
row
- ignored- Returns:
- 0 as data is not expandable
-
getRendererClass
public Class<? extends WComponent> getRendererClass(List<Integer> row)
Description copied from interface:WTable.TableModel
Retrieves the custom renderer for this row.- Specified by:
getRendererClass
in interfaceWTable.TableModel
- Parameters:
row
- ignored- Returns:
- null as data is not expandable
-
getRowKey
public Object getRowKey(List<Integer> row)
Retrieves the key (ie bean) used to uniquely identify this row.The usual implementation of this method would just return the row id passed in.
However, if you are required to dynamically add/remove rows in the model, which would change the row index, then the implementation of this method needs to return an object that uniquely identifies this row.
When rows have been added/removed, the
WTable.handleDataChanged()
method on WTable needs to be called.- Specified by:
getRowKey
in interfaceWTable.TableModel
- Parameters:
row
- the row index- Returns:
- the key (ie bean) used to uniquely identify this row
-
-