Class TableManager<T>

java.lang.Object
io.github.palexdev.virtualizedfx.table.TableManager<T>
Type Parameters:
T - the type of items

public class TableManager<T> extends Object
The FlowManager is responsible for managing the table's viewport, track its current TableState and trigger states transitions.

It stores the state of the viewport at any given time with three properties:

- the main one is the stateProperty() which holds the TableState object representing the current state of the viewport

- the last rows range property, which holds the last range of displayed rows as a IntegerRange

- the last columns range property, which holds the last range of displayed columns as a IntegerRange

As mentioned above this is also responsible for handling states transitions when: initializations occur (cells supply and removals when the viewport size changes); vertical and horizontal scrolling; changes occurred in the items list, as well as clear and reset of the viewport when needed
  • Property Details

  • Method Details

    • init

      public boolean init()
      This is responsible for filling the viewport with the right amount of rows/columns/cells. So, it is a bit more than just an initialization method since this is also called for example when the viewport size changes and cells may need to be added or removed.

      The first step is to gather a series of useful information such as:

      - the expected range of rows, TableHelper.rowsRange()

      - the expected range of columns, TableHelper.columnsRange()

      - the old/current state, stateProperty()

      We also ensure that the estimated size of the viewport is correct by calling TableHelper.computeEstimatedSize().

      The second step is to distinguish between two cases:

      1) The old/current state is TableState.EMPTY

      2) The old/current state is a valid state

      In the first case it means that the viewport is empty. For each row in the expected rows range we add a row to the new state with TableState.addRow(int). Since the viewport is empty we also need to call TableState.rowsChanged(). Last but not least we update all the properties of the manager, and then request the viewport layout with VirtualTable.requestViewportLayout().

      In the second case we call TableState.init(IntegerRange, IntegerRange) on the old/current state so that a new state, which reuses when possible the current already present rows, can be computed. At this point a special check is needed, the aforementioned method could also return the old/current state for whatever reason, in such case there's no need to proceed and the method exits immediately. Otherwise, same as above, update all the properties, call TableState.rowsChanged() and then VirtualTable.requestViewportLayout().
      Returns:
      in addition to the various computations made in this method, it also returns a boolean value to indicate whether computations lead to a layout request or not, VirtualTable.requestViewportLayout()
    • onVScroll

      public void onVScroll()
      This is responsible for handling vertical scrolling.

      If the current state is empty exits immediately.

      Before transitioning to a new state and eventually requesting a layout computation to the grid, we must check some parameters.

      First we compute the rows range and if that is not equal to the range of the current state then we call TableState.vScroll(IntegerRange) to create a new state which will contain all the needed rows for the new range

      The layout instead uses a different range and is compared against the last rows range, if they are not equal then VirtualTable.requestViewportLayout() is invoked.

      At the end the last rows range property is updated.

    • onHScroll

      public void onHScroll()
      This is responsible for handling horizontal scrolling.

      If the current state is empty exits immediately.

      Before transitioning to a new state and eventually requesting a layout computation to the grid, we must check some parameters.

      First we compute the columns range and if that is not equal to the range of the current state then we call TableState.hScroll(IntegerRange) to create a new state which will contain all the needed columns for the new range

      The layout instead uses a different range and is compared against the last columns range, if they are not equal then VirtualTable.requestViewportLayout() is invoked.

      At the end the last columns range property is updated.

    • onChange

      public void onChange(ListChangeListener.Change<? extends T> change)
      This is responsible for updating the viewport state whenever a change occurs in the items list.

      There are three separate situations:

      1) The items list is empty, calls clear() and exits

      2) The current state is TableState.EMPTY, calls init() and exits

      3) The given change is processed by using the ListChangeHelper utility class, then the new state is computed by using TableState.processChange(Change), finally VirtualTable.requestViewportLayout() is called and the last range property is updated.

    • onColumnChangedFactory

      public void onColumnChangedFactory(TableColumn<T,? extends TableCell<T>> column)
      This is responsible for transitioning to a new valid state when a cell factory ahs changed for a certain column. The state is computed with TableState.columnChangedFactory(TableColumn).

      At the end VirtualTable.requestViewportLayout() is invoked.

    • clear

      public void clear()
      Clears the viewport. Sets the state to FlowState.EMPTY.
    • reset

      public void reset()
      Resets the viewport by first calling clear(), then init().
    • getState

      public TableState<T> getState()
      Gets the value of the property state.
      Property description:
      Specifies the current state of the viewport as a TableState object.
    • stateProperty

      public TableStateProperty<T> stateProperty()
      Specifies the current state of the viewport as a TableState object.
      See Also:
    • setState

      protected void setState(TableState<T> state)
      Sets the value of the property state.
      Property description:
      Specifies the current state of the viewport as a TableState object.
    • getLastRowsRange

      public io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> getLastRowsRange()
      Gets the value of the property lastRowsRange.
      Property description:
      Specifies the last range of rows.
    • lastRowsRangeProperty

      public io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty lastRowsRangeProperty()
      Specifies the last range of rows.
      See Also:
    • setLastRowsRange

      protected void setLastRowsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastRowsRange)
      Sets the value of the property lastRowsRange.
      Property description:
      Specifies the last range of rows.
    • getLastColumnsRange

      public io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> getLastColumnsRange()
      Gets the value of the property lastColumnsRange.
      Property description:
      Specifies the last range of columns.
    • lastColumnsRangeProperty

      public io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty lastColumnsRangeProperty()
      Specifies the last range of columns.
      See Also:
    • setLastColumnsRange

      protected void setLastColumnsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastColumnsRange)
      Sets the value of the property lastColumnsRange.
      Property description:
      Specifies the last range of columns.
    • isProcessingChange

      public boolean isProcessingChange()
      Returns:
      whether a change is being processed by onChange(ListChangeListener.Change)