Class GridManager<T,C extends GridCell<T>>

java.lang.Object
io.github.palexdev.virtualizedfx.grid.GridManager<T,C>
Type Parameters:
T - the type of items
C - the type of cell used

public class GridManager<T,C extends GridCell<T>> extends Object
The FlowManager is responsible for managing the grid's viewport, track its current GridState 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 GridState 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 data structure; clear and reset the viewport when needed.
  • Property Summary

    Properties
    Type
    Property
    Description
    io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty
    Specifies the last range of columns.
    io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty
    Specifies the last range of rows.
    Keeps the GridState object which represents the current state of the viewport.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Responsible for clearing the viewport and resetting the manager' state.
    io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>
    Gets the value of the lastColumnsRange property.
    io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>
    Gets the value of the lastRowsRange property.
    Gets the value of the state property.
    boolean
    This is responsible for filling the viewport with the right amount of rows/columns/cells.
    protected boolean
     
    io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty
    Specifies the last range of columns.
    io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty
    Specifies the last range of rows.
    void
    onChange(io.github.palexdev.mfxcore.collections.ObservableGrid.Change<T> change)
    This is responsible for handling changes occurring in the grid's items data structure.
    void
    This is responsible for handling horizontal scrolling.
    void
    This is responsible for handling vertical scrolling.
    void
    Responsible for resetting the viewport.
    void
    setLastColumnsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastColumnsRange)
    Sets the value of the lastColumnsRange property.
    void
    setLastRowsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastRowsRange)
    Sets the value of the lastRowsRange property.
    protected void
    Sets the value of the state property.
    Keeps the GridState object which represents the current state of the viewport.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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, GridHelper.rowsRange()

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

      - the old/current state, stateProperty()

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

      The second step is to distinguish between two cases:

      1) The old/current state is GridState.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 GridState.addRow(int). Since the viewport is empty we also need to call GridState.cellsChanged(). Last but not least we update all the properties of the manager, and then request the viewport layout with VirtualGrid.requestViewportLayout().

      In the second case we call GridState.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 GridState.cellsChanged() and then VirtualGrid.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, VirtualGrid.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 GridState.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 VirtualGrid.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 GridState.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 VirtualGrid.requestViewportLayout() is invoked.

      At the end the last columns range property is updated.

    • onChange

      public void onChange(io.github.palexdev.mfxcore.collections.ObservableGrid.Change<T> change)
      This is responsible for handling changes occurring in the grid's items data structure.

      Before transitioning to a new state, there are three special cases that need to be covered:

      - if there are no items in the data structure (was cleared), we invoke clear()

      - if the current state is the GridState.EMPTY state than we must call init()

      - if the change is of type GridChangeType.TRANSPOSE then we reset() the viewport

      In any other case we can call GridState.change(Change) on the current state to produce a new state that reflects the changes occurred in the data structure. At the end a layout request is sent to the grid, VirtualGrid.requestViewportLayout() and both the last rows and columns ranges are updated.
    • clear

      public void clear()
      Responsible for clearing the viewport and resetting the manager' state.
    • reset

      public void reset()
      Responsible for resetting the viewport. First it calls clear() then init().
    • itemsEmpty

      protected boolean itemsEmpty()
      Returns:
      whether the data structure is empty
    • getState

      public GridState<T,C> getState()
      Gets the value of the state property.
      Property description:
      Keeps the GridState object which represents the current state of the viewport.
      Returns:
      the value of the state property
      See Also:
    • stateProperty

      public GridStateProperty<T,C> stateProperty()
      Keeps the GridState object which represents the current state of the viewport.
      Returns:
      the state property
      See Also:
    • setState

      protected void setState(GridState<T,C> state)
      Sets the value of the state property.
      Property description:
      Keeps the GridState object which represents the current state of the viewport.
      Parameters:
      state - the value for the state property
      See Also:
    • getLastRowsRange

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

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

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

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

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

      public void setLastColumnsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastColumnsRange)
      Sets the value of the lastColumnsRange property.
      Property description:
      Specifies the last range of columns.
      Parameters:
      lastColumnsRange - the value for the lastColumnsRange property
      See Also: