Example usage for javafx.scene.control TreeCell getTreeItem

List of usage examples for javafx.scene.control TreeCell getTreeItem

Introduction

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

Prototype

public final TreeItem<T> getTreeItem() 

Source Link

Document

Returns the TreeItem currently set in this TreeCell.

Usage

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

private void addPseudoClassToLeafs(TreeView<Path> tree) {
    PseudoClass leaf = PseudoClass.getPseudoClass("leaf");

    tree.setCellFactory(tv -> {//from   ww  w  . ja  v  a  2  s .c o m
        TreeCell<Path> cell = new TreeCell<>();
        cell.itemProperty().addListener((obs, oldValue, newValue) -> {
            if (newValue == null) {
                cell.setText("");
                cell.setGraphic(null);
            } else {
                cell.setText(newValue.toFile().getName());
                cell.setGraphic(cell.getTreeItem().getGraphic());
            }
        });
        cell.treeItemProperty().addListener((obs, oldTreeItem, newTreeItem) -> cell
                .pseudoClassStateChanged(leaf, newTreeItem != null && newTreeItem.isLeaf()));
        return cell;
    });
}

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

@Override
public String getRenderedText(final Object node) throws StepExecutionException {
    String result = EventThreadQueuerJavaFXImpl.invokeAndWait("getRenderedText", new Callable<String>() { //$NON-NLS-1$

        @Override/*from  ww  w. ja  va2  s .  co  m*/
        public String 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)) {
                    return cell.getText();
                }
            }
            return null;
        }
    });

    return result;
}

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

@Override
public void expandNode(final Object node) {
    scrollNodeToVisible(node);//www . ja va 2  s. c  o m
    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:org.eclipse.jubula.rc.javafx.tester.adapter.TreeOperationContext.java

@Override
public void collapseNode(final Object node) {
    scrollNodeToVisible(node);//from ww w  .j ava  2  s  . c o m
    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:org.eclipse.jubula.rc.javafx.tester.adapter.TreeOperationContext.java

@Override
public Rectangle getNodeBounds(final Object node) {
    Rectangle result = EventThreadQueuerJavaFXImpl.invokeAndWait("getNodeBounds", new Callable<Rectangle>() { //$NON-NLS-1$
        @Override//from w w  w .jav a2s  .  c  o m
        public Rectangle call() throws Exception {
            List<? extends TreeCell> tCells = ComponentHandler.getAssignableFrom(TreeCell.class);
            for (TreeCell<?> cell : tCells) {
                TreeItem<?> item = cell.getTreeItem();
                TreeView<?> tree = (TreeView<?>) getTree();
                if ((item != null && item.equals(node))) {
                    // Update the layout coordinates otherwise
                    // we would get old position values
                    tree.layout();

                    Point2D posTree = tree.localToScreen(0, 0);
                    Point2D posCell = cell.localToScreen(0, 0);
                    Bounds b = cell.getBoundsInParent();
                    Rectangle cBounds = new Rectangle(
                            Math.abs(Rounding.round((posCell.getX() - posTree.getX()))),
                            Math.abs(Rounding.round((posCell.getY() - posTree.getY()))),
                            Rounding.round(b.getWidth()), Rounding.round(b.getHeight()));
                    return cBounds;
                }
            }
            return null;
        }
    });
    return result;
}