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

The following examples show how to use javafx.scene.control.TreeItem#isLeaf() . 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: JFXTreeTableCellSkin.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private void updateDisclosureNode() {
    Node disclosureNode = ((JFXTreeTableCell<S, T>) getSkinnable()).getDisclosureNode();
    if (disclosureNode != null) {
        TreeItem<S> item = getSkinnable().getTreeTableRow().getTreeItem();
        final S value = item == null ? null : item.getValue();
        boolean disclosureVisible = value != null
                                    && !item.isLeaf()
                                    && value instanceof RecursiveTreeObject
                                    && ((RecursiveTreeObject) value).getGroupedColumn() == getSkinnable().getTableColumn();
        disclosureNode.setVisible(disclosureVisible);
        if (!disclosureVisible) {
            getChildren().remove(disclosureNode);
        } else if (disclosureNode.getParent() == null) {
            getChildren().add(disclosureNode);
            disclosureNode.toFront();
        } else {
            disclosureNode.toBack();
        }
        if (disclosureNode.getScene() != null) {
            disclosureNode.applyCss();
        }
    }
}
 
Example 2
Source File: OpcDaBrowserController.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void populateAvailableTags(TreeItem<OpcDaTagTreeBranch> selectedItem) {
	try {
		clearTagData();
		availableTags.clear();

		if (selectedItem != null && selectedItem.isLeaf()) {

			// fill in the possible tags
			OpcDaTagTreeBranch selectedNode = selectedItem.getValue();

			OpcDaTreeBrowser treeBrowser = getApp().getOpcDaClient().getTreeBrowser();

			Collection<OpcDaBrowserLeaf> tags = treeBrowser.getLeaves(selectedNode);

			availableTags.clear();
			for (OpcDaBrowserLeaf tag : tags) {
				if (!monitoredItemIds.contains(tag.getItemId())) {
					availableTags.add(tag);
				}
			}
		}
		lvAvailableTags.refresh();
	} catch (Exception e) {
		AppUtils.showErrorDialog(e);
	}
}
 
Example 3
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 4
Source File: RootController.java    From BetonQuest-Editor with GNU General Public License v3.0 6 votes vote down vote up
@FXML public void select(MouseEvent event) {
	try {
		TreeItem<String> selected = tree.getSelectionModel().getSelectedItem();
		if (event.getClickCount() != 2 || selected == null || !selected.isLeaf()) {
			return;
		}
		BetonQuestEditor instance = BetonQuestEditor.getInstance();
		PackageSet set = instance.getSet(selected.getParent().getValue());
		if (set == null) {
			return;
		}
		QuestPackage pack = set.getPackage(selected.getValue());
		if (pack == null) {
			return;
		}
		instance.display(pack);
		hide();
	} catch (Exception e) {
		ExceptionController.display(e);
	}
}
 
