Example usage for javafx.scene.control TreeItem getParent

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

Introduction

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

Prototype

public final TreeItem<T> getParent() 

Source Link

Document

The parent of this TreeItem.

Usage

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java

private void initializeFilesTree() {
    folderTree.setOnMouseClicked(event -> handleFolderChange());
    folderTree.setCellFactory(treeView -> {
        HBox hbox = new HBox();
        hbox.setMaxWidth(200);/* ww w . j  a v a  2  s .  c om*/
        hbox.setPrefWidth(200);
        hbox.setSpacing(7);

        FontAwesomeIconView openFolderIcon = new FontAwesomeIconView(FontAwesomeIcon.FOLDER_OPEN_ALT);
        openFolderIcon.setTranslateY(7);
        FontAwesomeIconView closedFolderIcon = new FontAwesomeIconView(FontAwesomeIcon.FOLDER_ALT);
        closedFolderIcon.setTranslateY(7);

        Label dirName = new Label();
        dirName.setMaxWidth(150);

        FontAwesomeIconView removeIcon = new FontAwesomeIconView(FontAwesomeIcon.REMOVE);

        Tooltip deleteToolTip = new Tooltip();
        deleteToolTip.setText("Verzeichnis aus Workspace entfernen");

        Button button = new Button(null, removeIcon);
        button.setTooltip(deleteToolTip);
        button.setTranslateX(8);

        return new TreeCell<String>() {
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setGraphic(null);
                    setText(null);
                } else if (getTreeItem() instanceof FilePathTreeItem) {
                    hbox.getChildren().clear();
                    dirName.setText(item);
                    if (getTreeItem().isExpanded()) {
                        hbox.getChildren().add(openFolderIcon);
                    } else {
                        hbox.getChildren().add(closedFolderIcon);
                    }
                    hbox.getChildren().add(dirName);
                    TreeItem<String> treeItem = getTreeItem();
                    TreeItem<String> parent = treeItem != null ? treeItem.getParent() : null;
                    if (parent != null && parent.equals(folderTree.getRoot())) {
                        String path = ((FilePathTreeItem) getTreeItem()).getFullPath();
                        button.setOnAction(event -> handleDeleteDirectory(Paths.get(path)));
                        hbox.getChildren().add(button);
                    }
                    setGraphic(hbox);
                }
            }
        };
    });
}

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

private String treeItemToScriptString(TreeItem item) {
    List<TreeItem> list = new ArrayList<>();
    do {// ww  w  . java  2 s.  c om
        list.add(item);
    } while ((item = item.getParent()) != null);
    Collections.reverse(list);

    StringBuilder sb = new StringBuilder("xdat");
    for (int i = 0; i < list.size(); i++) {
        Object value = list.get(i).getValue();
        if (value instanceof ListHolder) {
            ListHolder holder = (ListHolder) list.get(i).getValue();
            sb.append('.').append(holder.name);
            if (i + 1 < list.size()) {
                sb.append('[').append(holder.list.indexOf(list.get(++i).getValue())).append(']');
            }
        }
    }
    return sb.toString();
}

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

