Example usage for javafx.scene.control TreeItem getChildren

List of usage examples for javafx.scene.control TreeItem getChildren

Introduction

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

Prototype

public ObservableList<TreeItem<T>> getChildren() 

Source Link

Document

The children of this TreeItem.

Usage

From source file:Testing.TestMain.java

private void fileFinder(File dir, TreeItem<File> parent) throws IOException {
    String[] extensions = new String[] { "mp3" };
    TreeItem<File> root = new TreeItem<>(dir);
    root.setExpanded(true);//from w  ww.jav  a 2 s .  com
    dir.getCanonicalPath();

    List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
    //Collection collector = hyperStackOverflowFileMp3Scan(dir);
    //File[] files = null;
    //collector.toArray(files);

    for (File file : files) {
        if (!file.toString().contains("$RECYCLE.BIN")) {
            if (file.isDirectory()) {
                System.out.println("directory:" + file.getCanonicalPath());
                fileFinder(file, root);
            } else {
                System.out.println("    file:" + file.getCanonicalPath());
                root.getChildren().add(new TreeItem<>(file));
            }
        }
    }
    if (parent == null) {
        //treeViewFile.setRoot(root);
    } else {
        parent.getChildren().add(root);
    }
}

From source file:net.rptools.tokentool.controller.TokenTool_Controller.java

private TreeItem<Path> sortTreeNodes(TreeItem<Path> tree) {
    // Sort the nodes off of root
    tree.getChildren().sort(new Comparator<TreeItem<Path>>() {
        @Override//  ww w.  jav a2 s .com
        public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
            if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
                return 0;
            else if (o1.getChildren().size() == 0)
                return Integer.MAX_VALUE;
            else if (o2.getChildren().size() == 0)
                return Integer.MIN_VALUE;
            else
                return o1.getValue().compareTo(o2.getValue());
        }
    });

    return tree;
}

From source file:net.rptools.tokentool.controller.TokenTool_Controller.java

private void updateCompositImageView(TreeItem<Path> treeNode) {
    // Node removed...
    if (treeNode == null)
        return;/*  w  w w.ja  v a  2 s  .  com*/

    // I'm not a leaf on the wind! (Sub directory node)
    if (treeNode.getChildren().size() > 0)
        return;

    try {
        Path filePath = treeNode.getValue();
        lastSelectedItem = treeNode;

        // Set the Image Views
        maskImageView = ImageUtil.getMaskImage(maskImageView, filePath);
        overlayImageView = ImageUtil.getOverlayImage(overlayImageView, filePath);

        // Set the text label
        overlayNameLabel.setText(FilenameUtils.getBaseName(filePath.toFile().getName()));

        updateTokenPreviewImageView();
    } catch (IOException e) {
        // Not a valid URL, most likely this is just because it's a directory node.
        e.printStackTrace();
    }
}

From source file:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

public void refreshProjectView(ActionEvent actionEvent) {

    TreeItem<FXICCWrapper> filteredRoot = null;
    boolean filtersApplied = false;
    boolean hideUnprocessable = cbProjectFilterHideUnprocessable.isSelected();
    String analysisIDFilter = txtProjectFilterByAnalysis.getText();
    String idFilter = txtProjectFilterByID.getText();
    analysisIDFilter = "*" + analysisIDFilter.trim() + "*";
    idFilter = "*" + idFilter.trim() + "*";
    filtersApplied = hideUnprocessable;/* w  w w.  j  a  v  a  2  s  .c o m*/
    filteredRoot = new TreeItem<>(allProjectTreeItemsRoot.getValue());

    TreeItem<FXICCWrapper> root = filteredRoot;
    for (TreeItem<FXICCWrapper> currentNode : allProjectTreeItemsRoot.getChildren()) {
        TreeItem<FXICCWrapper> addable = isProcessable(currentNode, hideUnprocessable, idFilter,
                analysisIDFilter);
        if (addable != null)
            root.getChildren().add(addable);
    }
    projectTree.setRoot(filteredRoot);
}

From source file:com.cdd.bao.editor.EditSchema.java

private void fillTreeGroup(Schema schema, Schema.Group group, TreeItem<Branch> parent) {
    for (Schema.Assignment assn : group.assignments) {
        TreeItem<Branch> item = new TreeItem<>(new Branch(this, assn, schema.locatorID(assn)));
        parent.getChildren().add(item);
    }/* w w w  .jav  a  2 s . c o m*/
    for (Schema.Group subgrp : group.subGroups) {
        TreeItem<Branch> item = new TreeItem<>(new Branch(this, subgrp, schema.locatorID(subgrp)));
        item.setExpanded(true);
        parent.getChildren().add(item);
        fillTreeGroup(schema, subgrp, item);
    }
}

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);// w ww .j  a  va2s  .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:com.cdd.bao.editor.EditSchema.java

public TreeItem<Branch> locateBranch(String locatorID) {
    List<TreeItem<Branch>> stack = new ArrayList<>();
    stack.add(treeRoot);/*www .  j ava 2s .  co  m*/
    while (stack.size() > 0) {
        TreeItem<Branch> item = stack.remove(0);
        String lookID = item.getValue().locatorID;
        if (lookID != null && lookID.equals(locatorID))
            return item;
        for (TreeItem<Branch> sub : item.getChildren())
            stack.add(sub);
    }
    return null;
}

From source file:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

/**
 * Recursive helper method to load projects from configuration files.
 *//*from w w  w. j ava2 s. co m*/
