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:ubicrypt.ui.files.FilesController.java

private static void removeItem(final TreeItem<ITreeItem> item) {
    final TreeItem<ITreeItem> parent = item.getParent();
    parent.getChildren().remove(item);
}

From source file:sonicScream.utilities.ScriptParser.java

public static boolean areScriptTreesEqual(TreeItem<String> lhs, TreeItem<String> rhs) {
    if (lhs.getChildren().size() != rhs.getChildren().size() || lhs.isLeaf() != rhs.isLeaf()) {
        return false;
    }/*from w  w w. j  a va  2s. c  o m*/

    boolean areEqual = true;

    if (!lhs.isLeaf()) {
        for (int i = 0; i < lhs.getChildren().size() - 1; i++) {
            areScriptTreesEqual(lhs.getChildren().get(i), rhs.getChildren().get(i));
        }
    }

    return lhs.getValue().equals(rhs.getValue());
}

From source file:ubicrypt.ui.ctrl.HomeController.java

private static void removeItem(final TreeItem<ITreeItem> item) {
    final TreeItem<ITreeItem> parent = item.getParent();
    parent.getChildren().remove(item);
    if (parent.getChildren().isEmpty() && !(parent.getValue() instanceof RootFilesItem)) {
        removeItem(parent);/*from www  . jav  a  2s  . com*/
    }
}

From source file:Testing.TestMain.java

public static void treeSample(Stage stage, Collection root) {
    TreeItem<String> rootItem = new TreeItem<String>("D:\\");

    rootItem.setExpanded(true);//from   w w w  .  j  a  va  2 s .co  m

    for (Iterator it = root.iterator(); it.hasNext();) {
        Object i = it.next();
        TreeItem<String> item = new TreeItem<String>(i.toString());
        rootItem.getChildren().add(item);
    }
    /*
     for (int i = 1; i < 6; i++) {
     TreeItem<String> item = new TreeItem<String>("Message" + i);
     rootItem.getChildren().add(item);
     }*/
    TreeView<String> tree = new TreeView<String>(rootItem);
    StackPane rootpane = new StackPane();
    rootpane.getChildren().add(tree);
    stage.setScene(new Scene(rootpane, 300, 250));
    stage.show();
}

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

private static void buildTree(IOEntity entity, Field listField, TreeView<Object> elements, String nameFilter) {
    elements.setRoot(null);//from www.  j a  v  a2s .  com

    if (entity == null)
        return;

    try {
        List<IOEntity> list = (List<IOEntity>) listField.get(entity);
        if (!listField.isAnnotationPresent(Type.class)) {
            log.log(Level.WARNING, String.format("XDAT.%s: @Type not defined", listField.getName()));
            Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                    String.format("XDAT.%s: @Type not defined", listField.getName()));
        } else {
            Class<? extends IOEntity> type = listField.getAnnotation(Type.class).value()
                    .asSubclass(IOEntity.class);
            TreeItem<Object> rootItem = new TreeItem<>(new ListHolder(entity, list, listField.getName(), type));

            elements.setRoot(rootItem);

            rootItem.getChildren().addAll(list.stream().map(Controller::createTreeItem)
                    .filter(treeItem -> checkTreeNode(treeItem, nameFilter)).collect(Collectors.toList()));
        }
    } catch (IllegalAccessException e) {
        log.log(Level.WARNING, String.format("%s.%s is not accessible",
                listField.getDeclaringClass().getSimpleName(), listField.getName()), e);
        Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                listField.getDeclaringClass().getSimpleName() + "." + listField.getName()
                        + " is not accessible");
    }
}

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

private static boolean checkTreeNode(TreeItem<Object> treeItem, String nameFilter) {
    if (checkName(Objects.toString(treeItem.getValue()), nameFilter))
        return true;

    for (TreeItem<Object> childItem : treeItem.getChildren())
        if (checkTreeNode(childItem, nameFilter))
            return true;

    return false;
}

From source file:spdxedit.PackageEditor.java

/**
 * Opens the modal package editor for the provided package.
 *
 * @param pkg               The package to edit.
 * @param relatablePackages Packages to which the edited package may optionally have defined relationships
 * @param parentWindow      The parent window.
 *//*from  ww w  .ja  va  2  s  .c  o m*/
