Example usage for javafx.scene.control TreeView getRoot

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

Introduction

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

Prototype

public final TreeItem<T> getRoot() 

Source Link

Document

Returns the current root node of this TreeView, or null if no root node is specified.

Usage

From source file:acmi.l2.clientmod.xdat.Controller.java

private void updateContextMenu(ContextMenu contextMenu, TreeView<Object> elements) {
    contextMenu.getItems().clear();//from  w w w .  jav  a  2s.c  om

    TreeItem<Object> root = elements.getRoot();
    TreeItem<Object> selected = elements.getSelectionModel().getSelectedItem();

    if (selected == null) {
        if (root != null)
            contextMenu.getItems().add(createAddMenu("Add ..", elements, root));
    } else {
        Object value = selected.getValue();
        if (value instanceof ListHolder) {
            contextMenu.getItems().add(createAddMenu("Add ..", elements, selected));
        } else if (selected.getParent() != null && selected.getParent().getValue() instanceof ListHolder) {
            MenuItem add = createAddMenu("Add to parent ..", elements, selected.getParent());

            MenuItem delete = new MenuItem("Delete");
            delete.setOnAction(event -> {
                ListHolder parent = (ListHolder) selected.getParent().getValue();

                int index = parent.list.indexOf(value);
                editor.getHistory().valueRemoved(treeItemToScriptString(selected.getParent()), index);

                parent.list.remove(index);
                selected.getParent().getChildren().remove(selected);

                elements.getSelectionModel().selectPrevious();
                elements.getSelectionModel().selectNext();
            });
            contextMenu.getItems().addAll(add, delete);
        }
        if (value instanceof ComponentFactory) {
            MenuItem view = new MenuItem("View");
            view.setOnAction(event -> {
                if (value instanceof L2Context)
                    ((L2Context) value).setResources(l2resources.getValue());
                Stage stage = new Stage();
                stage.setTitle(value.toString());
                Scene scene = new Scene(((ComponentFactory) value).getComponent());
                scene.getStylesheets().add(getClass().getResource("l2.css").toExternalForm());
                stage.setScene(scene);
                stage.show();
            });
            contextMenu.getItems().add(view);
        }
    }
}

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

/**
 * Creates a new instance. The JTree must have a tree model.
 *
 * @param queuer//  www.  jav  a 2  s.  c  o  m
 *            The queuer
 * @param robot
 *            The Robot
 * @param tree
 *            The tree
 */
public TreeOperationContext(IEventThreadQueuer queuer, IRobot robot, TreeView<?> tree) {
    super(queuer, robot, tree);
    Validate.notNull(tree.getRoot());
}

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

@Override
public Object[] getRootNodes() {
    Object[] result = EventThreadQueuerJavaFXImpl.invokeAndWait("getRootNodes", new Callable<Object[]>() { //$NON-NLS-1$

        @Override/*from   ww  w .  ja v  a 2s  .c o m*/
        public Object[] call() throws Exception {
            TreeView<?> tree = (TreeView<?>) getTree();

            // If the root is visible, just return that.
            if (tree.showRootProperty().getValue()) {
                return new Object[] { tree.getRoot() };
            }

            // If the root is not visible, return all direct
            // children of the
            // non-visible root.
            return getChildren(tree.getRoot());
        }
    });
    return result;
}