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.IntegerRangeProperty
Specifies the last range of columns.io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty
Specifies the last range of rows.Keeps theGridState
object which represents the current state of the viewport. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Responsible for clearing the viewport and resetting the manager' state.io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>
Gets the value of thelastColumnsRange
property.io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>
Gets the value of thelastRowsRange
property.getState()
Gets the value of thestate
property.boolean
init()
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
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
reset()
Responsible for resetting the viewport.void
setLastColumnsRange
(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastColumnsRange) Sets the value of thelastColumnsRange
property.void
setLastRowsRange
(io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> lastRowsRange) Sets the value of thelastRowsRange
property.protected void
Sets the value of thestate
property.Keeps theGridState
object which represents the current state of the viewport.
-
Property Details
-
state
Keeps theGridState
object 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.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 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.EMPTY
state than we must callinit()
- if the change is of type
In any other case we can callGridChangeType.TRANSPOSE
then 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 thestate
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
Keeps theGridState
object which represents the current state of the viewport.- Returns:
- the
state
property - See Also:
-
setState
Sets the value of thestate
property.- Property description:
- Keeps the
GridState
object which represents the current state of the viewport. - Parameters:
state
- the value for thestate
property- See Also:
-
getLastRowsRange
Gets the value of thelastRowsRange
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 thelastRowsRange
property.- Property description:
- Specifies the last range of rows.
- Parameters:
lastRowsRange
- the value for thelastRowsRange
property- See Also:
-
getLastColumnsRange
Gets the value of thelastColumnsRange
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 thelastColumnsRange
property.- Property description:
- Specifies the last range of columns.
- Parameters:
lastColumnsRange
- the value for thelastColumnsRange
property- See Also:
-