Example usage for javafx.scene.control TreeItem getValue

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

Introduction

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

Prototype

public final T getValue() 

Source Link

Document

Returns the application-specific data represented by this TreeItem.

Usage

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

private void pullDetail(TreeItem<Branch> item) {
    if (currentlyRebuilding || item == null)
        return;//from  www.j a v a2 s . c  om
    Branch branch = item.getValue();

    if (branch.group != null) {
        // if root, check prefix first
        String prefix = detail.extractPrefix();
        if (prefix != null) {
            prefix = prefix.trim();
            if (!prefix.endsWith("#"))
                prefix += "#";
            if (!stack.peekSchema().getSchemaPrefix().equals(prefix)) {
                try {
                    new URI(prefix);
                } catch (Exception ex) {
                    //informMessage("Invalid URI", "Prefix is not a valid URI: " + prefix);
                    return;
                }
                Schema schema = stack.getSchema();
                schema.setSchemaPrefix(prefix);
                stack.setSchema(schema);
            }
        }

        // then handle the group content
        Schema.Group modGroup = detail.extractGroup();
        if (modGroup == null)
            return;

        updateBranchGroup(branch, modGroup);

        item.setValue(new Branch(this));
        item.setValue(branch); // triggers redraw
    } else if (branch.assignment != null) {
        Schema.Assignment modAssn = detail.extractAssignment();
        if (modAssn == null)
            return;

        updateBranchAssignment(branch, modAssn);

        item.setValue(new Branch(this));
        item.setValue(branch); // triggers redraw
    } else if (branch.assay != null) {
        Schema.Assay modAssay = detail.extractAssay();
        if (modAssay == null)
            return;

        updateBranchAssay(branch, modAssay);

        item.setValue(new Branch(this));
        item.setValue(branch); // triggers redraw
    }
}

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 .  j a  v  a 2  s.  c  o  m

    // 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:Main.java

private TreeItem<File> createNode(final File f) {
    return new TreeItem<File>(f) {
        private boolean isLeaf;
        private boolean isFirstTimeChildren = true;
        private boolean isFirstTimeLeaf = true;

        @Override/*from w ww .  j av  a 2  s.c  om*/
        public ObservableList<TreeItem<File>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                File f = (File) getValue();
                isLeaf = f.isFile();
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) {
            File f = TreeItem.getValue();
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            if (f.isFile()) {
                return FXCollections.emptyObservableList();
            }
            File[] files = f.listFiles();
            if (files != null) {
                ObservableList<TreeItem<File>> children = FXCollections.observableArrayList();
                for (File childFile : files) {
                    children.add(createNode(childFile));
                }
                return children;
            }
            return FXCollections.emptyObservableList();
        }
    };
}

From source file:Main.java

private TreeItem<File> createNode(final File f) {
    return new TreeItem<File>(f) {
        private boolean isLeaf;
        private boolean isFirstTimeChildren = true;
        private boolean isFirstTimeLeaf = true;

        @Override/* w w  w .  j av a2s . c  o m*/
        public ObservableList<TreeItem<File>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                File f = (File) getValue();
                isLeaf = f.isFile();
            }

            return isLeaf;
        }

        private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) {
            File f = TreeItem.getValue();
            if (f != null && f.isDirectory()) {
                File[] files = f.listFiles();
                if (files != null) {
                    ObservableList<TreeItem<File>> children = FXCollections.observableArrayList();

                    for (File childFile : files) {
                        children.add(createNode(childFile));
                    }

                    return children;
                }
            }

            return FXCollections.emptyObservableList();
        }
    };
}

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

public void actionEditPaste() {
    if (!treeView.isFocused())
        return; // punt to default action

    TreeItem<Branch> item = currentBranch();
    if (item == null) {
        Util.informMessage("Clipboard Paste", "Select a group to paste into.");
        return;//from   www  .ja v  a 2s. c o m
    }
    Branch branch = item.getValue();

    Clipboard clipboard = Clipboard.getSystemClipboard();
    String serial = clipboard.getString();
    if (serial == null) {
        Util.informWarning("Clipboard Paste", "Content is not parseable.");
        return;
    }

    JSONObject json = null;
    try {
        json = new JSONObject(new JSONTokener(serial));
    } catch (JSONException ex) {
        Util.informWarning("Clipboard Paste",
                "Content is not parseable: it should be a JSON-formatted string.");
        return;
    }

    Schema.Group group = ClipboardSchema.unpackGroup(json);
    Schema.Assignment assn = ClipboardSchema.unpackAssignment(json);
    Schema.Assay assay = ClipboardSchema.unpackAssay(json);
    if (group == null && assn == null && assay == null) {
        Util.informWarning("Clipboard Paste",
                "Content does not represent a group, assignment or assay: cannot paste.");
        return;
    }

    pullDetail();
    Schema schema = stack.getSchema();

    if (group != null) {
        schema.appendGroup(schema.obtainGroup(branch.locatorID), group);
    } else if (assn != null) {
        schema.appendAssignment(schema.obtainGroup(branch.locatorID), assn);
    } else if (assay != null) {
        schema.appendAssay(assay);
    }

    stack.changeSchema(schema);
    rebuildTree();

    if (group != null)
        setCurrentBranch(locateBranch(schema.locatorID(group)));
    else if (assn != null)
        setCurrentBranch(locateBranch(schema.locatorID(assn)));

}

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.TreeOperationContext.java

