Example usage for javafx.scene.control CheckBoxTreeItem CheckBoxTreeItem

List of usage examples for javafx.scene.control CheckBoxTreeItem CheckBoxTreeItem

Introduction

In this page you can find the example usage for javafx.scene.control CheckBoxTreeItem CheckBoxTreeItem.

Prototype

public CheckBoxTreeItem(T value) 

Source Link

Document

Creates a CheckBoxTreeItem with the value property set to the provided object.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    CheckBoxTreeItem<String> rootItem = new CheckBoxTreeItem<>("A");
    rootItem.setExpanded(true);/*from   ww  w . j  a  v  a  2  s  . c o  m*/

    TreeView tree = new TreeView(rootItem);
    tree.setEditable(true);

    tree.setCellFactory(CheckBoxTreeCell.forTreeView());

    CheckBoxTreeItem<String> checkBoxTreeItem = new CheckBoxTreeItem<>("a");
    rootItem.getChildren().add(checkBoxTreeItem);

    checkBoxTreeItem = new CheckBoxTreeItem<>("b");
    rootItem.getChildren().add(checkBoxTreeItem);

    tree.setRoot(rootItem);

    StackPane root = new StackPane();
    root.getChildren().add(tree);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}

From source file:caillou.company.clonemanager.gui.customComponent.excludeTree.ExcludeTreeController.java

public void buildTreeLazily(final TreeItem<DirectoryLazyCheckableTreeItem> currentItem, int nbPass) {
    if (nbPass == 0) {
        return;//  w  w w .j av a  2s .  c o  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)) {
        TreeItem<DirectoryLazyCheckableTreeItem> children = new CheckBoxTreeItem<>(
                this.factoryDirectoryCheckableTreeItem.createItem(subFile.getAbsolutePath()));
        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:caillou.company.clonemanager.gui.customComponent.excludeTree.ExcludeTreeController.java

public void buildTreeLazily(final CheckBoxTreeItem<DirectoryLazyCheckableTreeItem> currentItem, int nbPass) {
    if (nbPass == 0) {
        return;//from   w w  w . j  a v a 2s.c  o 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:caillou.company.clonemanager.gui.customComponent.excludeTree.ExcludeTreeController.java

public void initialiseRootDirectory() {
    DirectoryLazyCheckableTreeItem rootValue = this.factoryDirectoryCheckableTreeItem
            .createItem(this.getModel().getPath());
    final CheckBoxTreeItem<DirectoryLazyCheckableTreeItem> rootItem = new CheckBoxTreeItem<>(rootValue);
    rootItem.setSelected(true);/*from   ww  w . jav  a 2s .  c  om*/

    this.buildTreeLazily(rootItem, 3);
    treeView.setRoot(rootItem);

    treeView.prefWidthProperty().bind(this.rootId.widthProperty().subtract(10));
    treeView.prefHeightProperty().bind(this.rootId.heightProperty().subtract(10));
    treeView.setCellFactory(CheckBoxTreeCell.<DirectoryLazyCheckableTreeItem>forTreeView());
}

From source file:utilitybasedfx.MainGUIController.java

private void refreshFilesTree() {
    shouldRefreshFileTree = false;/*from   ww  w .  j a  v a  2  s  .  co m*/
    CheckBoxTreeItem<String> root;

    root = new CheckBoxTreeItem("root");
    root.setExpanded(true);

    addChildren(root, new File(Prefs.getSourcePath()));

    treeFilesToMutate.setStyle("-fx-font-size: 11; ");

    //treeFilesToMutate.getStylesheets().add("/css/treeViewColouredSelection.css"); // [FIXME] make the color change! WHY IT NO WORK

    treeFilesToMutate.setRoot(root);
    treeFilesToMutate.setShowRoot(false);
    treeFilesToMutate.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
}

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. ja v  a2  s  . c  om*/
            } 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 clearFilesTree() {
    shouldRefreshFileTree = false;/* w  w w  .  ja va  2s  .c  o  m*/
    CheckBoxTreeItem<String> root;

    root = new CheckBoxTreeItem("root");
    root.setExpanded(true);

    treeFilesToMutate.setRoot(root);
    treeFilesToMutate.setShowRoot(false);
}

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 {//ww w.  j  av a 2 s  . c  o m
            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);
                        }
                    }
                });
            }
        }
    }
}

From source file:utilitybasedfx.MainGUIController.java

private CheckBoxTreeItem<String> preSetupOpsTree(TreeView tree) {
    CheckBoxTreeItem<String> root = new CheckBoxTreeItem("root");

    root.setExpanded(true);// w  w w.  j  av a2  s. co  m

    tree.setStyle("-fx-font-size: 11; ");

    //tree.getStylesheets().add("/css/treeViewColouredSelection.css"); // [FIXME] make the color change! WHY IT NO WORK

    tree.setRoot(root);
    tree.setShowRoot(false);
    tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView());

    return root;
}