Top Description Fields Constructors Methods
com.dlsc.gemsfx.util

public Class CustomMultipleSelectionModel<T>

extends MultipleSelectionModel<T>
Class Inheritance
Type Parameters
<T>
the type of the items contained in the selection model.
Imports
javafx.beans.InvalidationListener, .WeakInvalidationListener, javafx.beans.property.ListProperty, .ReadOnlyListWrapper, .SimpleListProperty, javafx.collections.FXCollections, .ListChangeListener, .ObservableList, javafx.scene.control.MultipleSelectionModel, .SelectionMode, java.lang.ref.WeakReference, java.util.ArrayList, .HashMap, .List, .Map

CustomMultipleSelectionModel allows for managing the selection state of items in an ObservableList. It extends from MultipleSelectionModel and adds functionality to maintain a weak reference to the items list, facilitating the handling of list changes and ensuring selection consistency.

Field Summary

Modifier and TypeField and Description
private final ListProperty<T>
private final ListChangeListener<T>
private final InvalidationListener
private final ReadOnlyListWrapper<Integer>
private final ReadOnlyListWrapper<T>
private WeakReference<ObservableList<T>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
clearAndSelect(int index)

Implements abstract javafx.scene.control.SelectionModel.clearAndSelect.

A method that clears any selection prior to setting the selection to the given index.

public void
clearSelection(int index)

Implements abstract javafx.scene.control.SelectionModel.clearSelection.

This method will clear the selection of the item in the given index.

public void
clearSelection()

Implements abstract javafx.scene.control.SelectionModel.clearSelection.

Clears the selection model of all selected indices.

public final ObservableList<T>
public ObservableList<Integer>
getSelectedIndices()

Implements abstract javafx.scene.control.MultipleSelectionModel.getSelectedIndices.

Returns a read-only ObservableList of all selected indices.

public ObservableList<T>
getSelectedItems()

Implements abstract javafx.scene.control.MultipleSelectionModel.getSelectedItems.

Returns a read-only ObservableList of all selected items.

public boolean
isEmpty()

Implements abstract javafx.scene.control.SelectionModel.isEmpty.

This method is available to test whether there are any selected indices/items.

public boolean
isSelected(int index)

Implements abstract javafx.scene.control.SelectionModel.isSelected.

This method tests whether the given index is currently selected in this SelectionModel.

public final ListProperty<T>
private void
permuteSelection(int[] perm)

private void
removeIndices(ListChangeListener.Change<? extends T>
the ListChangeListener.Change instance that describes the changes to the list and which indices should be removed from the selection.
c
)

Removes the indices and items from the selection model based on the change described by the provided ListChangeListener.Change instance.

public void
select(int index)

Implements abstract javafx.scene.control.SelectionModel.select.

This will select the given index in the selection model, assuming the index is within the valid range (i.e. greater than or equal to zero, and less than the total number of items in the underlying data model).

public void
select(T obj)

Implements abstract javafx.scene.control.SelectionModel.select.

This method will attempt to select the index that contains the given object.

public void
selectAll()

Implements abstract javafx.scene.control.MultipleSelectionModel.selectAll.

Convenience method to select all available indices.

public void
selectFirst()

Implements abstract javafx.scene.control.MultipleSelectionModel.selectFirst.

This method will attempt to select the first index in the control.

public void
selectIndices(int index, int... indices)

Implements abstract javafx.scene.control.MultipleSelectionModel.selectIndices.

This method allows for one or more selections to be set at the same time.

public void
selectLast()

Implements abstract javafx.scene.control.MultipleSelectionModel.selectLast.

This method will attempt to select the last index in the control.

public void
selectNext()

Implements abstract javafx.scene.control.SelectionModel.selectNext.

This method will attempt to select the index directly after the current focused index.

public void
selectPrevious()

Implements abstract javafx.scene.control.SelectionModel.selectPrevious.

This method will attempt to select the index directly before the current focused index.

public final void
private void
updateItemsObserver()

Updates the observer for the items list.

private void
private void
updateSelectionOnItemsChange(ListChangeListener.Change<? extends T> c)

Updates the selection model when the items list changes.

