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

CheckBoxTreeItem/Cell: parent selected must be updated on remove/add children

XMLWordPrintable

      To reproduce, run example below: it creates a bunch of checkBoxTreeItems with one selected. Note that parent state is indeterminate as expected. Press button to remove the selected treeItem.

      - expected: parent state changed to unselected
      - actual: parent state still indeterminate

      public class CheckBoxTreeCellOnRemove extends Application {

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

          @Override
          public void start(Stage stage) throws Exception {
              stage.setTitle(VersionInfo.getRuntimeVersion());
              stage.setScene(getScene());
              stage.show();
          }

          private Scene getScene() {
              
              List<TreeItem<String>> ls = new ArrayList<TreeItem<String>>(10);
              for (int i = 0; i < 10; i++) {
                  ls.add(new CheckBoxTreeItem<String>("Test " + i));
              }
              
              TreeView<String> tv = new TreeView<String>();
              tv.setRoot(new CheckBoxTreeItem<String>("Root"));
              
              tv.getRoot().getChildren().addAll(ls);
              tv.getRoot().setExpanded(true);
              
              tv.setCellFactory(CheckBoxTreeCell.forTreeView());
              BorderPane root = new BorderPane();
              root.setCenter(tv);
              
              Button removeSelected = new Button("removeSelected");
              removeSelected.setOnAction(e -> {
                  TreeItem item = tv.getSelectionModel().getSelectedItem();
                  if (item == null || item == tv.getRoot()) return;
                  tv.getRoot().getChildren().remove(item);
              });
              HBox buttonPane = new HBox(removeSelected);
              root.setBottom(buttonPane);
              
              return new Scene(root, 600, 400);
          }
       
      }

            Unassigned Unassigned
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: