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

[TreeTableView] selection is saved on items which are inside the collapsed branch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      8.0b69

      Description

      Run the code:

          TreeTableView<Data> treeTableView;

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

          @Override
          public void start(Stage stage) throws Exception {
              treeTableView = new TreeTableView<Data>();
              treeTableView.setRoot(new TreeItem<Data>(new Data("Root")));
              treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 1")));
              treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 2")));
              treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 3")));
              treeTableView.getRoot().setExpanded(true);

              treeTableView.getColumns().add(new TreeTableColumn<Data, String>("Data"));
              ((TreeTableColumn<Data, String>) treeTableView.getColumns().get(0)).setCellValueFactory(new Callback<CellDataFeatures<Data, String>, ObservableValue<String>>() {
                  @Override
                  public ObservableValue<String> call(CellDataFeatures<Data, String> p) {
                      return p.getValue().getValue().property;
                  }
              });

              Button b1 = new Button("print selection");
              b1.setOnAction(new EventHandler() {
                  @Override
                  public void handle(Event t) {
                      System.out.println("selected item : " + treeTableView.getSelectionModel().getSelectedItem());
                      System.out.println("selected items : " + treeTableView.getSelectionModel().getSelectedItems());
                  }
              });

              treeTableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
                  @Override
                  public void changed(ObservableValue ov, Object t, Object t1) {
                      System.out.println("Changed selection to " + t1);
                  }
              });

              VBox vb = new VBox();
              vb.getChildren().addAll(b1, treeTableView);

              Scene scene = new Scene(vb, 300, 300);
              stage.setScene(scene);
              stage.show();
          }

          class Data {

              public StringProperty property;

              public Data(String data) {
                  property = new SimpleStringProperty(data);
              }

              @Override
              public String toString() {
                  return property.get();
              }
          }

      Select "item 2".
      collapse root.
      Click to print selected items.

      Output:
      Changed selection to TreeItem [ value: item 2 ]// <- selected item.
      selected item : TreeItem [ value: item 2 ] // <- after collapsing of root and clicking the button.
      selected items : [null]

      I expect to see droped selection and focused root.

      Affected tests:
      ControlsAutomatedTestSuite/javafx/scene/control/test/treetable/TreeTableAsTreeTest/multilevelJumpOnCollapsingTest

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            akirov Alexander Kirov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved:
              Imported: