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

TableRow vs. TreeTableRow: inconsistent visuals in cell selection mode

    XMLWordPrintable

Details

    • b05

    Backports

      Description

        With the combination of multiple, cell selection and all cells selected the row is un-/selected for Table-/TreeTableRow (seen in the example below).

        Steps to reproduce:
           - make sure there is a visible part of the row at the right
           - click into a cell of the first column
           - extend the selection to the right, such that both columns are selected
           - expected: same appearance in Table and TreeTable
           - actual: different appearance - for table the row part is not selected,
                for TreeTable the row part is selected

        The technical reason is the different implementation of updateSelection in the corresponding row:

        // tableRow:
        selected = !sm.isCellSelectionEnabled() && sm.isSelected(int);

        // treeTableRow:
        selected = sm.isSelected(int);
         
        The behavior in TableRow seems to be what's expected (there's a code comment to that effect) and TreeTableRow probably should be implemented the same way .. wondering why the different behavior doesn't show up in any test ..

        Note: this turned up in review of JDK-8235491 but is unrelated: same behavior before/after that fix.

        Example:

        public class SelectionVisuals extends Application {

            private Parent createContent() {

                ObservableList<Locale> data = FXCollections.observableArrayList(
                        Arrays.stream(Locale.getAvailableLocales(), 10, 20).collect(Collectors.toList()));

                TableView<Locale> table = new TableView<>(data);
                table.getColumns().addAll(createTableColumn("displayLanguage"), createTableColumn("displayCountry"));
                table.getSelectionModel().setCellSelectionEnabled(true);
                table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

                TreeTableView<Locale> treeTable = new TreeTableView<>(createTreeData(data));
                treeTable.setShowRoot(false);
                treeTable.getColumns().addAll(createTreeTableColumn("displayLanguage"), createTreeTableColumn("displayCountry"));
                treeTable.getSelectionModel().setCellSelectionEnabled(true);
                treeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

                HBox compare = new HBox(10, table, treeTable);
                BorderPane content = new BorderPane(compare);
                return content;
            }

            private <T> TableColumn<T, String> createTableColumn(String property) {
                TableColumn<T, String> column = new TableColumn<>(property);
                column.setCellValueFactory(new PropertyValueFactory<>(property));
                return column;
            }

            private TreeItem<Locale> createTreeData(ObservableList<Locale> data) {
                TreeItem<Locale> root = new TreeItem<>(Locale.ENGLISH);
                ObservableList<TreeItem<Locale>> children = root.getChildren();
                data.stream().map(TreeItem::new).forEach(children::add);
                return root;
            }

            private <T> TreeTableColumn<T, String> createTreeTableColumn(String property) {
                TreeTableColumn<T, String> column = new TreeTableColumn<>(property);
                column.setCellValueFactory(new TreeItemPropertyValueFactory<>(property));
                return column;
            }


            @Override
            public void start(Stage stage) throws Exception {
                stage.setScene(new Scene(createContent()));
                stage.show();
            }

            public static void main(String[] args) {
                launch(args);
            }

        }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: