Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8290741

Tree/TableView: implementation of isSelected(int) violates contract

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • jfx20
    • javafx
    • None
    • behavioral
    • low
    • Hide
      The change modifies behavior of isSelected(int) method only when cell selection is enabled. This change impacts default TableSelectionModel and TreeTableSelectionModel. Apps should not use this method in such a case, instead the methods that take specific column as a second argument should be called.
      Show
      The change modifies behavior of isSelected(int) method only when cell selection is enabled. This change impacts default TableSelectionModel and TreeTableSelectionModel. Apps should not use this method in such a case, instead the methods that take specific column as a second argument should be called.
    • Java API
    • JDK

      Summary

      Change semantics of TableView.TableViewSelectionModel.isSelected(int) in the case when cell selection is enabled, to return true if one or more cells is selected on the given row index. Existing behavior returns true only if all cells in the row are selected, which I think is incorrect.

      Problem

      A number of bugs has been logged related to the problem of arguably incorrect behavior of isSelected(int):

      JDK-8219720 Tree/TableView: incorrect cell selected after initial navigation into table JDK-8235491 Tree/TableView: implementation of isSelected(int) violates contract JDK-8088012 SelectionModel: mismatches between api doc and implementations JDK-8088725 TableSelectionModel: missing doc on how cellSelectionEnabled affects behaviour

      Solution

      1. reword SelectionModel.isSelected(int) javadoc, removing incorrect statement "Is functionally equivalent to calling getSelectedIndices().contains(index)."
      2. reimplement TableView.TableViewSelectionModel.isSelected(int) method to return true when at least one cell in any column is selected on the given row (was: all columns)
      3. modify TreeTableRow.updateSelection() to use the right isSelected() method
      4. update tests for Tree/TableView

      Compatibility Impact

      The change modifies behavior of isSelected(int) method only when cell selection is enabled. This change impacts default TableSelectionModel and TreeTableSelectionModel.

      Specification

      javafx.scene.control.SelectionModel

           /**
      -     * <p>Convenience method to inform if the given index is currently selected
      -     * in this SelectionModel. Is functionally equivalent to calling
      -     * <code>getSelectedIndices().contains(index)</code>.
      +     * This method tests whether the given index is currently selected
      +     * in this SelectionModel.
            *
            * @param index The index to check as to whether it is currently selected
            *      or not.
            * @return True if the given index is selected, false otherwise.
            */
           public abstract boolean isSelected(int index);

            angorya Andy Goryachev
            fastegal Jeanette Winzenburg
            Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: