Class GridManager<T,C extends GridCell<T>>
- Type Parameters:
T- the type of itemsC- the type of cell used
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
-
Property Summary
PropertiesTypePropertyDescriptionio.github.palexdev.mfxcore.base.properties.range.IntegerRangePropertySpecifies the last range of columns.io.github.palexdev.mfxcore.base.properties.range.IntegerRangePropertySpecifies the last range of rows.Keeps theGridStateobject which represents the current state of the viewport. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Responsible for clearing the viewport and resetting the manager' state.io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>Gets the value of thelastColumnsRangeproperty.io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>Gets the value of thelastRowsRangeproperty.getState()Gets the value of thestateproperty.booleaninit()This is responsible for filling the viewport with the right amount of rows/columns/cells.protected booleanio.github.palexdev.mfxcore.base.properties.range.IntegerRangePropertySpecifies the last range of columns.io.github.palexdev.mfxcore.base.properties.range.IntegerRangePropertySpecifies the last range of rows.voidThis is responsible for handling changes occurring in the grid's items data structure.voidThis is responsible for handling horizontal scrolling.voidThis is responsible for handling vertical scrolling.voidreset()Responsible for resetting the viewport.voidsetLastColumnsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastColumnsRange) Sets the value of thelastColumnsRangeproperty.voidsetLastRowsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastRowsRange) Sets the value of thelastRowsRangeproperty.protected voidSets the value of thestateproperty.Keeps theGridStateobject which represents the current state of the viewport.
-
Property Details
-
state
Keeps theGridStateobject which represents the current state of the viewport.- See Also:
-
lastRowsRange
public io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty lastRowsRangePropertySpecifies the last range of rows. -
lastColumnsRange
public io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty lastColumnsRangePropertySpecifies the last range of columns.
-
-
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
The second step is to distinguish between two cases:GridHelper.computeEstimatedSize().1) The old/current state is
GridState.EMPTY2) 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 withGridState.addRow(int). Since the viewport is empty we also need to callGridState.cellsChanged(). Last but not least we update all the properties of the manager, and then request the viewport layout withVirtualGrid.requestViewportLayout(). In the second case we callGridState.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, callGridState.cellsChanged()and thenVirtualGrid.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 rangeThe 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 rangeThe 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
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.EMPTYstate than we must callinit()- if the change is of type
In any other case we can callGridChangeType.TRANSPOSEthen wereset()the viewportGridState.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() -
itemsEmpty
protected boolean itemsEmpty()- Returns:
- whether the data structure is empty
-
getState
Gets the value of thestateproperty.- Property description:
- Keeps the
GridStateobject which represents the current state of the viewport. - Returns:
- the value of the
stateproperty - See Also:
-
stateProperty
Keeps theGridStateobject which represents the current state of the viewport.- Returns:
- the
stateproperty - See Also:
-
setState
Sets the value of thestateproperty.- Property description:
- Keeps the
GridStateobject which represents the current state of the viewport. - Parameters:
state- the value for thestateproperty- See Also:
-
getLastRowsRange
Gets the value of thelastRowsRangeproperty.- Property description:
- Specifies the last range of rows.
- Returns:
- the value of the
lastRowsRangeproperty - See Also:
-
lastRowsRangeProperty
public io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty lastRowsRangeProperty()Specifies the last range of rows.- Returns:
- the
lastRowsRangeproperty - See Also:
-
setLastRowsRange
public void setLastRowsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastRowsRange) Sets the value of thelastRowsRangeproperty.- Property description:
- Specifies the last range of rows.
- Parameters:
lastRowsRange- the value for thelastRowsRangeproperty- See Also:
-
getLastColumnsRange
Gets the value of thelastColumnsRangeproperty.- Property description:
- Specifies the last range of columns.
- Returns:
- the value of the
lastColumnsRangeproperty - See Also:
-
lastColumnsRangeProperty
public io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty lastColumnsRangeProperty()Specifies the last range of columns.- Returns:
- the
lastColumnsRangeproperty - See Also:
-
setLastColumnsRange
public void setLastColumnsRange(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastColumnsRange) Sets the value of thelastColumnsRangeproperty.- Property description:
- Specifies the last range of columns.
- Parameters:
lastColumnsRange- the value for thelastColumnsRangeproperty- See Also:
-