Class SimpleBeanBoundTableModel

    • 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 properties
        levelBeanProperty - 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 properties
        levelBeanProperties - the bean properties for the expandable levels
        levelColumnBeanProperties - 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 properties
        levels - 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 interface WTable.TableModel
        Overrides:
        isExpandable in class AbstractTableModel
        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 interface WTable.TableModel
        Overrides:
        isSelectable in class AbstractTableModel
        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
      • 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.
      • 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 and AbstractTableModel.isSortable(int) to support sorting.
        Specified by:
        sort in interface WTable.TableModel
        Overrides:
        sort in class AbstractTableModel
        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.
      • 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 interface WTable.TableModel
        Overrides:
        getRowKey in class AbstractTableModel
        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 property
        bean - 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 property
        bean - the bean
        value - 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)
      • getLevelIndex

        protected int getLevelIndex​(List<Integer> row)
        Parameters:
        row - the row index
        Returns:
        the index of the level