Module MaterialFX

Class MultipleSelectionManager<T>

java.lang.Object
io.github.palexdev.materialfx.selection.MultipleSelectionManager<T>

public class MultipleSelectionManager<T> extends Object
Helper class that is capable of managing/update MultipleSelectionModels.
  • Property Summary

    Properties
    Type
    Property
    Description
    The MapProperty used to keep track of multiple selection.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Specifies if this model allows multiple selection or should act like a SingleSelectionModel.
    void
    Clears the selection by setting it to an empty map.
    void
    deselectIndex(int index)
    Removes the given index from the selection map.
    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.
    void
    Retrieves the index of the given item from the items list and if it's not -1 removes it from the selection map.
    void
    deselectItems(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.
    void
    expandSelection(int index)
    This is responsible for expanding the selection in the given index direction.
    Builds a new observable hash map backed by a LinkedHashMap.
    Builds a new observable hash map backed by a LinkedHashMap, initialized with the given map.
    Returns an unmodifiable List containing all the selected values extracted from Map.values().
     
    void
    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.
    void
    replaceSelection(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.
    The MapProperty used to keep track of multiple selection.
    void
    setAllowsMultipleSelection(boolean allowsMultipleSelection)
    Sets the selection behavior of this model to be multiple (true) or single (false).
    void
    Replaces the selection with the given ObservableMap.
    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.
    void
    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.
    void
    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.
    void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Property Details

  • Constructor Details

  • 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

      public void deselectItem(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.
    • 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

      public void deselectItems(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.
    • 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

      public void updateSelection(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.
    • updateSelectionByIndexes

      public void updateSelectionByIndexes(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.
    • updateSelectionByItems

      public void updateSelectionByItems(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.
    • 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

      public void replaceSelection(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.
    • replaceSelection

      public void replaceSelection(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.
    • getMap

      protected ObservableMap<Integer,T> getMap()
      Builds a new observable hash map backed by a LinkedHashMap.
    • getMap

      protected ObservableMap<Integer,T> getMap(Map<Integer,T> map)
      Builds a new observable hash map backed by a LinkedHashMap, initialized with the given map.
    • getSelection

      public ObservableMap<Integer,T> getSelection()
      Returns:
      the selection ObservableMap
    • selectionProperty

      public MapProperty<Integer,T> selectionProperty()
      The MapProperty used to keep track of multiple selection.

      We use a MapProperty to 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

      public void setSelection(ObservableMap<Integer,T> selection)
      Replaces the selection with the given ObservableMap.
    • getSelectedValues

      public List<T> getSelectedValues()
      Returns an unmodifiable List containing all the selected values extracted from Map.values(). The values order is kept since the selection is backed by a LinkedHashMap.
    • 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.