Class AbstractCellTable<T>

Type Parameters:
T - the data type of each row
All Implemented Interfaces:
HasAttachHandlers, HasHandlers, HasKeyboardPagingPolicy, HasKeyboardSelectionPolicy, EventListener, Focusable, HasVisibility, IsRenderable, IsWidget, HasCellPreviewHandlers<T>, HasData<T>, HasKeyProvider<T>, HasRows
Direct Known Subclasses:
CellTable, DataGrid

public abstract class AbstractCellTable<T> extends AbstractHasData<T>
Abstract base class for tabular views that supports paging and columns.

Columns

The Column class defines the Cell used to render a column. Implement Column.getValue(Object) to retrieve the field value from the row object that will be rendered in the Cell.

Headers and Footers

A Header can be placed at the top (header) or bottom (footer) of the AbstractCellTable. You can specify a header as text using addColumn(Column, String), or you can create a custom Header that can change with the value of the cells, such as a column total. The Header will be rendered every time the row data changes or the table is redrawn. If you pass the same header instance (==) into adjacent columns, the header will span the columns.

  • Constructor Details

    • AbstractCellTable

      public AbstractCellTable(Element elem, int pageSize, AbstractCellTable.Resources resources, ProvidesKey<T> keyProvider)
      Constructs a table with the given page size, the specified AbstractCellTable.Style, and the given key provider.
      Parameters:
      elem - the parent Element
      pageSize - the page size
      resources - the resources to apply to the widget
      keyProvider - an instance of ProvidesKey, or null if the record object should act as its own key
    • AbstractCellTable

      public AbstractCellTable(Widget widget, int pageSize, AbstractCellTable.Resources resources, ProvidesKey<T> keyProvider)
      Constructs a table with the given page size, the specified AbstractCellTable.Style, and the given key provider.
      Parameters:
      widget - the parent widget
      pageSize - the page size
      resources - the resources to apply to the widget
      keyProvider - an instance of ProvidesKey, or null if the record object should act as its own key
  • Method Details

    • addColumn

      public void addColumn(Column<T,?> col)
      Adds a column to the end of the table.
      Parameters:
      col - the column to be added
    • addColumn

      public void addColumn(Column<T,?> col, Header<?> header)
      Adds a column to the end of the table with an associated header.
      Parameters:
      col - the column to be added
      header - the associated Header
    • addColumn

      public void addColumn(Column<T,?> col, Header<?> header, Header<?> footer)
      Adds a column to the end of the table with an associated header and footer.
      Parameters:
      col - the column to be added
      header - the associated Header
      footer - the associated footer (as a Header object)
    • addColumn

      public void addColumn(Column<T,?> col, String headerString)
      Adds a column to the end of the table with an associated String header.
      Parameters:
      col - the column to be added
      headerString - the associated header text, as a String
    • addColumn

      public void addColumn(Column<T,?> col, SafeHtml headerHtml)
      Adds a column to the end of the table with an associated SafeHtml header.
      Parameters:
      col - the column to be added
      headerHtml - the associated header text, as safe HTML
    • addColumn

      public void addColumn(Column<T,?> col, String headerString, String footerString)
      Adds a column to the end of the table with an associated String header and footer.
      Parameters:
      col - the column to be added
      headerString - the associated header text, as a String
      footerString - the associated footer text, as a String
    • addColumn

      public void addColumn(Column<T,?> col, SafeHtml headerHtml, SafeHtml footerHtml)
      Adds a column to the end of the table with an associated SafeHtml header and footer.
      Parameters:
      col - the column to be added
      headerHtml - the associated header text, as safe HTML
      footerHtml - the associated footer text, as safe HTML
    • addColumnSortHandler

      public HandlerRegistration addColumnSortHandler(ColumnSortEvent.Handler handler)
      Add a handler to handle ColumnSortEvents.
      Parameters:
      handler - the ColumnSortEvent.Handler to add
      Returns:
      a HandlerRegistration to remove the handler
    • addColumnStyleName

      public abstract void addColumnStyleName(int index, String styleName)
      Add a style name to the col element at the specified index, creating it if necessary.
      Parameters:
      index - the column index
      styleName - the style name to add
    • addRowHoverHandler

      public HandlerRegistration addRowHoverHandler(RowHoverEvent.Handler handler)
      Add a handler to handle RowHoverEvents.
      Parameters:
      handler - the RowHoverEvent.Handler to add
      Returns:
      a HandlerRegistration to remove the handler
    • clearColumnWidth

      public void clearColumnWidth(Column<T,?> column)
      Clear the width of the specified Column.
      Parameters:
      column - the column
    • clearColumnWidth

      public void clearColumnWidth(Integer column)
      Clear the width of the specified Column.
      Parameters:
      column - the column index
    • flush

      public void flush()
      Flush all pending changes to the table and render immediately.

      Modifications to the table, such as adding columns or setting data, are not rendered immediately. Instead, changes are coalesced at the end of the current event loop to avoid rendering the table multiple times. Use this method to force the table to render all pending modifications immediately.

    • getColumn

      public Column<T,?> getColumn(int col)
      Get the column at the specified index.
      Parameters:
      col - the index of the column to retrieve
      Returns:
      the Column at the index
    • getColumnCount

      public int getColumnCount()
      Get the number of columns in the table.
      Returns:
      the column count
    • getColumnIndex

      public int getColumnIndex(Column<T,?> column)
      Get the index of the specified column.
      Parameters:
      column - the column to search for
      Returns:
      the index of the column, or -1 if not found
    • getColumnSortList

      public ColumnSortList getColumnSortList()
      Get the ColumnSortList that specifies which columns are sorted. Modifications to the ColumnSortList will be reflected in the table header.

      Note that the implementation may redraw the headers on every modification to the ColumnSortList.

      Returns:
      the ColumnSortList
    • getColumnWidth

      public String getColumnWidth(Column<T,?> column)
      Get the width of a Column.
      Parameters:
      column - the column
      Returns:
      the width of the column, or null if not set
      See Also:
    • getEmptyTableWidget

      public Widget getEmptyTableWidget()
      Get the widget displayed when the table has no rows.
      Returns:
      the empty table widget
    • getFooter

      public Header<?> getFooter(int index)
      Get the Header from the footer section that was added with a Column.
    • getFooterBuilder

      public FooterBuilder<T> getFooterBuilder()
      Get the HeaderBuilder used to generate the footer section.
    • getHeader

      public Header<?> getHeader(int index)
      Get the Header from the header section that was added with a Column.
    • getHeaderBuilder

      public HeaderBuilder<T> getHeaderBuilder()
      Get the HeaderBuilder used to generate the header section.
    • getKeyboardSelectedColumn

      public int getKeyboardSelectedColumn()
      Get the index of the column that is currently selected via the keyboard.
      Returns:
      the currently selected column, or -1 if none selected
    • getKeyboardSelectedSubRow

      public int getKeyboardSelectedSubRow()
      Get the index of the sub row that is currently selected via the keyboard. If the row value maps to one rendered row element, the subrow is 0.
      Returns:
      the currently selected subrow, or -1 if none selected
    • getLoadingIndicator

      public Widget getLoadingIndicator()
      Get the widget displayed when the data is loading.
      Returns:
      the loading indicator
    • getResources

      public AbstractCellTable.Resources getResources()
      Get the resources used by this table.
    • getRowElement

      public TableRowElement getRowElement(int row)
      Get the TableRowElement for the specified row. If the row element has not been created, null is returned.
      Parameters:
      row - the row index
      Returns:
      the row element, or null if it doesn't exists
      Throws:
      IndexOutOfBoundsException - if the row index is outside of the current page
    • getRowStyles

      public RowStyles<T> getRowStyles()
      Gets the object used to determine how a row is styled.
      Returns:
      the RowStyles object if set, null if not
    • insertColumn

      public void insertColumn(int beforeIndex, Column<T,?> col)
      Inserts a column into the table at the specified index.
      Parameters:
      beforeIndex - the index to insert the column
      col - the column to be added
    • insertColumn

      public void insertColumn(int beforeIndex, Column<T,?> col, Header<?> header)
      Inserts a column into the table at the specified index with an associated header.
      Parameters:
      beforeIndex - the index to insert the column
      col - the column to be added
      header - the associated Header
    • insertColumn

      public void insertColumn(int beforeIndex, Column<T,?> col, Header<?> header, Header<?> footer)
      Inserts a column into the table at the specified index with an associated header and footer.
      Parameters:
      beforeIndex - the index to insert the column
      col - the column to be added
      header - the associated Header
      footer - the associated footer (as a Header object)
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • insertColumn

      public void insertColumn(int beforeIndex, Column<T,?> col, String headerString)
      Inserts a column into the table at the specified index with an associated String header.
      Parameters:
      beforeIndex - the index to insert the column
      col - the column to be added
      headerString - the associated header text, as a String
    • insertColumn

      public void insertColumn(int beforeIndex, Column<T,?> col, SafeHtml headerHtml)
      Inserts a column into the table at the specified index with an associated SafeHtml header.
      Parameters:
      beforeIndex - the index to insert the column
      col - the column to be added
      headerHtml - the associated header text, as safe HTML
    • insertColumn

      public void insertColumn(int beforeIndex, Column<T,?> col, String headerString, String footerString)
      Inserts a column into the table at the specified index with an associated String header and footer.
      Parameters:
      beforeIndex - the index to insert the column
      col - the column to be added
      headerString - the associated header text, as a String
      footerString - the associated footer text, as a String
    • insertColumn

      public void insertColumn(int beforeIndex, Column<T,?> col, SafeHtml headerHtml, SafeHtml footerHtml)
      Inserts a column into the table at the specified index with an associated SafeHtml header and footer.
      Parameters:
      beforeIndex - the index to insert the column
      col - the column to be added
      headerHtml - the associated header text, as safe HTML
      footerHtml - the associated footer text, as safe HTML
    • isAutoFooterRefreshDisabled

      public boolean isAutoFooterRefreshDisabled()
      Check if auto footer refresh is enabled or disabled.
      Returns:
      true if disabled, false if enabled
      See Also:
    • isAutoHeaderRefreshDisabled

      public boolean isAutoHeaderRefreshDisabled()
      Check if auto header refresh is enabled or disabled.
      Returns:
      true if disabled, false if enabled
      See Also:
    • isSkipRowHoverCheck

      public boolean isSkipRowHoverCheck()
      Gets the skipRowHoverCheck flag. If true, the CellTable will not check for row-level hover events (MOUSEOVER and MOUSEOUT).
      Returns:
      the flag value
    • isSkipRowHoverFloatElementCheck

      public boolean isSkipRowHoverFloatElementCheck()
      Gets the skipRowHoverFloatElementCheck flag. If true, the CellTable will not check for floating (fixed position) elements over the hovered row.
      Returns:
      the flag value
    • isSkipRowHoverStyleUpdate

      public boolean isSkipRowHoverStyleUpdate()
      Gets the skipRowHoverStyleUpdate flag. If true, the CellTable will not update the row's style on row-level hover events (MOUSEOVER and MOUSEOUT).
      Returns:
      the flag value
    • redrawFooters

      public void redrawFooters()
      Redraw the table's footers. The footers will be re-rendered synchronously.
    • redrawHeaders

      public void redrawHeaders()
      Redraw the table's headers. The headers will be re-rendered synchronously.
    • removeColumn

      public void removeColumn(Column<T,?> col)
      Remove a column.
      Parameters:
      col - the column to remove
    • removeColumn

      public void removeColumn(int index)
      Remove a column.
      Parameters:
      index - the column index
    • removeColumnStyleName

      public abstract void removeColumnStyleName(int index, String styleName)
      Remove a style from the col element at the specified index.
      Parameters:
      index - the column index
      styleName - the style name to remove
    • setAutoFooterRefreshDisabled

      public void setAutoFooterRefreshDisabled(boolean disabled)
      Enable or disable auto footer refresh when row data is changed. By default, footers are refreshed every time the row data changes in case the headers depend on the current row data. If the headers do not depend on the current row data, you can disable this feature to improve performance.

      Note that headers will still refresh when columns are added or removed, regardless of whether or not this feature is enabled.

    • setAutoHeaderRefreshDisabled

      public void setAutoHeaderRefreshDisabled(boolean disabled)
      Enable or disable auto header refresh when row data is changed. By default, headers are refreshed every time the row data changes in case the footers depend on the current row data. If the footers do not depend on the current row data, you can disable this feature to improve performance.

      Note that footers will still refresh when columns are added or removed, regardless of whether or not this feature is enabled.

    • setColumnWidth

      public void setColumnWidth(Column<T,?> column, String width)
      Set the width of a Column. The width will persist with the column and takes precedence of any width set via setColumnWidth(int, String).
      Parameters:
      column - the column
      width - the width of the column
    • setColumnWidth

      public void setColumnWidth(Column<T,?> column, double width, Style.Unit unit)
      Set the width of a Column. The width will persist with the column and takes precedence of any width set via setColumnWidth(int, double, Unit).
      Parameters:
      column - the column
      width - the width of the column
      unit - the Style.Unit of measurement
    • setColumnWidth

      public void setColumnWidth(int column, double width, Style.Unit unit)
      Set the width of a Column.
      Parameters:
      column - the column
      width - the width of the column
      unit - the Style.Unit of measurement
    • setColumnWidth

      public void setColumnWidth(int column, String width)
      Set the width of a Column.
      Parameters:
      column - the column
      width - the width of the column
    • setEmptyTableWidget

      @UiChild(tagname="emptyTableWidget", limit=1) public void setEmptyTableWidget(Widget widget)
      Set the widget to display when the table has no rows.
      Parameters:
      widget - the empty table widget, or null to disable
    • setFooterBuilder

      public void setFooterBuilder(FooterBuilder<T> builder)
      Set the HeaderBuilder used to build the footer section of the table.
    • setHeaderBuilder

      public void setHeaderBuilder(HeaderBuilder<T> builder)
      Set the HeaderBuilder used to build the header section of the table.
    • setKeyboardSelectedColumn

      public final void setKeyboardSelectedColumn(int column)
      Set the keyboard selected column index.

      If keyboard selection is disabled, this method does nothing.

      If the keyboard selected column is greater than the number of columns in the keyboard selected row, the last column in the row is selected, but the column index is remembered.

      Parameters:
      column - the column index, greater than or equal to zero
    • setKeyboardSelectedColumn

      public void setKeyboardSelectedColumn(int column, boolean stealFocus)
      Set the keyboard selected column index and optionally focus on the new cell.
      Parameters:
      column - the column index, greater than or equal to zero
      stealFocus - true to focus on the new column
      See Also:
    • setKeyboardSelectedRow

      public void setKeyboardSelectedRow(int row, boolean stealFocus)
      Description copied from class: AbstractHasData
      Set the keyboard selected row and optionally focus on the new row.
      Overrides:
      setKeyboardSelectedRow in class AbstractHasData<T>
      Parameters:
      row - the row index relative to the page start
      stealFocus - true to focus on the new row
      See Also:
    • setKeyboardSelectedRow

      public void setKeyboardSelectedRow(int row, int subrow, boolean stealFocus)
      Set the keyboard selected row and subrow, optionally focus on the new row.
      Parameters:
      row - the row index relative to the page start
      subrow - the row index of the child row
      stealFocus - true to focus on the new row
      See Also:
    • setLoadingIndicator

      @UiChild(tagname="loadingIndicator", limit=1) public void setLoadingIndicator(Widget widget)
      Set the widget to display when the data is loading.
      Parameters:
      widget - the loading indicator, or null to disable
    • setRowStyles

      public void setRowStyles(RowStyles<T> rowStyles)
      Sets the object used to determine how a row is styled; the change will take effect the next time that the table is rendered.
      Parameters:
      rowStyles - a RowStyles object
    • setSkipRowHoverCheck

      public void setSkipRowHoverCheck(boolean skipRowHoverCheck)
      Sets the skipRowHoverCheck flag. If set, the CellTable will not check for row-level hover events (MOUSEOVER and MOUSEOUT).
      Parameters:
      skipRowHoverCheck - the new flag value
    • setSkipRowHoverFloatElementCheck

      public void setSkipRowHoverFloatElementCheck(boolean skipRowHoverFloatElementCheck)
      Sets the skipRowHoverFloatElementCheck flag. If set, the CellTable will not not check for floating (fixed position) elements over the hovered row.
      Parameters:
      skipRowHoverFloatElementCheck - the new flag value
    • setSkipRowHoverStyleUpdate

      public void setSkipRowHoverStyleUpdate(boolean skipRowHoverStyleUpdate)
      Sets the skipRowHoverStyleUpdate flag. If set, the CellTable will not update the row's style on row-level hover events (MOUSEOVER and MOUSEOUT).
      Parameters:
      skipRowHoverCheck - the new flag value
    • setTableBuilder

      public void setTableBuilder(CellTableBuilder<T> tableBuilder)
      Specify the CellTableBuilder that will be used to render the row values into the table.
    • convertToElements

      protected Element convertToElements(SafeHtml html)
      Description copied from class: AbstractHasData
      Convert the specified HTML into DOM elements and return the parent of the DOM elements.
      Overrides:
      convertToElements in class AbstractHasData<T>
      Parameters:
      html - the HTML to convert
      Returns:
      the parent element
    • dependsOnSelection

      protected boolean dependsOnSelection()
      Description copied from class: AbstractHasData
      Check whether or not the cells in the view depend on the selection state.
      Specified by:
      dependsOnSelection in class AbstractHasData<T>
      Returns:
      true if cells depend on selection, false if not
    • doSetColumnWidth

      protected abstract void doSetColumnWidth(int column, String width)
      Set the width of a column.
      Parameters:
      column - the column index
      width - the width, or null to clear the width
    • doSetHeaderVisible

      protected abstract void doSetHeaderVisible(boolean isFooter, boolean isVisible)
      Show or hide a header section.
      Parameters:
      isFooter - true for the footer, false for the header
      isVisible - true to show, false to hide
    • getChildContainer

      protected Element getChildContainer()
      Description copied from class: AbstractHasData
      Return the element that holds the rendered cells.
      Specified by:
      getChildContainer in class AbstractHasData<T>
      Returns:
      the container Element
    • getChildElement

      protected TableRowElement getChildElement(int row)
      Get the element that represents the specified index.

      The row element may not be the same as the TR element at the specified index if some row values are rendered with additional rows.

      Overrides:
      getChildElement in class AbstractHasData<T>
      Parameters:
      row - the row index, relative to the page start
      Returns:
      the row element, or null if it doesn't exists
      Throws:
      IndexOutOfBoundsException - if the row index is outside of the current page
    • getKeyboardSelectedElement

      protected Element getKeyboardSelectedElement()
      Description copied from class: AbstractHasData
      Get the element that has keyboard selection.
      Specified by:
      getKeyboardSelectedElement in class AbstractHasData<T>
      Returns:
      the keyboard selected element
    • getRealColumnCount

      protected int getRealColumnCount()
      Get the real column count, which is the greater of the number of Columns or the maximum index of a column with a defined column width.
    • getTableBodyElement

      protected abstract TableSectionElement getTableBodyElement()
      Get the tbody element that contains the render row values.
    • getTableFootElement

      protected abstract TableSectionElement getTableFootElement()
      Get the tfoot element that contains the footers.
    • getTableHeadElement

      protected abstract TableSectionElement getTableHeadElement()
      Get the thead element that contains the headers.
    • isKeyboardNavigationSuppressed

      protected boolean isKeyboardNavigationSuppressed()
      Description copied from class: AbstractHasData
      Check if keyboard navigation is being suppressed, such as when the user is editing a cell.
      Specified by:
      isKeyboardNavigationSuppressed in class AbstractHasData<T>
      Returns:
      true if suppressed, false if not
    • onBlur

      protected void onBlur()
      Description copied from class: AbstractHasData
      Called when the widget is blurred.
      Overrides:
      onBlur in class AbstractHasData<T>
    • onBrowserEvent2

      protected void onBrowserEvent2(Event event)
      Description copied from class: AbstractHasData
      Overrides:
      onBrowserEvent2 in class AbstractHasData<T>
      Parameters:
      event - the event that was fired
    • onFocus

      protected void onFocus()
      Description copied from class: AbstractHasData
      Called when the widget is focused.
      Overrides:
      onFocus in class AbstractHasData<T>
    • refreshColumnWidths

      protected void refreshColumnWidths()
    • renderRowValues

      @Deprecated protected void renderRowValues(SafeHtmlBuilder sb, List<T> values, int start, SelectionModel<? super T> selectionModel)
      Deprecated.
      as of GWT 2.5, use a CellTableBuilder to customize the table structure instead
      Description copied from class: AbstractHasData
      Render all row values into the specified SafeHtmlBuilder.

      Subclasses can optionally throw an UnsupportedOperationException if they prefer to render the rows in AbstractHasData.replaceAllChildren(List, SafeHtml) and AbstractHasData.replaceChildren(List, int, SafeHtml). In this case, the SafeHtml argument will be null. Though a bit hacky, this is designed to supported legacy widgets that use SafeHtmlBuilder, and newer widgets that use other builders, such as the ElementBuilder API.

      Specified by:
      renderRowValues in class AbstractHasData<T>
      Parameters:
      sb - the SafeHtmlBuilder to render into
      values - the row values
      start - the absolute start index of the values
      selectionModel - the SelectionModel
      See Also:
    • renderRowValuesLegacy

      @Deprecated protected final void renderRowValuesLegacy(SafeHtmlBuilder sb, List<T> values, int start, SelectionModel<? super T> selectionModel)
      Deprecated.
      as of GWT 2.5, use a CellTableBuilder to customize the table structure instead
      Render all row values into the specified SafeHtmlBuilder.

      This method is here for legacy reasons, to support subclasses that call renderRowValues(SafeHtmlBuilder, List, int, SelectionModel).

      Parameters:
      sb - the SafeHtmlBuilder to render into
      values - the row values
      start - the absolute start index of the values
      selectionModel - the SelectionModel
    • replaceAllChildren

      protected void replaceAllChildren(List<T> values, SafeHtml html)
      Description copied from class: AbstractHasData
      Replace all children with the specified html.
      Overrides:
      replaceAllChildren in class AbstractHasData<T>
      Parameters:
      values - the values of the new children
      html - the html to render, or null if AbstractHasData.renderRowValues(SafeHtmlBuilder, List, int, SelectionModel) throws an UnsupportedOperationException
    • replaceChildren

      protected void replaceChildren(List<T> values, int start, SafeHtml html)
      Description copied from class: AbstractHasData
      Convert the specified HTML into DOM elements and replace the existing elements starting at the specified index. If the number of children specified exceeds the existing number of children, the remaining children should be appended.
      Overrides:
      replaceChildren in class AbstractHasData<T>
      Parameters:
      values - the values of the new children
      start - the start index to be replaced, relative to the page start
      html - the html to render, or null if AbstractHasData.renderRowValues(SafeHtmlBuilder, List, int, SelectionModel) throws an UnsupportedOperationException
    • resetFocusOnCell

      protected boolean resetFocusOnCell()
      Description copied from class: AbstractHasData
      Reset focus on the currently focused cell.
      Specified by:
      resetFocusOnCell in class AbstractHasData<T>
      Returns:
      true if focus is taken, false if not
    • setKeyboardSelected

      protected void setKeyboardSelected(int index, boolean selected, boolean stealFocus)
      Description copied from class: AbstractHasData
      Update an element to reflect its keyboard selected state.
      Specified by:
      setKeyboardSelected in class AbstractHasData<T>
      Parameters:
      index - the index of the element
      selected - true if selected, false if not
      stealFocus - true if the row should steal focus, false if not
    • getColumnWidth

      String getColumnWidth(int columnIndex)
      Get the column width. Associating a width with a Column takes precedence over setting the width of a column index.
      Parameters:
      columnIndex - the column index
      Returns:
      the column width, or null if none specified
    • getSubRowElement

      protected TableRowElement getSubRowElement(int absRow, int subrow)
      Get a subrow element given the index of the row value and the sub row index.
      Parameters:
      absRow - the absolute row value index
      subrow - the index of the subrow beneath the row.
      Returns:
      the row element, or null if not found