Class TableSelectionModel<T>

Type Parameters:
T - The type of the underlying data model for the UI control.
Direct Known Subclasses:
TableView.TableViewSelectionModel, TreeTableView.TreeTableViewSelectionModel

public abstract class TableSelectionModel<T> extends MultipleSelectionModel<T>
The abstract base class for MultipleSelectionModel implementations that are used within table-like controls (most notably TableView and TreeTableView).
Since:
JavaFX 8.0
  • Property Details

    • cellSelectionEnabled

      public final BooleanProperty cellSelectionEnabledProperty
      A boolean property used to represent whether the table is in row or cell selection modes. By default a table is in row selection mode which means that individual cells can not be selected. Setting cellSelectionEnabled to be true results in cells being able to be selected (but not rows).
      See Also:
  • Constructor Details

    • TableSelectionModel

      public TableSelectionModel()
      Constructor for subclasses to call.
  • Method Details

    • isSelected

      public abstract boolean isSelected(int row, TableColumnBase<T,?> column)
      Convenience function which tests whether the given row and column index is currently selected in this table instance. If the table control is in its 'cell selection' mode (where individual cells can be selected, rather than entire rows), and if the column argument is null, this method should return true only if all cells in the given row are selected.
      Parameters:
      row - the row
      column - the column
      Returns:
      true if the given row and column index is currently selected in this table instance
    • select

      public abstract void select(int row, TableColumnBase<T,?> column)
      Selects the cell at the given row/column intersection. If the table control is in its 'cell selection' mode (where individual cells can be selected, rather than entire rows), and if the column argument is null, this method should select all cells in the given row.
      Parameters:
      row - the row
      column - the column
    • clearAndSelect

      public abstract void clearAndSelect(int row, TableColumnBase<T,?> column)
      Clears all selection, and then selects the cell at the given row/column intersection. If the table control is in its 'cell selection' mode (where individual cells can be selected, rather than entire rows), and if the column argument is null, this method should select all cells in the given row.
      Parameters:
      row - the row
      column - the column
    • clearSelection

      public abstract void clearSelection(int row, TableColumnBase<T,?> column)
      Removes selection from the specified row/column position (in view indexes). If this particular cell (or row if the column value is -1) is not selected, nothing happens. If the table control is in its 'cell selection' mode (where individual cells can be selected, rather than entire rows), and if the column argument is null, this method should deselect all cells in the given row.
      Parameters:
      row - the row
      column - the column
    • selectLeftCell

      public abstract void selectLeftCell()
      Selects the cell to the left of the currently selected cell.
    • selectRightCell

      public abstract void selectRightCell()
      Selects the cell to the right of the currently selected cell.
    • selectAboveCell

      public abstract void selectAboveCell()
      Selects the cell directly above the currently selected cell.
    • selectBelowCell

      public abstract void selectBelowCell()
      Selects the cell directly below the currently selected cell.
    • selectRange

      public abstract void selectRange(int minRow, TableColumnBase<T,?> minColumn, int maxRow, TableColumnBase<T,?> maxColumn)
      Selects the cells in the range (minRow, minColumn) to (maxRow, maxColumn), inclusive.
      Parameters:
      minRow - the minRow
      minColumn - the minColumn
      maxRow - the maxRow
      maxColumn - the maxColumn
    • cellSelectionEnabledProperty

      public final BooleanProperty cellSelectionEnabledProperty()
      A boolean property used to represent whether the table is in row or cell selection modes. By default a table is in row selection mode which means that individual cells can not be selected. Setting cellSelectionEnabled to be true results in cells being able to be selected (but not rows).
      See Also:
    • setCellSelectionEnabled

      public final void setCellSelectionEnabled(boolean value)
      Sets the value of the property cellSelectionEnabled.
      Property description:
      A boolean property used to represent whether the table is in row or cell selection modes. By default a table is in row selection mode which means that individual cells can not be selected. Setting cellSelectionEnabled to be true results in cells being able to be selected (but not rows).
    • isCellSelectionEnabled

      public final boolean isCellSelectionEnabled()
      Gets the value of the property cellSelectionEnabled.
      Property description:
      A boolean property used to represent whether the table is in row or cell selection modes. By default a table is in row selection mode which means that individual cells can not be selected. Setting cellSelectionEnabled to be true results in cells being able to be selected (but not rows).
    • getSelectedIndices

      public ObservableList<Integer> getSelectedIndices()
      Description copied from class: MultipleSelectionModel

      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.

      Specified by:
      getSelectedIndices in class MultipleSelectionModel<T>
      Returns:
      the list of selected indices
    • getSelectedItems

      public ObservableList<T> getSelectedItems()
      Description copied from class: MultipleSelectionModel

      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.

      Specified by:
      getSelectedItems in class MultipleSelectionModel<T>
      Returns:
      the list of selected items
    • getItemCount

      protected abstract int getItemCount()
      Returns the number of items in the data model that underpins the control. An example would be that a ListView selection model would likely return listView.getItems().size(). The valid range of selectable indices is between 0 and whatever is returned by this method.
      Returns:
      the number of items in the data model that underpins the control
    • getModelItem

      protected abstract T getModelItem(int index)
      Returns the item at the given index. An example using ListView would be listView.getItems().get(index).
      Parameters:
      index - The index of the item that is requested from the underlying data model.
      Returns:
      Returns null if the index is out of bounds, or an element of type T that is related to the given index.
    • focus

      protected abstract void focus(int index)
      Focuses the item at the given index.
      Parameters:
      index - the index of the item to be focused
    • getFocusedIndex

      protected abstract int getFocusedIndex()
      Gets the index of the focused item.
      Returns:
      the index of the focused item
    • clearAndSelect

      public void clearAndSelect(int row)
      Description copied from class: SelectionModel
      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 SelectionModel.clearSelection() first, meaning that observers that are listening to the selected index property will not see the selected index being temporarily set to -1.
      Specified by:
      clearAndSelect in class SelectionModel<T>
      Parameters:
      row - The index that should be the only selected index in this selection model.
    • select

      public void select(int row)
      Description copied from class: SelectionModel

      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 SelectionModel.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 SelectionModel.getSelectedIndex().

      Specified by:
      select in class SelectionModel<T>
      Parameters:
      row - The position of the item to select in the selection model.
    • select

      public void select(T obj)
      Description copied from class: SelectionModel

      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.

      Specified by:
      select in class SelectionModel<T>
      Parameters:
      obj - The object to attempt to select in the underlying data model.
    • selectIndices

      public void selectIndices(int row, int... rows)
      Description copied from class: MultipleSelectionModel

      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.

      Specified by:
      selectIndices in class MultipleSelectionModel<T>
      Parameters:
      row - the first index to select
      rows - zero or more additional indices to select
    • selectAll

      public void selectAll()
      Description copied from class: MultipleSelectionModel

      Convenience method to select all available indices.

      Specified by:
      selectAll in class MultipleSelectionModel<T>
    • selectFirst

      public void selectFirst()
      Description copied from class: MultipleSelectionModel

      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.

      Specified by:
      selectFirst in class MultipleSelectionModel<T>
    • selectLast

      public void selectLast()
      Description copied from class: MultipleSelectionModel

      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.

      Specified by:
      selectLast in class MultipleSelectionModel<T>
    • clearSelection

      public void clearSelection(int index)
      Description copied from class: SelectionModel

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

      Specified by:
      clearSelection in class SelectionModel<T>
      Parameters:
      index - The selected item to deselect.
    • clearSelection

      public void clearSelection()
      Description copied from class: SelectionModel

      Clears the selection model of all selected indices.

      Specified by:
      clearSelection in class SelectionModel<T>
    • isSelected

      public boolean isSelected(int index)
      Description copied from class: SelectionModel

      Convenience method to inform if the given index is currently selected in this SelectionModel. Is functionally equivalent to calling getSelectedIndices().contains(index).

      Specified by:
      isSelected in class SelectionModel<T>
      Parameters:
      index - The index to check as to whether it is currently selected or not.
      Returns:
      True if the given index is selected, false otherwise.
    • isEmpty

      public boolean isEmpty()
      Description copied from class: SelectionModel
      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.
      Specified by:
      isEmpty in class SelectionModel<T>
      Returns:
      Will return true if there are no selected items, and false if there are.
    • selectPrevious

      public void selectPrevious()
      Description copied from class: SelectionModel

      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.

      Specified by:
      selectPrevious in class SelectionModel<T>
    • selectNext

      public void selectNext()
      Description copied from class: SelectionModel

      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.

      Specified by:
      selectNext in class SelectionModel<T>