public static void editPackage(final SpdxPackage pkg, final List<SpdxPackage> relatablePackages,
        SpdxDocumentContainer documentContainer, Window parentWindow) {

    final PackageEditor packageEditor = new PackageEditor(pkg, relatablePackages, documentContainer);
    final Stage dialogStage = new Stage();
    dialogStage.setTitle("Edit SPDX Package: " + pkg.getName());
    dialogStage.initStyle(StageStyle.DECORATED);
    dialogStage.initModality(Modality.APPLICATION_MODAL);
    dialogStage.setY(parentWindow.getX() + parentWindow.getWidth() / 2);
    dialogStage.setY(parentWindow.getY() + parentWindow.getHeight() / 2);
    dialogStage.setResizable(false);
    try {
        FXMLLoader loader = new FXMLLoader(NewPackageDialog.class.getResource("/PackageEditor.fxml"));
        loader.setController(packageEditor);
        Pane pane = loader.load();
        Scene scene = new Scene(pane);
        dialogStage.setScene(scene);
        dialogStage.getIcons().clear();
        dialogStage.getIcons().add(UiUtils.ICON_IMAGE_VIEW.getImage());
        //Populate the file list on appearance
        dialogStage.setOnShown(event -> {
            try {
                final SpdxFile dummyfile = new SpdxFile(pkg.getName(), null, null, null, null, null, null, null,
                        null, null, null, null, null);
                TreeItem<SpdxFile> root = new TreeItem<>(dummyfile);
                packageEditor.filesTable.setRoot(root);
                //Assume a package without is external
                //TODO: replace with external packages or whatever alternate mechanism in 2.1
                packageEditor.btnAddFile.setDisable(pkg.getFiles().length == 0);
                root.getChildren()
                        .setAll(Stream.of(pkg.getFiles())
                                .sorted(Comparator.comparing(file -> StringUtils.lowerCase(file.getName()))) //Sort by file name
                                .map(TreeItem<SpdxFile>::new).collect(Collectors.toList()));
            } catch (InvalidSPDXAnalysisException e) {
                logger.error("Unable to get files for package " + pkg.getName(), e);
            }

            packageEditor.tabFiles.setExpanded(true);

        });

        //Won't assign this event through FXML - don't want to propagate the stage beyond this point.
        packageEditor.btnOk.setOnMouseClicked(event -> dialogStage.close());
        dialogStage.showAndWait();

    } catch (IOException ioe) {
        throw new RuntimeException("Unable to load dialog", ioe);
    }
}

From source file:sonicScream.utilities.ScriptParser.java

private static StringBuilder recursiveBuildScript(StringBuilder scriptString, TreeItem<String> node,
        int level) {
    String tabs = "";
    for (int i = 1; i < level; i++) {
        tabs += "\t";
    }//ww  w . ja v  a 2s . c  o  m

    if (node.getParent() != null) {
        scriptString.append(tabs + node.getValue() + "\n");
    }
    /* 
     * TODO: Figure out a way to track brace placement without just checking to see if a node has children. Maybe 
     * a custom node object that tracks whether a node is followed by braces?
     */
    if (!node.isLeaf()) {
        scriptString.append(tabs + "{\n");
        level++;
        for (int i = 0; i < node.getChildren().size(); i++) {
            scriptString = recursiveBuildScript(scriptString, node.getChildren().get(i), level);
        }
        level--;
        scriptString.append(tabs + "}\n");
    }
    return scriptString;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    final Scene scene = new Scene(new Group(), 200, 400);
    Group sceneRoot = (Group) scene.getRoot();

    TreeItem<String> childNode1 = new TreeItem<>("Node 1");
    TreeItem<String> childNode2 = new TreeItem<>("Node 2");
    TreeItem<String> childNode3 = new TreeItem<>("Node 3");

    TreeItem<String> root = new TreeItem<>("Root");
    root.setExpanded(true);//from  w  w w .  j  a v a 2s. c  om

    root.getChildren().setAll(childNode1, childNode2, childNode3);

    TreeTableColumn<String, String> column = new TreeTableColumn<>("Column");
    column.setPrefWidth(150);

    column.setCellValueFactory(
            (CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(p.getValue().getValue()));

    TreeTableView<String> treeTableView = new TreeTableView<>(root);
    treeTableView.getColumns().add(column);
    sceneRoot.getChildren().add(treeTableView);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Button Sample");
    stage.setWidth(300);//from   w ww  .  j  av a 2s .  co m
    stage.setHeight(190);

    VBox vbox = new VBox();
    vbox.setLayoutX(20);
    vbox.setLayoutY(20);

    TreeItem<String> root = new TreeItem<String>("Root Node");
    root.setExpanded(true);
    root.getChildren().addAll(new TreeItem<String>("Item 1"), new TreeItem<String>("Item 2"),
            new TreeItem<String>("Item 3"));
    TreeView<String> treeView = new TreeView<String>(root);

    vbox.getChildren().add(treeView);
    vbox.setSpacing(10);
    ((Group) scene.getRoot()).getChildren().add(vbox);

    stage.setScene(scene);
    stage.show();
}