private void loadProjectsRecursivelyFromXMLFiles(final TreeItem<FXICCWrapper> root,
        List<InformationalConfigurationContent> availableProjectConfigurations) {
    int count = 0;
    String path = Roddy.getApplicationProperty(RunMode.UI,
            RoddyUIController.APP_PROPERTY_LAST_OPEN_PROJECT_PATH, "");

    for (InformationalConfigurationContent icc : availableProjectConfigurations) {
        FXICCWrapper fpw = new FXICCWrapper(icc, count++);
        TreeItem<FXICCWrapper> newItem = new TreeItem<>(fpw);
        root.getChildren().add(newItem);
        try {

            Map<String, String> analyses = fpw.getAnalyses();
            for (String analysisID : analyses.keySet()) {
                FXICCWrapper fpwAnalysis = new FXICCWrapper(icc, analysisID, count++);
                newItem.getChildren().add(new TreeItem<>(fpwAnalysis));
            }
            loadProjectsRecursivelyFromXMLFiles(newItem, icc.getSubContent());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //Add an expand listener to the topmost nodes
    if (root.getValue() != null) {
        for (final TreeItem<FXICCWrapper> treeItem : root.getChildren()) {
            treeItem.setExpanded(true);
        }
        return;
    }
    for (final TreeItem<FXICCWrapper> treeItem : root.getChildren()) {

        treeItem.expandedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean,
                    Boolean newValue) {
                if (!newValue)
                    return;

                //Upon expand close all other nodes.
                for (TreeItem<FXICCWrapper> sister : root.getChildren()) {
                    if (treeItem == sister) {
                        Roddy.setApplicationProperty(RunMode.UI,
                                RoddyUIController.APP_PROPERTY_LAST_OPEN_PROJECT_PATH,
                                treeItem.getValue().getID());

                    } else {
                        sister.setExpanded(false);
                    }
                }
            }
        });
        if (treeItem.getValue().getID().equals(path))
            treeItem.setExpanded(true);
    }

}

From source file:acmi.l2.clientmod.xdat.Controller.java

private static TreeItem<Object> createTreeItem(IOEntity o) {
    TreeItem<Object> item = new TreeItem<>(o);

    List<Field> fields = new ArrayList<>();
    Class<?> clazz = o.getClass();
    while (clazz != Object.class) {
        Arrays.stream(clazz.getDeclaredFields()).filter(field -> !field.isSynthetic())
                .filter(field -> List.class.isAssignableFrom(field.getType())
                        || IOEntity.class.isAssignableFrom(field.getType()))
                .forEach(fields::add);/*from   www  .ja v  a 2  s. c om*/
        clazz = clazz.getSuperclass();
    }
    fields.forEach(field -> {
        field.setAccessible(true);

        Optional<Object> obj = Optional.empty();
        try {
            obj = Optional.ofNullable(field.get(o));
        } catch (IllegalAccessException e) {
            log.log(Level.WARNING, String.format("%s.%s is not accessible", o.getClass(), field.getName()), e);
            Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                    String.format("%s.%s is not accessible", o.getClass(), field.getName()));
        }

        obj.ifPresent(val -> {
            if (List.class.isAssignableFrom(field.getType())) {
                if (!field.isAnnotationPresent(Type.class)) {
                    log.log(Level.WARNING,
                            String.format("%s.%s: @Type not defined", o.getClass().getName(), field.getName()));
                    Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                            String.format("%s.%s: @Type not defined", o.getClass().getName(), field.getName()));
                } else {
                    List<IOEntity> list = (List<IOEntity>) val;
                    Class<? extends IOEntity> type = field.getAnnotation(Type.class).value()
                            .asSubclass(IOEntity.class);
                    TreeItem<Object> listItem = new TreeItem<>(new ListHolder(o, list, field.getName(), type));

                    item.getChildren().add(listItem);

                    listItem.getChildren()
                            .addAll(list.stream().map(Controller::createTreeItem).collect(Collectors.toList()));
                }
            } else if (IOEntity.class.isAssignableFrom(field.getType())) {
                IOEntity ioEntity = (IOEntity) val;

                item.getChildren().add(createTreeItem(ioEntity));
            }
        });
    });
    return item;
}

From source file:acmi.l2.clientmod.xdat.Controller.java

private MenuItem createAddMenu(String name, TreeView<Object> elements, TreeItem<Object> selected) {
    ListHolder listHolder = (ListHolder) selected.getValue();

    MenuItem add = new MenuItem(name);
    add.setOnAction(event -> {/*from ww w. ja va2 s . co m*/
        Stream<ClassHolder> st = SubclassManager.getInstance().getClassWithAllSubclasses(listHolder.type)
                .stream().map(ClassHolder::new);
        List<ClassHolder> list = st.collect(Collectors.toList());

        Optional<ClassHolder> choice;

        if (list.size() == 1) {
            choice = Optional.of(list.get(0));
        } else {
            ChoiceDialog<ClassHolder> cd = new ChoiceDialog<>(list.get(0), list);
            cd.setTitle("Select class");
            cd.setHeaderText(null);
            choice = cd.showAndWait();
        }
        choice.ifPresent(toCreate -> {
            try {
                IOEntity obj = toCreate.clazz.newInstance();

                listHolder.list.add(obj);
                TreeItem<Object> treeItem = createTreeItem(obj);
                selected.getChildren().add(treeItem);
                elements.getSelectionModel().select(treeItem);
                elements.scrollTo(elements.getSelectionModel().getSelectedIndex());

                editor.getHistory().valueCreated(treeItemToScriptString(selected), toCreate.clazz);
            } catch (ReflectiveOperationException e) {
                log.log(Level.WARNING, String.format("Couldn't instantiate %s", toCreate.clazz.getName()), e);
                Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                        "Couldn't instantiate " + toCreate.clazz);
            }
        });
    });

    return add;
}