private void
Inherited from javafx.scene.control.MultipleSelectionModel:
getSelectionModeselectionModePropertyselectRangesetSelectionMode

Field Detail

itemsback to summary
private final ListProperty<T> items
itemsContentListenerback to summary
private final ListChangeListener<T> itemsContentListener
itemsPropertyListenerback to summary
private final InvalidationListener itemsPropertyListener
selectedIndicesback to summary
private final ReadOnlyListWrapper<Integer> selectedIndices
selectedItemsback to summary
private final ReadOnlyListWrapper<T> selectedItems
weakItemsRefback to summary
private WeakReference<ObservableList<T>> weakItemsRef

Constructor Detail

CustomMultipleSelectionModelback to summary
public CustomMultipleSelectionModel()

Method Detail

addIndicesback to summary
private void addIndices(ListChangeListener.Change<? extends T> c)
clearAndSelectback to summary
public void clearAndSelect(int index)

Implements abstract javafx.scene.control.SelectionModel.clearAndSelect.

Doc from javafx.scene.control.SelectionModel.clearAndSelect.

A method that clears any selection prior to setting the selection to the given index. The purpose of this method is to avoid having to call clearSelection() first, meaning that observers that are listening to the selected index property will not see the selected index being temporarily set to -1.

Annotations
@Override
clearSelectionback to summary
public void clearSelection(int index)

Implements abstract javafx.scene.control.SelectionModel.clearSelection.

Doc from javafx.scene.control.SelectionModel.clearSelection.

This method will clear the selection of the item in the given index. If the given index is not selected, nothing will happen.

Annotations
@Override
clearSelectionback to summary
public void clearSelection()

Implements abstract javafx.scene.control.SelectionModel.clearSelection.

Doc from javafx.scene.control.SelectionModel.clearSelection.

Clears the selection model of all selected indices.

Annotations
@Override
getItemsback to summary
public final ObservableList<T> getItems()
getSelectedIndicesback to summary
public ObservableList<Integer> getSelectedIndices()

Implements abstract javafx.scene.control.MultipleSelectionModel.getSelectedIndices.

Doc from javafx.scene.control.MultipleSelectionModel.getSelectedIndices.

Returns a read-only ObservableList of all selected indices. The ObservableList will be updated by the selection model to always reflect changes in selection. This can be observed by adding a ListChangeListener to the returned ObservableList.

Annotations
@Override
getSelectedItemsback to summary
public ObservableList<T> getSelectedItems()

Implements abstract javafx.scene.control.MultipleSelectionModel.getSelectedItems.

Doc from javafx.scene.control.MultipleSelectionModel.getSelectedItems.

Returns a read-only ObservableList of all selected items. The ObservableList will be updated further by the selection model to always reflect changes in selection. This can be observed by adding a ListChangeListener to the returned ObservableList.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements abstract javafx.scene.control.SelectionModel.isEmpty.

Doc from javafx.scene.control.SelectionModel.isEmpty.

This method is available to test whether there are any selected indices/items. It will return true if there are no selected items, and false if there are.

Annotations
@Override
isSelectedback to summary
public boolean isSelected(int index)

Implements abstract javafx.scene.control.SelectionModel.isSelected.

Doc from javafx.scene.control.SelectionModel.isSelected.

This method tests whether the given index is currently selected in this SelectionModel.

Annotations
@Override
itemsPropertyback to summary
public final ListProperty<T> itemsProperty()
permuteSelectionback to summary
private void permuteSelection(int[] perm)
removeIndicesback to summary
private void removeIndices(ListChangeListener.Change<? extends T> c)

Removes the indices and items from the selection model based on the change described by the provided ListChangeListener.Change instance.

Parameters
c:ListChangeListener.Change<? extends T>

the ListChangeListener.Change instance that describes the changes to the list and which indices should be removed from the selection.

selectback to summary
public void select(int index)

Implements abstract javafx.scene.control.SelectionModel.select.

Doc from javafx.scene.control.SelectionModel.select.

This will select the given index in the selection model, assuming the index is within the valid range (i.e. greater than or equal to zero, and less than the total number of items in the underlying data model).

If there is already one or more indices selected in this model, calling this method will not clear these selections - to do so it is necessary to first call clearSelection().

