Example usage for javafx.scene.control TreeView layout

List of usage examples for javafx.scene.control TreeView layout

Introduction

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

Prototype

public final void layout() 

Source Link

Document

Executes a top-down layout pass on the scene graph under this parent.

Usage

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

@Override
public Rectangle getVisibleRowBounds(final Rectangle rowBounds) {
    Rectangle result = EventThreadQueuerJavaFXImpl.invokeAndWait("getVisibleRowBounds", //$NON-NLS-1$
            new Callable<Rectangle>() {

                @Override// w  w  w. j  a va2  s. co m
                public Rectangle call() throws Exception {
                    TreeView<?> tree = ((TreeView<?>) getTree());
                    // Update the layout coordinates otherwise
                    // we would get old position values
                    tree.layout();
                    Rectangle visibleTreeBounds = new Rectangle(0, 0, Rounding.round(tree.getWidth()),
                            Rounding.round(tree.getHeight()));
                    return rowBounds.intersection(visibleTreeBounds);
                }
            });
    return result;

}

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

@Override
public void expandNode(final Object node) {
    scrollNodeToVisible(node);//from ww  w  .  ja  v  a 2s.  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:org.eclipse.jubula.rc.javafx.tester.adapter.TreeOperationContext.java

@Override
public void collapseNode(final Object node) {
    scrollNodeToVisible(node);/*from www.  j  a  va  2s  .  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// ww w  . j  a v a  2s  .c  om
        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;
}