- All Implemented Interfaces:
Cloneable
VFXTable
is a specific moment in time. In other words
every state is given by a unique combination of the table's properties (in terms of values).
The state carries six important pieces of information:
1) The range of rows to display
2) The range of columns to display
3) The rows that are currently in the viewport
4) A flag that indicates whether rows have changed since the last state (either the rows map or range)
5) A flag that indicates whether columns have changed since the last state (the range)
6) A flag that indicates whether this state is a clone of a previous state
Global state and "sub-state"
The table component is a bit different from others. Cells are not placed directly in the viewport but are
wrapped in rows as also explained here VFXTable
. Because of this, the state class keeps track of how many and
which rows/items are to be displayed in the viewport. However, there is absolutely no information regarding the cells.
This important piece of data is stored in each row; they also have a particular type of IndexBiMap
to keep
track of how many cells and which columns are to be displayed in the viewport.
I like to refer to this class as the global state
mainly for two reasons: 1) this is what the table's subsystems
use to work, 2) Even if cells' infos are not directly available here, this keeps track of the rows, which means that
we can indeed get them.
As already said above, the state class has a special flag which indicates whether an instance was produced by cloning
another state object (with clone()
).
Q: Why?
A: This mechanism is mainly a consequence of the above explanation about global and sub-states. There may be changes
in the table that do not need to produce a new VFXTableState
(e.g., a column changing its cell factory).
Still, I wanted the system to inform users that a change did indeed happen. Creating a new state from scratch would have
been a waste of performance. So, I decided to implement the clone()
method to pass every variable from one
state to a new one without any alteration. This way, the VFXTable.stateProperty()
would trigger a change event
because instances would be different.
The only issue with such mechanism is that in most cases a clone state can be used, we don't want the table's skin to
do anything (no layout should be needed). This can be done by checking the flag with isClone()
.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final VFXTableState
Special instance ofVFXTableState
used to indicate that no columns can be present in the viewport at a certain time. -
Constructor Summary
ConstructorsModifierConstructorDescriptionVFXTableState
(VFXTable<T> table, io.github.palexdev.mfxcore.base.beans.range.IntegerRange rowsRange, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columnsRange) protected
VFXTableState
(VFXTable<T> table, io.github.palexdev.mfxcore.base.beans.range.IntegerRange rowsRange, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columnsRange, IndexBiMap.StateMap<T, VFXTableRow<T>> rows) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addRow
(int index, VFXTableRow<T> row) Delegates toaddRow(int, Object, VFXTableRow)
by retrieving theT
item from the items' list at the given index.protected void
addRow
(int index, T item, VFXTableRow<T> row) Adds the given row to theIndexBiMap.StateMap
of this state object.int
cellsNum()
clone()
Creates a newVFXTableState
instance with the exact same parameters of this state.protected void
dispose()
Disposes this state by caching and clearing all of its rows.io.github.palexdev.mfxcore.base.beans.range.IntegerRange
protected IndexBiMap.StateMap
<T, VFXTableRow<T>> getRows()
protected SequencedMap
<Integer, VFXTableRow<T>> protected List
<Map.Entry<T, VFXTableRow<T>>> List
<Map.Entry<T, VFXTableRow<T>>> io.github.palexdev.mfxcore.base.beans.range.IntegerRange
getTable()
boolean
boolean
boolean
isClone()
boolean
isEmpty()
boolean
protected VFXTableRow
<T> removeRow
(int index) Attempts at to remove a row from theIndexBiMap.StateMap
first by the given index and in case it is not found by converting the index to an object in the items' list.protected VFXTableRow
<T> Removes a row by the given item from theIndexBiMap.StateMap
.protected void
setColumnsChanged
(boolean columnsChanged) protected void
setColumnsChanged
(VFXTableState<T> other) protected void
setRowsChanged
(boolean rowsChanged) int
size()
-
Field Details
-
INVALID
Special instance ofVFXTableState
used to indicate that no columns can be present in the viewport at a certain time. The reasons can be many, for example, invalid range, width/height <= 0, etc...This and
isEmpty()
are two totally different things!!
-
-
Constructor Details
-
VFXTableState
-
VFXTableState
protected VFXTableState(VFXTable<T> table, io.github.palexdev.mfxcore.base.beans.range.IntegerRange rowsRange, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columnsRange, IndexBiMap.StateMap<T, VFXTableRow<T>> rows)
-
-
Method Details
-
addRow
Delegates toaddRow(int, Object, VFXTableRow)
by retrieving theT
item from the items' list at the given index.- See Also:
-
addRow
Adds the given row to theIndexBiMap.StateMap
of this state object.- See Also:
-
removeRow
Attempts at to remove a row from theIndexBiMap.StateMap
first by the given index and in case it is not found by converting the index to an object in the items' list.- See Also:
-
removeRow
Removes a row by the given item from theIndexBiMap.StateMap
.- See Also:
-
dispose
protected void dispose()Disposes this state by caching and clearing all of its rows. TheIndexBiMap.StateMap
is also cleared.- See Also:
-
clone
Creates a newVFXTableState
instance with the exact same parameters of this state. Also, the new state'sclone
flag is set to true. -
getTable
- Returns:
- the
VFXTable
instance this state is associated to
-
getRowsRange
public io.github.palexdev.mfxcore.base.beans.range.IntegerRange getRowsRange()- Returns:
- the range of rows to display
-
getColumnsRange
public io.github.palexdev.mfxcore.base.beans.range.IntegerRange getColumnsRange()- Returns:
- the range of columns to display
-
getRows
- Returns:
- the map containing the rows
- See Also:
-
getRowsByIndex
- Returns:
- the map containing the rows by their index
-
getRowsByItem
- Returns:
- the list containing the rows by their item, as entries because of possible duplicates
- See Also:
-
getRowsByIndexUnmodifiable
- Returns:
- the map containing the rows by their index, unmodifiable
-
getRowsByItemUnmodifiable
- Returns:
- the list containing the rows by their item, as entries because of possible duplicates, unmodifiable
- See Also:
-
cellsNum
public int cellsNum()- Returns:
- the total number of cells by summing the number cells of each row in the
IndexBiMap.StateMap
-
size
public int size()- Returns:
- the number of rows in the
IndexBiMap.StateMap
-
isEmpty
public boolean isEmpty()- Returns:
- whether the
IndexBiMap.StateMap
is empty - See Also:
-
haveRowsChanged
public boolean haveRowsChanged()- Returns:
- whether the rows have changed since the last state. Used by the default skin to check whether the viewport has to update its children or not.
- See Also:
-
setRowsChanged
protected void setRowsChanged(boolean rowsChanged) - See Also:
-
haveColumnsChanged
public boolean haveColumnsChanged()- Returns:
- whether the columns have changed since the last state. Used by the default skin to check whether the viewport has to update its children or not.
- See Also:
-
setColumnsChanged
protected void setColumnsChanged(boolean columnsChanged) - See Also:
-
setColumnsChanged
- See Also:
-
isLayoutNeeded
public boolean isLayoutNeeded()- Returns:
- whether either
haveRowsChanged()
orhaveColumnsChanged()
are true, which in general means that layout needs to be re-computed.
-
isClone
public boolean isClone()- Returns:
- whether this state object is a clone of a previous state
-