Java Code Examples for javafx.scene.control.TreeItem#getChildren()

The following examples show how to use javafx.scene.control.TreeItem#getChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceTree.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Cleanup the tree.
 */
@FxThread
private void cleanup(@NotNull TreeItem<ResourceElement> treeItem) {

    var element = treeItem.getValue();
    if (element instanceof FileResourceElement || element instanceof LoadingResourceElement) {
        return;
    }

    var children = treeItem.getChildren();

    for (int i = children.size() - 1; i >= 0; i--) {
        cleanup(children.get(i));
    }

    if (children.isEmpty() && treeItem.getParent() != null) {
        var parent = treeItem.getParent();
        var parentChildren = parent.getChildren();
        parentChildren.remove(treeItem);
    }
}
 
Example 2
Source File: ScenegraphTreeView.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
private void removeForNode(final TreeItem<SVNode> treeItem) {
    if (treeItem != null) {
        final List<TreeItem<SVNode>> treeItemChildren = treeItem.getChildren();
        if (treeItemChildren != null) {
            /**
             * Do not use directly the list as it will suffer concurrent
             * modifications
             */
            @SuppressWarnings("unchecked") final TreeItem<SVNode> children[] = treeItemChildren.toArray(new TreeItem[treeItemChildren.size()]);
            for (int i = 0; i < children.length; i++) {
                removeForNode(children[i]);
            }
        }

        // This does not seem to delete the TreeItem from the tree -- only
        // moves
        // it up a level visually
        /**
         * I don't know why this protection is needed
         */
        if (treeItem.getParent() != null) {
            treeItem.getParent().getChildren().remove(treeItem);
        }
        treeViewData.remove(treeItem.getValue());
    }
}
 
Example 3
Source File: ConditionTreeView.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public void setSelection(TreeItem<ConditionNode> item) {
    try {
        if (item == null || !(item instanceof CheckBoxTreeItem)) {
            return;
        }
        CheckBoxTreeItem<ConditionNode> citem = (CheckBoxTreeItem<ConditionNode>) item;
        ConditionNode node = item.getValue();
        if (selectedTitles.contains(node.getTitle())) {
            citem.setSelected(true);
            return;
        } else if (item.isLeaf()) {
            return;
        }
        for (TreeItem<ConditionNode> child : item.getChildren()) {
            setSelection(child);
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 4
Source File: FilesTreeController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
protected TreeItem<FileInformation> getChild(TreeItem<FileInformation> item, String name) {
    if (item == null) {
        return null;
    }
    for (TreeItem<FileInformation> child : item.getChildren()) {
        if (name.equals(child.getValue().getFileName())) {
            return child;
        }
    }
    FileInformation childInfo = new FileInformation();
    childInfo.setFileName(name);
    final TreeItem<FileInformation> childItem = new TreeItem(childInfo);
    childItem.setExpanded(true);
    childInfo.getSelectedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> ov,
                Boolean oldItem, Boolean newItem) {
            if (!isSettingValues) {
                treeItemSelected(childItem, newItem);
            }
        }
    });
    item.getChildren().add(childItem);
    return childItem;
}
 
Example 5
Source File: TreeUtil.java    From arma-dialog-creator with MIT License 6 votes vote down vote up
/**
 Checks if the given start TreeItem contains the searching {@link TreeItem} as a descendant. Checks are done recursively.
 
 @param startItem where to start searching
 @param searchingFor TreeItem to look for
 @return if startItem has the descendant searchingFor
 */
public static boolean hasDescendant(@NotNull TreeItem<?> startItem, @NotNull TreeItem<?> searchingFor) {
	if (startItem.equals(searchingFor)) {
		return true;
	}
	if (startItem.getChildren().size() == 0) {
		return false;
	}
	for (TreeItem<?> item : startItem.getChildren()) {
		boolean contains = hasDescendant(item, searchingFor);
		if (contains) {
			return true;
		}
		
	}
	
	return false;
}
 
Example 6
Source File: VirtualResourceTree.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Fill the tree item.
 *
 * @param item the tree item.
 */
@FxThread
private void fill(@NotNull final TreeItem<VirtualResourceElement<?>> item) {

    final VirtualResourceElement<?> element = item.getValue();
    if(!element.hasChildren()) {
        return;
    }

    final ObservableList<TreeItem<VirtualResourceElement<?>>> items = item.getChildren();

    final Array<VirtualResourceElement<?>> children = element.getChildren();
    children.sort(NAME_COMPARATOR);
    children.forEach(child -> items.add(new TreeItem<>(child)));

    items.forEach(this::fill);
}
 
