List of usage examples for javafx.scene.control CheckBoxTreeItem selectedProperty
public final BooleanProperty selectedProperty()
From source file:caillou.company.clonemanager.gui.customComponent.excludeTree.ExcludeTreeController.java
public void buildTreeLazily(final CheckBoxTreeItem<DirectoryLazyCheckableTreeItem> currentItem, int nbPass) { if (nbPass == 0) { return;//from w ww .j a va 2 s. co m } boolean lazyChilds = nbPass > 2; DirectoryLazyCheckableTreeItem currentItemValue = currentItem.getValue(); final ExcludeTreeController excludeControllerInstance = this; File currentDirectory = new File(currentItemValue.getAbsolutePath()); if (!currentDirectory.canRead()) { return; } currentItemValue.setLoaded(lazyChilds); currentItem.getChildren().clear(); for (File subFile : currentDirectory.listFiles(directoryFilter)) { DirectoryLazyCheckableTreeItem childrenDirectoryLazyCheckableTreeItem = this.factoryDirectoryCheckableTreeItem .createItem(subFile.getAbsolutePath()); CheckBoxTreeItem<DirectoryLazyCheckableTreeItem> children = new CheckBoxTreeItem<>( childrenDirectoryLazyCheckableTreeItem); children.setSelected(!this.getModel().isExcludedByUser(subFile.toPath())); final ExcludeModel excludeModel = this.getModel(); final File tmpFile = subFile; children.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { excludeModel.removeExclusionByUser(tmpFile.toPath()); } else { excludeModel.addExclusionByUser(tmpFile.toPath()); } } }); this.buildTreeLazily(children, nbPass - 1); currentItem.getChildren().add(children); } if (nbPass == 2) { currentItem.expandedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { excludeControllerInstance.buildTreeLazily(currentItem, 3); currentItem.expandedProperty().removeListener(this); } }); } }
From source file:utilitybasedfx.MainGUIController.java
private boolean addChildren(TreeItem parentBranch, File parentFile) { boolean containsJavaFiles = false; File children[] = parentFile.listFiles(); if (children != null) { ArrayList<File> directories = new ArrayList<File>(); ArrayList<File> files = new ArrayList<File>(); for (File child : children) { if (child.isDirectory()) { directories.add(child);/*from w w w .j ava2 s . c o m*/ } else { files.add(child); } } for (File dir : directories) { CheckBoxTreeItem<String> treeItem = new CheckBoxTreeItem<>(dir.getName()); treeItem.setExpanded(true); if (addChildren(treeItem, dir)) { containsJavaFiles = true; parentBranch.getChildren().add(treeItem); } } for (File file : files) { if (file.getName().endsWith(".java")) { CheckBoxTreeItem<String> treeItem = new CheckBoxTreeItem<>(file.getName()); treeItem.selectedProperty().addListener(new ChangeListener<Boolean>() { public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { addFilepathToArraylist(treeItem); } else { removeFilepathFromArraylist(treeItem); } } }); parentBranch.getChildren().add(treeItem); containsJavaFiles = true; } } } return containsJavaFiles; }
From source file:utilitybasedfx.MainGUIController.java
private void fillTreeFromArray(String[] ops, CheckBoxTreeItem<String> root, ArrayList<String> listForOpsEvent) { CheckBoxTreeItem<String> subFolder = null; for (String op : ops) { if (op.startsWith("-")) { subFolder = new CheckBoxTreeItem<String>(op.substring(1)); subFolder.setExpanded(true); root.getChildren().add(subFolder); } else {/*from w w w .j a v a 2 s. c om*/ CheckBoxTreeItem<String> opTreeItem = new CheckBoxTreeItem<String>(op); if (subFolder != null) { subFolder.getChildren().add(opTreeItem); opTreeItem.selectedProperty().addListener(new ChangeListener<Boolean>() { public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { addOpToArraylist(opTreeItem, listForOpsEvent); } else { removeOpFromArraylist(opTreeItem, listForOpsEvent); } } }); } } } }