java.lang.Object
io.github.palexdev.materialfx.selection.MultipleSelectionManager<T>
Helper class that is capable of managing/update MultipleSelectionModels.
-
Property Summary
Properties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanSpecifies if this model allows multiple selection or should act like a SingleSelectionModel.voidClears the selection by setting it to an empty map.voiddeselectIndex(int index) Removes the given index from the selection map.voiddeselectIndexes(int... indexes) Removes all the specified indexes from the selection map, done by creating a tmp map, updating the tmp map and then replacing the selection with this new map.voiddeselectItem(T item) Retrieves the index of the given item from the items list and if it's not -1 removes it from the selection map.voiddeselectItems(T... items) Filters the items list to check if the given items exist, then retrieves their index and collect them to a tmp map, then replaces the selection with this new map.voidexpandSelection(int index) This is responsible for expanding the selection in the given index direction.protected ObservableMap<Integer,T> getMap()Builds a new observable hash map backed by aLinkedHashMap.protected ObservableMap<Integer,T> Builds a new observable hash map backed by aLinkedHashMap, initialized with the given map.Returns an unmodifiableListcontaining all the selected values extracted fromMap.values().voidreplaceSelection(Integer... indexes) If multiple selection is allowed replaces the selection with all the given indexes (and the retrieved items), otherwise replaces the selection with the first given index.voidreplaceSelection(T... items) If multiple selection is allowed replaces the selection with all the given items (and the retrieved indexes), otherwise replaces the selection with the first given item.TheMapPropertyused to keep track of multiple selection.voidsetAllowsMultipleSelection(boolean allowsMultipleSelection) Sets the selection behavior of this model to be multiple (true) or single (false).voidsetSelection(ObservableMap<Integer, T> selection) Replaces the selection with the givenObservableMap.voidupdateSelection(int index) If multiple selection is allowed adds the given index (and the retrieved item) to the selection map, otherwise creates a new tmp map containing only the given index-item entry and replaces the selection.voidupdateSelection(T item) If multiple selection is allowed adds the given item (and the retrieved index) to the selection map, otherwise creates a new tmp map containing only the given index-item entry and replaces the selection.voidupdateSelectionByIndexes(List<Integer> indexes) If multiple selection is allowed adds all the given indexes to the selection (and the retrieved items), otherwise replaces the selection with the first index given in the list.voidupdateSelectionByItems(List<T> items) If multiple selection is allowed adds all the given items to the selection (and the retrieved indexes), otherwise replaces the selection with the first item given in the list.
-
Property Details
-
selection
TheMapPropertyused to keep track of multiple selection. We use aMapPropertyto represent multiple selection because this way we can always update it "atomically", meaning that when the selected indexes changes the selected items are updated as well (also true viceversa).- See Also:
-
-
Constructor Details
-
MultipleSelectionManager
-
-
Method Details
-
clearSelection
public void clearSelection()Clears the selection by setting it to an empty map. -
deselectIndex
public void deselectIndex(int index) Removes the given index from the selection map. -
deselectItem
Retrieves the index of the given item from the items list and if it's not -1 removes it from the selection map. -
deselectIndexes
public void deselectIndexes(int... indexes) Removes all the specified indexes from the selection map, done by creating a tmp map, updating the tmp map and then replacing the selection with this new map. -
deselectItems
Filters the items list to check if the given items exist, then retrieves their index and collect them to a tmp map, then replaces the selection with this new map. -
updateSelection
public void updateSelection(int index) If multiple selection is allowed adds the given index (and the retrieved item) to the selection map, otherwise creates a new tmp map containing only the given index-item entry and replaces the selection. -
updateSelection
If multiple selection is allowed adds the given item (and the retrieved index) to the selection map, otherwise creates a new tmp map containing only the given index-item entry and replaces the selection. -
updateSelectionByIndexes
If multiple selection is allowed adds all the given indexes to the selection (and the retrieved items), otherwise replaces the selection with the first index given in the list. -
updateSelectionByItems
If multiple selection is allowed adds all the given items to the selection (and the retrieved indexes), otherwise replaces the selection with the first item given in the list. -
expandSelection
public void expandSelection(int index) This is responsible for expanding the selection in the given index direction. There are 4 cases to consider:1) The selection is empty: the new selection will go from [0 to index]
2) The minimum selected index is equal to the given index: the new selection will just be [index]
3) The given index is lesser than the minimum index: the new selection will go from [index to min]
4) The given index is greater than the minimum index: the new selection will go from [min to index]
-
replaceSelection
If multiple selection is allowed replaces the selection with all the given indexes (and the retrieved items), otherwise replaces the selection with the first given index. -
replaceSelection
If multiple selection is allowed replaces the selection with all the given items (and the retrieved indexes), otherwise replaces the selection with the first given item. -
getMap
Builds a new observable hash map backed by aLinkedHashMap. -
getMap
Builds a new observable hash map backed by aLinkedHashMap, initialized with the given map. -
getSelection
- Returns:
- the selection
ObservableMap
-
selectionProperty
TheMapPropertyused to keep track of multiple selection. We use aMapPropertyto represent multiple selection because this way we can always update it "atomically", meaning that when the selected indexes changes the selected items are updated as well (also true viceversa).- See Also:
-
setSelection
Replaces the selection with the givenObservableMap. -
getSelectedValues
Returns an unmodifiableListcontaining all the selected values extracted fromMap.values(). The values order is kept since the selection is backed by aLinkedHashMap. -
allowsMultipleSelection
public boolean allowsMultipleSelection()Specifies if this model allows multiple selection or should act like a SingleSelectionModel. -
setAllowsMultipleSelection
public void setAllowsMultipleSelection(boolean allowsMultipleSelection) Sets the selection behavior of this model to be multiple (true) or single (false).If it's set to false the selection is cleared.
-