Class SimpleBeanBoundTableModel
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractTableModel
-
- com.github.bordertech.wcomponents.AbstractBeanBoundTableModel
-
- com.github.bordertech.wcomponents.SimpleBeanBoundTableModel
-
- All Implemented Interfaces:
BeanAware
,BeanProviderBound
,WTable.BeanBoundTableModel
,WTable.TableModel
,Serializable
public class SimpleBeanBoundTableModel extends AbstractBeanBoundTableModel
A simple table data model that is bound to a list of beans.The simplest use of this model is to define the column bean properties for a list of beans that is not expandable, via the
SimpleBeanBoundTableModel(String[])
constructor.The model also allows tree like structures (ie expandable rows) to be defined by using
SimpleBeanBoundTableModel.LevelDetails
. EachSimpleBeanBoundTableModel.LevelDetails
determines which "beanProperty" will be used to expand the next level. The defined "beanProperty" is usually another list of beans. There are different helper constructors that will help define these levels based on the bean properties passed in.If the data is hierarchic, then the one
SimpleBeanBoundTableModel.LevelDetails
can be defined, and thesetIterateFirstLevel(boolean)
can be set to true. The model will then iterate this level down the bean list using the level's bean property. The maximum number of iterations can be set viasetMaxIterations(int)
.The model supports sorting. A comparator for a particular column can be added via
setComparator(int, Comparator)
.- Since:
- 1.0.0
- Author:
- Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleBeanBoundTableModel.LevelDetails
The details of an expandable level.
-
Field Summary
Fields Modifier and Type Field Description static ComparableComparator
COMPARABLE_COMPARATOR
A simple comparator that compares comparables, for use in sorting e.g. columns containing Strings.
-
Constructor Summary
Constructors Constructor Description SimpleBeanBoundTableModel(String[] columnBeanProperties)
Define the column bean properties for the top level.SimpleBeanBoundTableModel(String[] columnBeanProperties, SimpleBeanBoundTableModel.LevelDetails... levels)
Define the column bean properties for the top level along with the expandable levels.SimpleBeanBoundTableModel(String[] columnBeanProperties, String levelBeanProperty)
Define the column bean properties for the top level along with the bean property of the first expandable level.SimpleBeanBoundTableModel(String[] columnBeanProperties, String[] levelBeanProperties, String[][] levelColumnBeanProperties)
Define the column bean properties for the top level along with the bean properties and column bean properties of the expandable levels.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
buildBeanUtilString(List<Integer> row)
List<?>
getBeanList()
protected Object
getBeanPropertyValue(String property, Object bean)
Get the bean property value.int
getChildCount(List<Integer> row)
Retrieves the number of children a row has.protected int
getLevelIndex(List<Integer> row)
int
getMaxIterations()
Class<? extends WComponent>
getRendererClass(List<Integer> row)
This model does not support the concept of rows being expandable by default.protected Object
getRowBean(List<Integer> 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.protected int
getSize(Object data)
protected Object
getTopRowBean(List<Integer> row)
Return the top level bean for this row index.Object
getValueAt(List<Integer> row, int col)
Retrieves the value at the given row and column.boolean
isCellEditable(List<Integer> row, int col)
Indicates whether the given cell is editable.boolean
isEditable()
Indicates whether the data in this model is editable.boolean
isExpandable(List<Integer> row)
This model does not support the concept of rows being expandable by default.boolean
isIterateFirstLevel()
boolean
isSelectable(List<Integer> row)
This model does not support the concept of row selectability by default.boolean
isSortable(int col)
This model does not support the concept of sorting by default.protected void
setBeanPropertyValue(String property, Object bean, Serializable value)
Set the bean property value.void
setComparator(int col, Comparator comparator)
Sets the comparator for the given column, to enable sorting.void
setEditable(boolean editable)
Sets whether the data in this model is editable.void
setIterateFirstLevel(boolean iterateFirstLevel)
void
setMaxIterations(int maxIterations)
void
setSelectable(boolean selectable)
Sets whether the rows are globally selectable.void
setValueAt(Object value, List<Integer> row, int col)
This model does not support the concept of editable cells by default.int[]
sort(int col, boolean ascending)
This model does not support the concept of sorting by default.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractBeanBoundTableModel
getBean, getBeanId, getBeanProperty, getBeanValue, setBeanId, setBeanProperty, setBeanProvider
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractTableModel
hasChildren, isDisabled, sort
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.WTable.TableModel
hasChildren, isDisabled
-
-
-
-
Field Detail
-
COMPARABLE_COMPARATOR
public static final ComparableComparator COMPARABLE_COMPARATOR
A simple comparator that compares comparables, for use in sorting e.g. columns containing Strings.
-
-
Constructor Detail
-
SimpleBeanBoundTableModel
public SimpleBeanBoundTableModel(String[] columnBeanProperties)
Define the column bean properties for the top level.- Parameters:
columnBeanProperties
- the column bean properties
-
SimpleBeanBoundTableModel
public SimpleBeanBoundTableModel(String[] columnBeanProperties, String levelBeanProperty)
Define the column bean properties for the top level along with the bean property of the first expandable level.The expandable level will use the same column bean properties as the top level.
To iterate down multiple levels on this bean property, set
setIterateFirstLevel(boolean)
to true.- Parameters:
columnBeanProperties
- the column bean propertieslevelBeanProperty
- the bean property for the expandable level
-
SimpleBeanBoundTableModel
public SimpleBeanBoundTableModel(String[] columnBeanProperties, String[] levelBeanProperties, String[][] levelColumnBeanProperties)
Define the column bean properties for the top level along with the bean properties and column bean properties of the expandable levels.- Parameters:
columnBeanProperties
- the top level column bean propertieslevelBeanProperties
- the bean properties for the expandable levelslevelColumnBeanProperties
- the column bean properties for the expandable levels
-
SimpleBeanBoundTableModel
public SimpleBeanBoundTableModel(String[] columnBeanProperties, SimpleBeanBoundTableModel.LevelDetails... levels)
Define the column bean properties for the top level along with the expandable levels.- Parameters:
columnBeanProperties
- the top level column bean propertieslevels
- the expandable levels
-
-
Method Detail
-
isExpandable
public boolean isExpandable(List<Integer> row)
Description copied from class:AbstractTableModel
This model does not support the concept of rows being expandable by default. Subclasses will need to override this method for expansion of specific rows.- Specified by:
isExpandable
in interfaceWTable.TableModel
- Overrides:
isExpandable
in classAbstractTableModel
- Parameters:
row
- ignored- Returns:
- true if expandable levels defined
-
isSelectable
public boolean isSelectable(List<Integer> row)
Description copied from class:AbstractTableModel
This model does not support the concept of row selectability by default. Subclasses will need to override this method for selection of specific rows.- Specified by:
isSelectable
in interfaceWTable.TableModel
- Overrides:
isSelectable
in classAbstractTableModel
- Parameters:
row
- ignored- Returns:
- true if the model is globally selectable, otherwise false
-
setSelectable
public void setSelectable(boolean selectable)
Sets whether the rows are globally selectable.- Parameters:
selectable
- true if the rows are globally selectable, otherwise false
-
getMaxIterations
public int getMaxIterations()
- Returns:
- the maximum iterations on the first level. -1 indicates no limit.
-
setMaxIterations
public void setMaxIterations(int maxIterations)
- Parameters:
maxIterations
- the maximum iterations on the first level. -1 indicates no limit.
-
isIterateFirstLevel
public boolean isIterateFirstLevel()
- Returns:
- returns true if iterate on the first level
-
setIterateFirstLevel
public void setIterateFirstLevel(boolean iterateFirstLevel)
- Parameters:
iterateFirstLevel
- true if iterate on first level
-
isSortable
public boolean isSortable(int col)
This model does not support the concept of sorting by default. Subclasses will need to override this method andAbstractTableModel.sort(int, boolean)
to support sorting.- Specified by:
isSortable
in interfaceWTable.TableModel
- Overrides:
isSortable
in classAbstractTableModel
- Parameters:
col
- ignored.- Returns:
- false.
-
setComparator
public void setComparator(int col, Comparator comparator)
Sets the comparator for the given column, to enable sorting.- Parameters:
col
- the column to set the comparator on.comparator
- the comparator to set.
-
getValueAt
public Object getValueAt(List<Integer> row, int col)
Retrieves the value at the given row and column.- 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. This model only supports editability at a global level. SeesetEditable(boolean)
.- Specified by:
isCellEditable
in interfaceWTable.TableModel
- Overrides:
isCellEditable
in classAbstractTableModel
- Parameters:
row
- ignored.col
- ignored.- Returns:
- true if the given cell is editable, false otherwise.
-
setValueAt
public void setValueAt(Object value, List<Integer> row, int col)
This model does not support the concept of editable cells by default. Subclasses will need to override this method andAbstractTableModel.isCellEditable(java.util.List, int)
to support cell editing.- Specified by:
setValueAt
in interfaceWTable.TableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
value
- ignored.row
- ignored.col
- ignored.
-
isEditable
public boolean isEditable()
Indicates whether the data in this model is editable.- Returns:
- true if the data in this model is editable, false otherwise.
-
setEditable
public void setEditable(boolean editable)
Sets whether the data in this model is editable. By default, the data is not editable.- Parameters:
editable
- true if the data is editable, false if it is read-only.
-
sort
public int[] sort(int col, boolean ascending)
This model does not support the concept of sorting by default. Subclasses will need to override this method andAbstractTableModel.isSortable(int)
to support sorting.- Specified by:
sort
in interfaceWTable.TableModel
- Overrides:
sort
in classAbstractTableModel
- Parameters:
col
- ignored.ascending
- ignored.- Returns:
- null
-
getRowCount
public int getRowCount()
Retrieves the number of rows for the root (ie top) level.- Returns:
- the number of rows in the model for the root (ie top) level.
-
getChildCount
public int getChildCount(List<Integer> row)
Retrieves the number of children a row has.- Parameters:
row
- the row index- Returns:
- the number of rows in the model for this level.
-
getRendererClass
public Class<? extends WComponent> getRendererClass(List<Integer> row)
This model does not support the concept of rows being expandable by default. Subclasses will need to override this method for expansion of specific rows.- Specified by:
getRendererClass
in interfaceWTable.TableModel
- Overrides:
getRendererClass
in classAbstractTableModel
- Parameters:
row
- ignored- Returns:
- null
-
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
- Overrides:
getRowKey
in classAbstractTableModel
- Parameters:
row
- the row index- Returns:
- the key (ie bean) used to uniquely identify this row
-
getRowBean
protected Object getRowBean(List<Integer> row)
- Parameters:
row
- the row index- Returns:
- the bean for this row
-
getTopRowBean
protected Object getTopRowBean(List<Integer> row)
Return the top level bean for this row index.- Parameters:
row
- the row index- Returns:
- the root row bean (ie top level) for this index
-
buildBeanUtilString
protected String buildBeanUtilString(List<Integer> row)
- Parameters:
row
- the row index- Returns:
- the bean util syntax string to retrieve the row bean
-
getBeanList
public List<?> getBeanList()
- Returns:
- the bean data as a list
-
getBeanPropertyValue
protected Object getBeanPropertyValue(String property, Object bean)
Get the bean property value.- Parameters:
property
- the bean propertybean
- the bean- Returns:
- the bean property value
-
setBeanPropertyValue
protected void setBeanPropertyValue(String property, Object bean, Serializable value)
Set the bean property value.- Parameters:
property
- the bean propertybean
- the beanvalue
- the value to set
-
getSize
protected int getSize(Object data)
- Parameters:
data
- the array or list of beans- Returns:
- the number of beans (ie size)
-
-