Example 7
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private String getTreeTableItemText(TreeTableView<?> treeTableView, TreeItem<?> lastPathComponent) {
    @SuppressWarnings("rawtypes")
    TreeTableColumn treeTableColumn = treeTableView.getTreeColumn();
    if (treeTableColumn == null) {
        treeTableColumn = treeTableView.getColumns().get(0);
    }
    ObservableValue<?> cellObservableValue = treeTableColumn.getCellObservableValue(lastPathComponent);
    String original = cellObservableValue.getValue().toString();
    String itemText = original;
    int suffixIndex = 0;
    TreeItem<?> parent = lastPathComponent.getParent();
    if (parent == null)
        return itemText;
    ObservableList<?> children = parent.getChildren();
    for (int i = 0; i < children.indexOf(lastPathComponent); i++) {
        TreeItem<?> child = (TreeItem<?>) children.get(i);
        cellObservableValue = treeTableColumn.getCellObservableValue(child);
        String current = cellObservableValue.getValue().toString();
        if (current.equals(original)) {
            itemText = String.format("%s(%d)", original, ++suffixIndex);
        }
    }
    return itemText;
}
 
Example 8
Source File: FileUnarchiveController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public void checkSelection(TreeItem<FileInformation> item) {
    try {
        if (item == null || item.getValue() == null) {
            return;
        }
        FileInformation info = item.getValue();
        if (info.isSelected() && "file".equals(info.getFileType())) {
            selected.add(info.getFileName());
        }
        List<TreeItem<FileInformation>> children = item.getChildren();
        if (children == null || children.isEmpty()) {
            return;
        }
        for (TreeItem<FileInformation> child : children) {
            checkSelection(child);
        }
    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 9
Source File: GeographyCodeSelectorController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
protected void addNode(TreeItem<Text> node, GeographyCode parent, GeographyCode child) {
    if (node == null || parent == null || child == null) {
        return;
    }
    if (node.getValue().getUserData() != null) {
        long current = (long) (node.getValue().getUserData());
        if (current == parent.getGcid()) {
            Text childNode = new Text(child.getName());
            childNode.setOnMouseClicked((MouseEvent event) -> {
                userController.codeSelected(child);
            });
            childNode.setUserData(child.getGcid());
            TreeItem<Text> codeItem = new TreeItem(childNode);
            node.getChildren().add(codeItem);
            node.setExpanded(true);
            return;
        }
    }
    if (node.isLeaf()) {
        return;
    }
    for (TreeItem<Text> subNode : node.getChildren()) {
        addNode(subNode, parent, child);
    }
}
 
Example 10
Source File: ConditionTreeView.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public void expandNone(TreeItem<ConditionNode> item) {
    try {
        if (item == null || item.isLeaf()) {
            return;
        }
        item.setExpanded(true);
        for (TreeItem<ConditionNode> child : item.getChildren()) {
            expandNode(child);
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 11
Source File: IconEditorFactory.java    From constellation with Apache License 2.0 5 votes vote down vote up
private TreeItem<IconNode> findIconNode(TreeItem<IconNode> node, String value) {
    final IconNode iconNode = node.getValue();
    if (iconNode.iconExists(value)) {
        return node;
    } else {
        for (TreeItem<IconNode> child : node.getChildren()) {
            final TreeItem<IconNode> result = findIconNode(child, value);
            if (result != null) {
                return result;
            }
        }
        return null;
    }

}
 
Example 12
Source File: FunctionStage.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void addAllParentTreeItem(TreeItem<Object> root, List<TreeItem<Object>> parentItems) {
    ObservableList<TreeItem<Object>> children = root.getChildren();
    for (TreeItem<Object> treeItem : children) {
        if (treeItem.getChildren().size() != 0) {
            parentItems.add(treeItem);
        } else {
            addAllParentTreeItem(treeItem, parentItems);
        }
    }
}
 
Example 13
Source File: ModFuncContextMenu.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private void recurseModFuncItems(TreeItem<ModFunc> item, HashSet<ModFunc> funcs) {
    if(item == null)
        return;
    if(item.getValue() == null || (!item.getValue().isModule() && !item.getValue().isModuleInfo()))
        funcs.add(item.getValue());

    for (TreeItem<ModFunc> childItem : item.getChildren()) {
        recurseModFuncItems(childItem, funcs);
    }
}
 
Example 14
Source File: ConditionTreeView.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public void checkSelection(TreeItem<ConditionNode> item) {
    try {
        if (item == null || !(item instanceof CheckBoxTreeItem)) {
            return;
        }
        CheckBoxTreeItem<ConditionNode> citem = (CheckBoxTreeItem<ConditionNode>) item;
        ConditionNode node = item.getValue();
        if (citem.isSelected()) {
            if (finalConditions == null || finalConditions.isBlank()) {
                if (node.getCondition() == null || node.getCondition().isBlank()) {
                    finalConditions = "";
                } else {
                    finalConditions = " ( " + node.getCondition() + ") ";
                }
            } else {
                if (node.getCondition() != null && !node.getCondition().isBlank()) {
                    finalConditions += " OR ( " + node.getCondition() + " ) ";
                }
            }

            if (finalTitle == null || finalTitle.isBlank()) {
                finalTitle = "\"" + node.getTitle() + "\"";
            } else {
                finalTitle += " + \"" + node.getTitle() + "\"";
            }
            if (!selectedTitles.contains(node.getTitle())) {
                selectedTitles.add(node.getTitle());
            }
            return;
        } else if (item.isLeaf() || !citem.isIndeterminate()) {
            return;
        }
        for (TreeItem<ConditionNode> child : item.getChildren()) {
            checkSelection(child);
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 15
Source File: ConfigurationUIController.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void setCurrentNodePath(String value) {
    if (value == null) return;
    String[] parts = value.split(Pattern.quote(DELIMITER));
    TreeItem<ConfigNode> current = deviceTree.getRoot();
    for (String part : parts) {
        for (TreeItem child : current.getChildren()) {
            if (child.toString().equals(part)) {
                current = child;
            }
        }
    }
    deviceTree.getSelectionModel().select(current);
}
 
Example 16
Source File: ResourceTree.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Fill the node.
 */
@FxThread
private void fill(@NotNull TreeItem<ResourceElement> treeItem) {

    var element = treeItem.getValue();
    var extensionFilter = getExtensionFilter();

    if (!element.hasChildren(extensionFilter, isOnlyFolders())) {
        return;
    }

    var items = treeItem.getChildren();

    if (isLazyMode()) {
        items.add(new TreeItem<>(LoadingResourceElement.getInstance()));
    } else {

        var children = element.getChildren(extensionFilter, isOnlyFolders());
        if (children == null) {
            return;
        }

        children.sort(NAME_COMPARATOR);
        children.forEach(child -> items.add(new TreeItem<>(child)));

        items.forEach(this::fill);
    }
}
 
Example 17
Source File: FileBrowserController.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void assertTreeDoesntContain(final TreeItem<FileInfo> item, final Path file)
{
    final Path dir = item.getValue().file.toPath();
    logger.log(Level.FINE, () -> "Does " + dir + " still contain " + file + "?");
    if (! file.startsWith(dir))
    {
        logger.log(Level.FINE, "Can't!");
        return;
    }

    final int dir_len = dir.getNameCount();
    final File sub = new File(item.getValue().file, file.getName(dir_len).toString());
    for (TreeItem<FileInfo> child : item.getChildren())
        if (sub.equals(child.getValue().file))
        {
            // Found file or sub path to it..
            if (sub.isDirectory())
                assertTreeDoesntContain(child, file);
            else
            {   // Found the file still listed as a child of 'item',
                // so refresh 'item'
                logger.log(Level.FINE, () -> "Forcing refresh of " + dir + " to hide " + sub);
                Platform.runLater(() -> ((FileTreeItem)item).forceRefresh());
            }
            return;
        }

    logger.log(Level.FINE, "Not found, all good");
}
 
Example 18
Source File: ModFuncContextMenu.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private ArrayList<ModFunc> findUnfilteredFunctions() {
    ObservableList<TreeItem<ModFunc>> filteredTreeModules = rootProperty.get().getChildren();
    ArrayList<ModFunc> funs = new ArrayList<>();
    for (TreeItem<ModFunc> treeItem : filteredTreeModules) {
        for (TreeItem<ModFunc> modFunc : treeItem.getChildren()) {
            if(!modFunc.getValue().isModuleInfo()) {
                funs.add(modFunc.getValue());
            }
        }
    }
    return funs;
}
 
Example 19
Source File: AlarmTreeView.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void dumpTree(TreeItem<AlarmTreeItem<?>> item)
{
	final ObservableList<TreeItem<AlarmTreeItem<?>>> children = item.getChildren();
	System.out.printf("item: %s , has %d children.\n", item.getValue().getName(), children.size());
	for (final TreeItem<AlarmTreeItem<?>> child : children)
	{
		System.out.println(child.getValue().getName());
		dumpTree(child);
	}
}
 
Example 20
Source File: PathItem.java    From LiveDirsFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void signalDeletionRecursively(TreeItem<T> node, I initiator) {
    for(TreeItem<T> child: node.getChildren()) {
        signalDeletionRecursively(child, initiator);
    }
    reporter.reportDeletion(getPath(), getPath().relativize(getProjector().apply(node.getValue())), initiator);
}