@Override
public void collapseNode(final Object node) {
    scrollNodeToVisible(node);/*from  w  w w  .j a  v a 2s.  c om*/
    Object result = EventThreadQueuerJavaFXImpl.invokeAndWait("collapseNode", new Callable<Object>() { //$NON-NLS-1$

        @Override
        public Object call() throws Exception {
            List<? extends TreeCell> tCells = ComponentHandler.getAssignableFrom(TreeCell.class);
            for (TreeCell<?> cell : tCells) {
                TreeItem<?> item = cell.getTreeItem();
                if (item != null && item.equals(node) && item.isExpanded()) {
                    TreeView<?> tree = ((TreeView<?>) getTree());
                    // Update the layout coordinates otherwise
                    // we would get old position values
                    tree.layout();
                    return cell.getDisclosureNode();
                }
            }
            return null;
        }
    });
    if (result != null) {
        getRobot().click(result, null, ClickOptions.create().setClickCount(1).setMouseButton(1));
    }
    EventThreadQueuerJavaFXImpl.invokeAndWait("collapseNodeCheckIfCollapsed", new Callable<Void>() { //$NON-NLS-1$

        @Override
        public Void call() throws Exception {
            TreeItem<?> item = (TreeItem<?>) node;
            if (!((TreeView<?>) getTree()).isDisabled() && item.isExpanded()) {
                log.warn("Collapse node fallback used for: " //$NON-NLS-1$
                        + item.getValue());

                item.setExpanded(false);
            }
            return null;
        }
    });
}

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//from  w ww.j av  a  2 s .c o  m
        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:org.eclipse.jubula.rc.javafx.tester.adapter.TreeOperationContext.java

@Override
public void expandNode(final Object node) {
    scrollNodeToVisible(node);/*from   www . j  a v  a2s  .  c  om*/
    Object result = EventThreadQueuerJavaFXImpl.invokeAndWait("expandNode", //$NON-NLS-1$
            new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    List<? extends TreeCell> tCells = ComponentHandler.getAssignableFrom(TreeCell.class);
                    for (TreeCell<?> cell : tCells) {
                        TreeItem<?> item = cell.getTreeItem();
                        if (item != null && item.equals(node) && !item.isExpanded()) {
                            TreeView<?> tree = ((TreeView<?>) getTree());
                            // Update the layout coordinates otherwise
                            // we would get old position values
                            tree.layout();
                            return cell.getDisclosureNode();
                        }
                    }
                    return null;
                }
            });
    if (result != null) {
        getRobot().click(result, null, ClickOptions.create().setClickCount(1).setMouseButton(1));
    }
    EventThreadQueuerJavaFXImpl.invokeAndWait("expandNodeCheckIfExpanded", //$NON-NLS-1$
            new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    TreeItem<?> item = (TreeItem<?>) node;
                    if (!((TreeView<?>) getTree()).isDisabled() && !item.isExpanded()) {
                        log.warn("Expand node fallback used for: " //$NON-NLS-1$
                                + item.getValue());

                        item.setExpanded(true);
                    }
                    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 ww . j  a va  2s.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:spdxedit.PackageEditor.java

private void handleFileSelected(TreeItem<SpdxFile> newSelection) {
    btnDeleteFileFromPackage.setDisable(newSelection == null);
    if (newSelection == null) {
        currentFile = null;//from w  w  w . jav a2  s  .c o  m
    } else {
        //Set currentFile to null to make sure we don't accidentally edit the previous file
        currentFile = null;
        //Set the file type checkbox values to reflect this file's types
        chkListFileTypes.getCheckModel().clearChecks();

        //If multiple selections, then disable everything but the delete button
        boolean multipleSelections = filesTable.getSelectionModel().getSelectedItems().size() > 1;
        chkListFileTypes.setDisable(multipleSelections);
        //Disable/enable usage checkboxes for multiple selection
        Stream.of(chkExcludeFile, chkBuildTool, chkMetafile, chkOptionalComponent, chkDocumentation,
                chkTestCase, chkDataFile).forEach(checkbox -> checkbox.setDisable(multipleSelections));
        if (multipleSelections)
            return;

        //The element lookup by index seems to be broken on the CheckListView control,
        //so we'll have to provide the indices

        chkListFileTypes.getItems().forEach(item -> {
            if (ArrayUtils.contains(newSelection.getValue().getFileTypes(), item.getValue()))
                chkListFileTypes.getCheckModel().check(item);
            else
                chkListFileTypes.getCheckModel().clearCheck(item);
        });

        //Reset the relationship checkboxes
        chkDataFile.setSelected(SpdxLogic
                .findRelationship(newSelection.getValue(), RelationshipType.DATA_FILE_OF, pkg).isPresent());
        chkTestCase.setSelected(SpdxLogic
                .findRelationship(newSelection.getValue(), RelationshipType.TEST_CASE_OF, pkg).isPresent());
        chkDocumentation.setSelected(SpdxLogic
                .findRelationship(newSelection.getValue(), RelationshipType.DOCUMENTATION_OF, pkg).isPresent());
        chkMetafile.setSelected(SpdxLogic
                .findRelationship(newSelection.getValue(), RelationshipType.METAFILE_OF, pkg).isPresent());
        chkOptionalComponent.setSelected(
                SpdxLogic.findRelationship(newSelection.getValue(), RelationshipType.OPTIONAL_COMPONENT_OF, pkg)
                        .isPresent());
        chkBuildTool.setSelected(SpdxLogic
                .findRelationship(newSelection.getValue(), RelationshipType.BUILD_TOOL_OF, pkg).isPresent());

        chkExcludeFile.setSelected(SpdxLogic.isFileExcludedFromVerification(pkg, newSelection.getValue()));

        //Set the file relationship checkboxes
        Relationship[] relationships = newSelection.getValue().getRelationships();

        currentFile = newSelection.getValue();
    }
}