If the index is already selected, it will not be selected again, or unselected. However, if multiple selection is implemented, then calling select on an already selected index will have the effect of making the index the new selected index (as returned by getSelectedIndex().

Annotations
@Override
selectback to summary
public void select(T obj)

Implements abstract javafx.scene.control.SelectionModel.select.

Doc from javafx.scene.control.SelectionModel.select.

This method will attempt to select the index that contains the given object. It will iterate through the underlying data model until it finds an item whose value is equal to the given object. At this point it will stop iterating - this means that this method will not select multiple indices.

Annotations
@Override
selectAllback to summary
public void selectAll()

Implements abstract javafx.scene.control.MultipleSelectionModel.selectAll.

Doc from javafx.scene.control.MultipleSelectionModel.selectAll.

Convenience method to select all available indices.

Annotations
@Override
selectFirstback to summary
public void selectFirst()

Implements abstract javafx.scene.control.MultipleSelectionModel.selectFirst.

Doc from javafx.scene.control.MultipleSelectionModel.selectFirst.

This method will attempt to select the first index in the control. If clearSelection is not called first, this method will have the result of selecting the first index, whilst retaining the selection of any other currently selected indices.

If the first index is already selected, calling this method will have no result, and no selection event will take place.

Annotations
@Override
selectIndicesback to summary
public void selectIndices(int index, int... indices)

Implements abstract javafx.scene.control.MultipleSelectionModel.selectIndices.

Doc from javafx.scene.control.MultipleSelectionModel.selectIndices.

This method allows for one or more selections to be set at the same time. It will ignore any value that is not within the valid range (i.e. greater than or equal to zero, and less than the total number of items in the underlying data model). Any duplication of indices will be ignored.

If there is already one or more indices selected in this model, calling this method will not clear these selections - to do so it is necessary to first call clearSelection.

The last valid value given will become the selected index / selected item.

Annotations
@Override
selectLastback to summary
public void selectLast()

Implements abstract javafx.scene.control.MultipleSelectionModel.selectLast.

Doc from javafx.scene.control.MultipleSelectionModel.selectLast.

This method will attempt to select the last index in the control. If clearSelection is not called first, this method will have the result of selecting the last index, whilst retaining the selection of any other currently selected indices.

If the last index is already selected, calling this method will have no result, and no selection event will take place.

Annotations
@Override
selectNextback to summary
public void selectNext()

Implements abstract javafx.scene.control.SelectionModel.selectNext.

Doc from javafx.scene.control.SelectionModel.selectNext.

This method will attempt to select the index directly after the current focused index. If clearSelection is not called first, this method will have the result of selecting the next index, whilst retaining the selection of any other currently selected indices.

Calling this method will only succeed if:

  • There is currently a lead/focused index.
  • The lead/focus index is not the last index in the control.
  • The next index is not already selected.

If any of these conditions is false, no selection event will take place.

Annotations
@Override
selectPreviousback to summary
public void selectPrevious()

Implements abstract javafx.scene.control.SelectionModel.selectPrevious.

Doc from javafx.scene.control.SelectionModel.selectPrevious.

This method will attempt to select the index directly before the current focused index. If clearSelection is not called first, this method will have the result of selecting the previous index, whilst retaining the selection of any other currently selected indices.

Calling this method will only succeed if:

  • There is currently a lead/focused index.
  • The lead/focus index is not the first index in the control.
  • The previous index is not already selected.

If any of these conditions is false, no selection event will take place.

Annotations
@Override
setItemsback to summary
public final void setItems(ObservableList<T> value)
updateItemsObserverback to summary
private void updateItemsObserver()

Updates the observer for the items list. If the reference to the items list changes, this method sets up a new listener and clears the current selection. If the reference remains the same, it validates the selected indices and updates the selected item and index.

updateSelectedItemAndIndexback to summary
private void updateSelectedItemAndIndex()
updateSelectionOnItemsChangeback to summary
private void updateSelectionOnItemsChange(ListChangeListener.Change<? extends T> c)

Updates the selection model when the items list changes. Ensures the selection remains consistent with the current state of the items list.

validateSelectedIndicesback to summary
private void validateSelectedIndices()