private void updateContextMenu(ContextMenu contextMenu, TreeView<Object> elements) {
    contextMenu.getItems().clear();/*from   w  w  w  .  j  a v  a2 s .com*/

    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:com.heliosdecompiler.helios.gui.controller.FileTreeController.java

public void updateTree(List<TreeNode> add, List<TreeNode> remove) {
    Set<TreeItem<TreeNode>> updated = new HashSet<>();

    ArrayDeque<TreeNode> queue = new ArrayDeque<>();
    queue.addAll(add);/*w  w  w . ja v  a 2  s .c  o  m*/

    while (!queue.isEmpty()) {
        TreeNode thisNode = queue.pop();

        TreeItem<TreeNode> parent;

        if (thisNode.getParent() == null) {
            parent = rootItem;
        } else {
            parent = itemMap.get(thisNode.getParent());
        }

        updated.add(parent);

        TreeItem<TreeNode> thisItem = new TreeItem<>(thisNode);
        thisItem.addEventHandler(TreeItem.<TreeNode>branchExpandedEvent(), event -> {
            if (thisItem.getChildren().size() == 1) {
                thisItem.getChildren().get(0).setExpanded(true);
            }
        });
        thisItem.setGraphic(new ImageView(new Image(getIconForTreeItem(thisNode))));
        FutureTask<Void> call = new FutureTask<>(() -> {
            parent.getChildren().add(thisItem);
            return null;
        });
        Platform.runLater(call);
        try {
            call.get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

        itemMap.put(thisNode, thisItem);

        queue.addAll(thisNode.getChildren());
    }

    for (TreeItem<TreeNode> parent : updated) {
        if (parent.getChildren().size() > 1) {
            FutureTask<Void> call = new FutureTask<>(() -> {
                parent.getChildren().sort((a, b) -> {
                    int ac = a.getValue().getChildren().size();
                    int bc = b.getValue().getChildren().size();

                    if (ac == 0 && bc != 0)
                        return 1;
                    else if (ac != 0 && bc == 0)
                        return -1;
                    return a.getValue().getDisplayName().compareTo(b.getValue().getDisplayName());
                });
                return null;
            });
            Platform.runLater(call);
            try {
                call.get();
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }

    queue.addAll(remove);

    while (!queue.isEmpty()) {
        TreeNode thisNode = queue.pop();
        TreeItem<TreeNode> thisItem = itemMap.remove(thisNode);
        thisItem.getParent().getChildren().remove(thisItem);
        queue.addAll(thisNode.getChildren());
    }
}

From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java

public void fireDelete(JEVisClass jclass) {
    System.out.println("delete event");
    if (jclass == null) {
        jclass = getSelectionModel().getSelectedItem().getValue();
    }/*from w ww.j  a  v a2s .c  o m*/

    if (jclass != null) {
        try {
            ConfirmDialog dia = new ConfirmDialog();
            String question = "Do you want to delete the Class \"" + jclass.getName() + "\" ?";

            if (dia.show(JEConfig.getStage(), "Delete Class", "Delete Class?",
                    question) == ConfirmDialog.Response.YES) {
                try {
                    System.out.println("User want to delete: " + jclass.getName());

                    if (jclass.getInheritance() != null) {
                        for (JEVisClassRelationship rel : jclass
                                .getRelationships(JEVisConstants.ClassRelationship.INHERIT)) {
                            jclass.deleteRelationship(rel);
                        }
                    }

                    final TreeItem<JEVisClass> item = getObjectTreeItem(jclass);
                    final TreeItem<JEVisClass> parentItem = item.getParent();

                    jclass.delete();
                    deteleItemFromTree(item);

                    //                        Platform.runLater(new Runnable() {
                    //                            @Override
                    //                            public void run() {
                    //                                parentItem.getChildren().remove(item);
                    //                                getSelectionModel().select(parentItem);
                    //                                parentItem.setExpanded(false);
                    //
                    //                            }
                    //                        });
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        } catch (JEVisException ex) {
            Logger.getLogger(ClassTree.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java

private void deteleItemFromTree(final TreeItem<JEVisClass> item) {
    try {/*from www. j  a  v a 2s  .  c  o m*/
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                try {
                    String className = item.getValue().getName();

                    _itemCache.remove(className);

                    for (Map.Entry<TreeItem<JEVisClass>, ObservableList<TreeItem<JEVisClass>>> entry : _itemChildren
                            .entrySet()) {

                        if (entry.getValue().contains(item)) {
                            entry.getValue().remove(item);
                        }
                    }

                    getSelectionModel().select(item.getParent());

                    if (_graphicCache.containsKey(className)) {
                        _graphicCache.remove(className);
                    }

                    //                    parentItem.setExpanded(false);
                } catch (JEVisException ex) {
                    Logger.getLogger(ClassTree.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        });
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.navpanel.NavPanel.java

/**
 * Set the tree to the passed in group/*from ww  w  . j a  v a  2  s.  co m*/
 *
 * @param grouping
 */
public void setFocusedGroup(DrawableGroup grouping) {

    List<String> path = groupingToPath(grouping);

    final GroupTreeItem treeItemForGroup = ((GroupTreeItem) activeTreeProperty.get().getRoot())
            .getTreeItemForPath(path);

    if (treeItemForGroup != null) {
        Platform.runLater(() -> {
            TreeItem<TreeNode> ti = treeItemForGroup;
            while (ti != null) {
                ti.setExpanded(true);
                ti = ti.getParent();
            }
            int row = activeTreeProperty.get().getRow(treeItemForGroup);
            if (row != -1) {
                activeTreeProperty.get().getSelectionModel().select(treeItemForGroup);
                activeTreeProperty.get().scrollTo(row);
            }
        });
    }
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.navpanel.NavPanel.java

/**
 * Set the tree to the passed in group//from   w  w w .j  a v a 2s  .c  om
 *
 * @param grouping
 */
@ThreadConfined(type = ThreadType.JFX)
public void setFocusedGroup(DrawableGroup grouping) {

    List<String> path = groupingToPath(grouping);

    final GroupTreeItem treeItemForGroup = ((GroupTreeItem) activeTreeProperty.get().getRoot())
            .getTreeItemForPath(path);

    if (treeItemForGroup != null) {
        /* When we used to run the below code on the FX thread, it would
         * get into infinite loops when the next group button was pressed
         * quickly because the udpates became out of order and History could
         * not
         * keep track of what was current.
         *
         * Currently (4/2/15), this method is already on the FX thread, so
         * it is OK. */
        //Platform.runLater(() -> {
        TreeItem<TreeNode> ti = treeItemForGroup;
        while (ti != null) {
            ti.setExpanded(true);
            ti = ti.getParent();
        }
        int row = activeTreeProperty.get().getRow(treeItemForGroup);
        if (row != -1) {
            activeTreeProperty.get().getSelectionModel().select(treeItemForGroup);
            activeTreeProperty.get().scrollTo(row);
        }
        //});   //end Platform.runLater
    }
}

From source file:sonicScream.controllers.CategoryTabController.java

private void recursiveSetNodeExpanded(TreeItem<String> root, boolean expanded) {
    if (root.getParent() != null) //Don't want to collapse the root!
    {//from w ww  . j av  a 2s  . c  o  m
        root.setExpanded(expanded);
    }
    for (TreeItem<String> item : root.getChildren()) {
        if (item.getChildren().isEmpty()) {
            item.setExpanded(expanded);
        } else {
            recursiveSetNodeExpanded(item, expanded);
        }
    }
}

From source file:sonicScream.controllers.CategoryTabController.java

public void revertSound() {
    TreeItem<String> selectedNode = (TreeItem<String>) CategoryTabTreeView.getSelectionModel()
            .getSelectedItem();//w  w  w  .  ja v a 2s .  co m
    if (!selectedNode.isLeaf()) {
        return; //Shouldn't even be possible, but just in case
    }
    //We use this later to find the correct node to select after a reversion.
    int nodeParentIndex = selectedNode.getParent().getParent().getChildren().indexOf(selectedNode.getParent());

    Script activeScript = (Script) CategoryTabComboBox.getValue();

    //get the index of the selected node relative to its parent.
    int selectedWaveIndex = selectedNode.getParent().getChildren().indexOf(selectedNode);
    VPKFileService vpkService = (VPKFileService) ServiceLocator.getService(VPKFileService.class);
    Script vpkScript = new Script(vpkService.getVPKEntry(activeScript.getVPKPath()), _category);
    List<TreeItem<String>> vpkWaves = TreeUtils.getWaveStrings(vpkScript.getRootNode()).orElse(null);
    if (vpkWaves != null && vpkWaves.size() > selectedWaveIndex) {
        TreeItem<String> selectedNodeInRoot = TreeUtils.getWaveStrings(activeScript.getRootNode()).get()
                .get(selectedWaveIndex);
        TreeItem<String> selectedNodeInVPKRoot = vpkWaves.get(selectedWaveIndex);
        String vpkNodeString = StringUtils.normalizeSpace((selectedNodeInVPKRoot.getValue()));
        selectedNodeInRoot.setValue(vpkNodeString);
        selectedNode.setValue(StringParsing.rootSoundToSimpleSound(vpkNodeString));
    }
    //if the index does NOT exist, remove the index from the root node, and
    //then do all the updating
    else {
        TreeItem<String> selectedNodeInRoot = TreeUtils.getWaveStrings(activeScript.getRootNode()).get()
                .get(selectedWaveIndex);
        selectedNodeInRoot.getParent().getChildren().remove(selectedNodeInRoot);
        selectedNode.getParent().getChildren().remove(selectedNode);
        //TODO: Delete the parent if it no longer has any children.
    }
}