Example 5
Source File: ConditionTreeView.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public void checkExpanded(TreeItem<ConditionNode> item) {
    try {
        if (item == null || item.isLeaf() || !(item instanceof CheckBoxTreeItem)) {
            return;
        }
        CheckBoxTreeItem<ConditionNode> citem = (CheckBoxTreeItem<ConditionNode>) item;
        ConditionNode node = item.getValue();
        if (citem.isExpanded() && !expandedNodes.contains(node.getTitle())) {
            expandedNodes.add(node.getTitle());
        }
        for (TreeItem<ConditionNode> child : item.getChildren()) {
            checkExpanded(child);
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 6
Source File: TestRunner.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private TestTreeItem findNextFailureInChildren(TestTreeItem parent, boolean findInSibling) {
    TestTreeItem found = null;
    for (TreeItem<Test> child : parent.getChildren()) {
        if (child.isLeaf()
                && (((TestTreeItem) child).getState() == State.FAILURE || ((TestTreeItem) child).getState() == State.ERROR)) {
            found = (TestTreeItem) child;
            break;
        } else {
            found = findNextFailureInChildren((TestTreeItem) child, findInSibling);
            if (found != null) {
                break;
            }
        }
    }
    if (found == null && findInSibling) {
        TestTreeItem sib = (TestTreeItem) parent.nextSibling();
        if (isFailure(sib)) {
            found = sib;
        } else {
            if (sib != null) {
                found = findNextFailureInChildren(sib, true);
            }
        }
    }
    return found;
}
 
Example 7
Source File: JFXTreeTableCellBehavior.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean handleDisclosureNode(double x, double y) {
    final TreeItem<S> treeItem = getControl().getTreeTableRow().getTreeItem();
    if (!treeItem.isLeaf()) {
        final Node disclosureNode = getControl().getTreeTableRow().getDisclosureNode();
        if (disclosureNode != null) {
            if (disclosureNode.getBoundsInParent().contains(x + disclosureNode.getTranslateX(), y)) {
                if (treeItem != null) {
                    treeItem.setExpanded(!treeItem.isExpanded());
                }
                return true;
            }
        }
    }
    return false;
}
 
Example 8
Source File: PreferencesDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static <T> void forEachLeaf(TreeItem<? extends T> parent, Consumer<T> func)
{
	if (parent.isLeaf())
	{
		func.accept(parent.getValue());
	}
	else
	{
		parent.getChildren().forEach(child -> forEachLeaf(child, func));
	}
}
 
Example 9
Source File: TreeHelper.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Expand or collapse complete sub tree
 *
 *  @param node Node from which on to expand
 *  @param expand Expand or collapse?
 */
public static void setExpanded(final TreeItem<?> node, final boolean expand)
{
    if (node.isLeaf())
        return;
    node.setExpanded(expand);
    for (TreeItem<?> sub : node.getChildren())
        setExpanded(sub, expand);
}
 
Example 10
Source File: AlarmTreeView.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void expandAlarms(final TreeItem<AlarmTreeItem<?>> node)
{
    if (node.isLeaf())
        return;

    // Always expand the root, which itself is not visible,
    // but this will show all the top-level elements.
    // In addition, expand those items which are in active alarm.
    final boolean expand = node.getValue().getState().severity.isActive() ||
                           node == tree_view.getRoot();
    node.setExpanded(expand);
    for (TreeItem<AlarmTreeItem<?>> sub : node.getChildren())
        expandAlarms(sub);
}
 
Example 11
Source File: TestRunner.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void writeToParent(TreeItem<Test> parent, JSONObject parentJSON) {
    ObservableList<TreeItem<Test>> children = parent.getChildren();
    for (TreeItem<Test> child : children) {
        if (child.isLeaf()) {
            writeLeafToParent(child, parentJSON);
        } else {
            writeToParent(child, createParentJSONObject(child, parentJSON));
        }
    }
}
 
Example 12
Source File: MetadataNode.java    From sis with Apache License 2.0 5 votes vote down vote up
private void expandNodes(TreeItem<TreeTable.Node> root) {
    if (root == null || root.isLeaf()) {
        return;
    }
    root.setExpanded(getExpandNode().test(root.getValue()));
    for (TreeItem<TreeTable.Node> child : root.getChildren()) {
        expandNodes(child);
    }
}
 
Example 13
Source File: PreferencesDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static <T> void forEachLeaf(TreeItem<? extends T> parent, Consumer<T> func)
{
	if (parent.isLeaf())
	{
		func.accept(parent.getValue());
	}
	else
	{
		parent.getChildren().forEach(child -> forEachLeaf(child, func));
	}
}
 
Example 14
Source File: ResourceView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void expandTreeView(TreeItem<Resource> item) {
    if (item != null && !item.isLeaf()) {
        item.setExpanded(true);
        for (TreeItem<Resource> child : item.getChildren()) {
            expandTreeView(child);
        }
    }
}
 
Example 15
Source File: FunctionStage.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void changed(ObservableValue<? extends TreeItem<Object>> observable, TreeItem<Object> oldValue,
        TreeItem<Object> newValue) {
    if (newValue == null) {
        okButton.setDisable(true);
        documentArea.setText("");
        argumentPane.getChildren().clear();
        return;
    }
    TreeItem<Object> item = tree.getSelectionModel().getSelectedItem();
    String doc = "";
    boolean disable = true;
    functionItem = item;
    Object value = item.getValue();
    if (value instanceof Module) {
        doc = ((Module) value).getDocumentation();
    } else {
        doc = ((Function) value).getDocumentation();
        disable = false;
    }
    okButton.setDisable(disable);
    documentArea.setText(doc);
    argumentPane.getChildren().clear();
    if (item.isLeaf()) {
        addArguments(item);
    }
}
 
Example 16
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 17
Source File: ConditionTreeView.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public void expandNode(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 18
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 19
Source File: GeographyCodeSelectorController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
protected void removeNode(TreeItem<Text> node, GeographyCode code) {
    if (node == null || code == null || node.isLeaf()) {
        return;
    }
    for (TreeItem<Text> subNode : node.getChildren()) {
        if (subNode.getValue().getUserData() != null) {
            long subCode = (long) (subNode.getValue().getUserData());
            if (subCode == code.getGcid()) {
                node.getChildren().remove(subNode);
                return;
            }
        }
        removeNode(subNode, code);
    }
}
 
Example 20
Source File: GeographyCodeSelectorController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
protected boolean loaded(TreeItem<Text> item) {
    if (item == null || item.isLeaf()) {
        return true;
    }
    try {
        TreeItem<Text> dummyItem = (TreeItem<Text>) (item.getChildren().get(0));
        return !"Loading".equals(dummyItem.getValue().getText());
    } catch (Exception e) {
        return true;
    }
}