Example usage for javafx.scene.control TreeItem TreeItem

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

Introduction

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

Prototype

public TreeItem(final T value) 

Source Link

Document

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

Usage

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   ww w.j ava  2 s  .c o  m
        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:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

/**
 * Load a list of available projects related to the current ini file
 * Load all projects from accessible configuration files.
 * This is done in a JavaFX Task./* w ww.j  ava2 s  .  co  m*/
 *
 * @param iniFile
 */
private void loadProjects(File iniFile) {
    RoddyUITask task = new RoddyUITask<TreeItem<FXICCWrapper>>(UIConstants.UITASK_LOAD_PROJECTS) {
        @Override
        public TreeItem<FXICCWrapper> _call() throws Exception {
            TreeItem<FXICCWrapper> root = new TreeItem<>(null);
            AppConfig appConfig = new AppConfig(iniFile);
            String[] allConfigDirectories = appConfig.getProperty("configurationDirectories", "")
                    .split(StringConstants.SPLIT_COMMA);
            List<File> folders = new LinkedList<>();
            for (String s : allConfigDirectories) {
                File f = new File(s);
                if (f.exists())
                    folders.add(f);
            }
            ConfigurationFactory.initialize(folders);
            List<InformationalConfigurationContent> availableProjectConfigurations = ConfigurationFactory
                    .getInstance().getAvailableProjectConfigurations();
            availableProjectConfigurations.sort(new Comparator<InformationalConfigurationContent>() {
                @Override
                public int compare(InformationalConfigurationContent o1, InformationalConfigurationContent o2) {
                    return o1.name.compareTo(o2.name);
                }
            });
            loadProjectsRecursivelyFromXMLFiles(root, availableProjectConfigurations);
            return root;
        }

        @Override
        public void _failed() {
            logger.log(Level.WARNING, UIConstants.ERRTXT_PROJECTSNOTLOADED, getException());
        }

        @Override
        protected void _succeeded() {
            allProjectTreeItemsRoot = valueProperty().get();
            refreshProjectView(null);
        }
    };
    RoddyUITask.runTask(task);
}

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

private void rebuildTree() {
    currentlyRebuilding = true;//  ww w .  j a  v  a 2 s.co m

    treeTemplate.getChildren().clear();
    treeAssays.getChildren().clear();

    Schema schema = stack.getSchema();
    Schema.Group root = schema.getRoot();

    treeTemplate.setValue(new Branch(this, root, schema.locatorID(root)));
    fillTreeGroup(schema, root, treeTemplate);

    for (int n = 0; n < schema.numAssays(); n++) {
        Schema.Assay assay = schema.getAssay(n);
        TreeItem<Branch> item = new TreeItem<>(new Branch(this, assay, schema.locatorID(assay)));
        treeAssays.getChildren().add(item);
    }

    currentlyRebuilding = false;
}

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);/*from   w ww  .j a va2s. 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:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

/**
 * Recursive helper method to load projects from configuration files.
 *//*from  w  w w .j  ava 2  s.  c  om*/
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: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;/* www  . j  ava2s  .c  om*/
    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:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

private TreeItem<FXICCWrapper> isProcessable(TreeItem<FXICCWrapper> currentNode, boolean hideUnprocessable,
        String idFilter, String analysisIDFilter) {
    WildcardFileFilter wffID = new WildcardFileFilter(idFilter);
    WildcardFileFilter wffAID = new WildcardFileFilter(analysisIDFilter);
    FXICCWrapper cWrapper = currentNode.getValue();
    boolean isVisible = false;
    TreeItem<FXICCWrapper> copyOfTreeItem = new TreeItem<>(currentNode.getValue());
    copyOfTreeItem.setExpanded(currentNode.isExpanded());
    //        System.out.println(currentNode.getValue().getID() + " " + currentNode.getChildren().size());
    //At first: Check, if the node has children and if one of those children is visible.
    for (TreeItem<FXICCWrapper> treeItem : currentNode.getChildren()) {
        TreeItem<FXICCWrapper> childVisible = isProcessable(treeItem, hideUnprocessable, idFilter,
                analysisIDFilter);//from   w ww. ja  v  a  2 s  .  c  o  m
        if (childVisible != null)
            copyOfTreeItem.getChildren().add(childVisible);
    }

    //If there are no visible children, then check the node itself.
    if (copyOfTreeItem.getChildren().size() == 0) {
        //            System.out.println(cWrapper.getID());
        //Is this a project node or an analysis node?
        isVisible = wffID.accept(new File(cWrapper.getID()));
        if (!isVisible)
            return null;
        if (cWrapper.isAnalysisWrapper()) {
            isVisible = wffAID.accept(new File(cWrapper.getAnalysisID()));
            if (!isVisible)
                return null;
        } else {
            if (hideUnprocessable) {
                isVisible = false;
                return null;
            } else {
                if (cWrapper.hasAnalyses())
                    return null;
            }
        }
        //            if (isVisible && !cWrapper.hasAnalyses()) {
        //                if (currentNode.getChildren().size() > 0)
        //                    isVisible = false;
        //            }
    } else {
        isVisible = true;
    }

    if (isVisible)
        return copyOfTreeItem;
    return null;
}

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

private TreeItem<Path> cacheOverlays(File dir, TreeItem<Path> parent, int THUMB_SIZE) throws IOException {
    log.info("Caching " + dir.getAbsolutePath());

    TreeItem<Path> root = new TreeItem<>(dir.toPath());
    root.setExpanded(false);//from   w w w  . ja v  a  2s.co m
    File[] files = dir.listFiles();
    final String I18N_CACHE_TEXT = I18N.getString("TokenTool.treeview.caching");

    final Task<Void> task = new Task<Void>() {
        @Override
        protected Void call() throws Exception {
            for (File file : files) {
                if (loadOverlaysThread.isInterrupted())
                    break;

                if (file.isDirectory()) {
                    cacheOverlays(file, root, THUMB_SIZE);
                } else {
                    Path filePath = file.toPath();
                    TreeItem<Path> imageNode = new TreeItem<>(filePath,
                            ImageUtil.getOverlayThumb(new ImageView(), filePath));
                    root.getChildren().add(imageNode);
                    loadCount.getAndIncrement();
                    overlayTreeProgressBar.progressProperty().set(loadCount.doubleValue() / overlayCount);
                }
            }

            if (parent != null) {
                // When we show the overlay image, the TreeItem value is empty so we need to
                // sort those to the bottom for a cleaner look and keep sub dir's at the top.
                // If a node has no children then it's an overlay, otherwise it's a directory...
                root.getChildren().sort(new Comparator<TreeItem<Path>>() {
                    @Override
                    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());
                    }
                });

                parent.getChildren().add(root);

                parent.getChildren().sort(new Comparator<TreeItem<Path>>() {
                    @Override
                    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 null;
        }
    };

    overlayTreeProgressBar.progressProperty().addListener(observable -> {
        Platform.runLater(() -> progressBarLabel
                .setText(I18N_CACHE_TEXT + Math.round(overlayCount - loadCount.doubleValue()) + "..."));
    });

    // Only add this listener to the parent task so it's only called once
    if (parent == null) {
        overlayTreeProgressBar.progressProperty().addListener(observable -> {
            Platform.runLater(() -> {
                if (overlayTreeProgressBar.getProgress() >= 1)
                    treeViewFinish();
            });
        });
    }

    executorService.execute(task);
    return root;
}