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: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  www.  j  a va2  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);//  w w  w.  ja  va  2  s . c o 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;
}

From source file:qupath.lib.gui.tma.TMASummaryViewer.java

private Pane createSidePane() {
    BorderPane pane = new BorderPane();

    TabPane tabPane = new TabPane();

    kmDisplay = new KaplanMeierDisplay(null, null, null, null);
    BorderPane paneKaplanMeier = new BorderPane();
    paneKaplanMeier.setCenter(kmDisplay.getView());
    paneKaplanMeier.setPadding(new Insets(10, 10, 10, 10));
    //      comboMainMeasurement.prefWidthProperty().bind(paneKaplanMeier.widthProperty());
    comboMainMeasurement.setMaxWidth(Double.MAX_VALUE);
    comboMainMeasurement.setTooltip(new Tooltip("Measurement thresholded to create survival curves etc."));

    GridPane kmTop = new GridPane();
    kmTop.add(new Label("Score"), 0, 0);
    kmTop.add(comboMainMeasurement, 1, 0);
    kmTop.add(new Label("Survival type"), 0, 1);
    kmTop.add(comboSurvival, 1, 1);//  w w  w .  j  a v  a 2 s .com
    comboSurvival.setTooltip(new Tooltip("Specify overall or recurrence-free survival (if applicable)"));
    comboSurvival.setMaxWidth(Double.MAX_VALUE);
    GridPane.setHgrow(comboMainMeasurement, Priority.ALWAYS);
    GridPane.setHgrow(comboSurvival, Priority.ALWAYS);
    kmTop.setHgap(5);
    paneKaplanMeier.setTop(kmTop);
    //      kmDisplay.setOrientation(Orientation.VERTICAL);

    histogramDisplay = new HistogramDisplay(model, false);

    comboMainMeasurement.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> {
        histogramDisplay.refreshCombo();
        histogramDisplay.showHistogram(n);
        updateSurvivalCurves();
    });
    comboMeasurementMethod.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> {
        histogramDisplay.refreshHistogram();
        scatterPane.updateChart();
        updateSurvivalCurves();
    });
    comboSurvival.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> {
        updateSurvivalCurves();
    });

    // Create a Tab for showing images
    BorderPane paneImages = new BorderPane();
    CheckBox cbShowOverlay = new CheckBox("Show overlay");
    imageAvailability.addListener((c, v, n) -> {
        if (n == ImageAvailability.OVERLAY_ONLY)
            cbShowOverlay.setSelected(true);
        else if (n == ImageAvailability.IMAGE_ONLY)
            cbShowOverlay.setSelected(false);
        cbShowOverlay.setDisable(n != ImageAvailability.BOTH);
    });
    ListView<TMAEntry> listImages = new ListView<>();
    listImages.setCellFactory(v -> new ImageListCell(cbShowOverlay.selectedProperty(), imageCache));
    listImages.widthProperty().addListener((v, o, n) -> listImages.refresh());
    listImages.setStyle("-fx-control-inner-background-alt: -fx-control-inner-background ;");
    table.getSelectionModel().getSelectedItems().addListener((Change<? extends TreeItem<TMAEntry>> e) -> {
        List<TMAEntry> entries = new ArrayList<>();
        for (TreeItem<TMAEntry> item : e.getList()) {
            if (item.getChildren().isEmpty()) {
                if (item.getValue().hasImage() || item.getValue().hasOverlay())
                    entries.add(item.getValue());
            } else {
                for (TreeItem<TMAEntry> item2 : item.getChildren()) {
                    if (item2.getValue().hasImage() || item2.getValue().hasOverlay())
                        entries.add(item2.getValue());
                }
            }
            listImages.getItems().setAll(entries);
        }
    });
    cbShowOverlay.setAlignment(Pos.CENTER);
    cbShowOverlay.setMaxWidth(Double.MAX_VALUE);
    cbShowOverlay.setPadding(new Insets(5, 5, 5, 5));
    cbShowOverlay.selectedProperty().addListener((v, o, n) -> listImages.refresh());
    paneImages.setCenter(listImages);
    paneImages.setTop(cbShowOverlay);

    // Determine visibility based upon whether there are any images to show
    //      Tab tabImages = new Tab("Images", paneImages);

    ScrollPane scrollPane = new ScrollPane(paneKaplanMeier);
    scrollPane.setFitToWidth(true);
    scrollPane.setFitToHeight(true);
    scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
    scrollPane.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
    Tab tabSurvival = new Tab("Survival", scrollPane);
    tabPane.getTabs().addAll(new Tab("Table", getCustomizeTablePane()),
            //            tabImages,
            new Tab("Histogram", histogramDisplay.getPane()), new Tab("Scatterplot", scatterPane.getPane()),
            tabSurvival);
    tabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);

    //      if (imageAvailability.get() != ImageAvailability.NONE)
    //         tabPane.getTabs().add(1, tabImages);
    //      
    //      imageAvailability.addListener((c, v, n) -> {
    //         if (n == ImageAvailability.NONE)
    //            tabPane.getTabs().remove(tabImages);
    //         else if (!tabPane.getTabs().contains(tabImages))
    //            tabPane.getTabs().add(1, tabImages);
    //      });

    //      tabSurvival.visibleProperty().bind(
    //            Bindings.createBooleanBinding(() -> !survivalColumns.isEmpty(), survivalColumns)
    //            );

    pane.setCenter(tabPane);

    pane.setMinWidth(350);

    return pane;
}

From source file:qupath.lib.gui.tma.TMASummaryViewer.java

/**
 * Recursively search for a TreeItem, based upon the TMAEntry it represents.
 * /*from   w w w.  java 2 s .  c o  m*/
 * @param item
 * @param entry
 * @return
 */
private TreeItem<TMAEntry> getItem(final TreeItem<TMAEntry> item, final TMAEntry entry) {
    if (item == null)
        return null;
    if (item.getValue() == entry)
        return item;
    for (TreeItem<TMAEntry> item2 : item.getChildren()) {
        TreeItem<TMAEntry> found = getItem(item2, entry);
        if (found != null)
            return found;
    }
    return null;
}