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.BasicTableModelinterface to be used as the model forWTable.AdapterBasicTableModel.BasicTableModelprovides 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.BasicTableModelinterface.- Since:
- 1.0.0
- Author:
- Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAdapterBasicTableModel.BasicTableModelBasicTableModel provides a basic interface that can be adapted viaAdapterBasicTableModelforWTable.
-
Constructor Summary
Constructors Constructor Description AdapterBasicTableModel(AdapterBasicTableModel.BasicTableModel model)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AdapterBasicTableModel.BasicTableModelgetBacking()intgetChildCount(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.intgetRowCount()Retrieves the number of rows for the root (ie top) level.ObjectgetRowKey(List<Integer> row)Retrieves the key (ie bean) used to uniquely identify this row.ObjectgetValueAt(List<Integer> row, int col)Retrieves the value at the given row and column.booleanhasChildren(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).booleanisCellEditable(List<Integer> row, int col)Indicates whether the given cell is editable.booleanisDisabled(List<Integer> row)Indicates whether the given row is disabled.booleanisExpandable(List<Integer> row)Indicates whether the given row is expandable.booleanisSelectable(List<Integer> row)Indicates whether the given row is selectable.booleanisSortable(int col)Indicates whether the model supports sorting by the given column.voidsetValueAt(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:
getValueAtin 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:
isCellEditablein 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:
setValueAtin 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:
isSortablein 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:
sortin 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:
isDisabledin 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:
isSelectablein 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.TableModelIndicates whether the given row is expandable.- Specified by:
isExpandablein 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:
getRowCountin 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.TableModelAllows 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:
hasChildrenin interfaceWTable.TableModel- Parameters:
row- ignored- Returns:
- false as data is not expandable
-
getChildCount
public int getChildCount(List<Integer> row)
Description copied from interface:WTable.TableModelRetrieves the number of children a row has.- Specified by:
getChildCountin 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.TableModelRetrieves the custom renderer for this row.- Specified by:
getRendererClassin 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:
getRowKeyin interfaceWTable.TableModel- Parameters:
row- the row index- Returns:
- the key (ie bean) used to uniquely identify this row
-
-