Interface WTable.TableModel

  • All Known Subinterfaces:
    WTable.BeanBoundTableModel, WTable.ScrollableTableModel
    All Known Implementing Classes:
    AbstractBeanBoundTableModel, AbstractTableModel, AdapterBasicTableModel, EmptyTableModel, SimpleBeanBoundTableModel
    Enclosing class:
    WTable

    public static interface WTable.TableModel

    TableModel provides the data for tables. In a MVC sense, the TableModel is the Model, the WTable is the controller and the view is comprised of the WTable layout and column renderers.

    Note that Data may be stored locally or sourced remotely, depending on the particular TableModel implementation.

    The row indexes used in the interface are a list of row indexes. Each item in the list is the index of the row for that level. The size of the list passed in matches the depth of the row.

    Row and column indices for all methods are zero-based, and TableModels are not expected to perform bounds-checking.

    Since:
    1.0.0
    Author:
    Jonathan Austin
    • Method Detail

      • getValueAt

        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

        boolean isCellEditable​(List<Integer> row,
                               int col)
        Indicates whether the given cell is editable.
        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

        void setValueAt​(Object value,
                        List<Integer> row,
                        int col)
        Sets the value at the given row and column.
        Parameters:
        value - the value to set.
        row - - the row index.
        col - - the column index.
      • isSortable

        boolean isSortable​(int col)
        Indicates whether the model supports sorting by the given column.
        Parameters:
        col - the column index.
        Returns:
        true if the model is sortable by the given column, false otherwise.
      • sort

        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.

        1. 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}.

        2. 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.

        Parameters:
        col - the column to sort on
        ascending - 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

        boolean isDisabled​(List<Integer> row)
        Indicates whether the given row is disabled.
        Parameters:
        row - the row index
        Returns:
        true if the row is disabled, false otherwise.
      • isSelectable

        boolean isSelectable​(List<Integer> row)
        Indicates whether the given row is selectable.
        Parameters:
        row - the row index
        Returns:
        true if the row is selectable, false otherwise.
      • isExpandable

        boolean isExpandable​(List<Integer> row)
        Indicates whether the given row is expandable.
        Parameters:
        row - the row index
        Returns:
        true if the row is expandable, false otherwise.
      • getRowCount

        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.
      • hasChildren

        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).
        Parameters:
        row - the row index
        Returns:
        true if the row has children
      • getChildCount

        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

        Class<? extends WComponent> getRendererClass​(List<Integer> row)
        Retrieves the custom renderer for this row.
        Parameters:
        row - the row index
        Returns:
        the renderer class, or null if the default renderer is to be used.
      • getRowKey

        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.

        Parameters:
        row - the row index
        Returns:
        the key (ie bean) used to uniquely identify this row