下面列出了javafx.scene.control.TreeItem#isLeaf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
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();
}
}
}
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);
}
}
@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);
}
}
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());
}
}
@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;
}
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;
}
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;
}
}
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);
}
}
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());
}
}
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());
}
}
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());
}
}
@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);
}
}
private void expandTreeView(TreeItem<Resource> item) {
if (item != null && !item.isLeaf()) {
item.setExpanded(true);
for (TreeItem<Resource> child : item.getChildren()) {
expandTreeView(child);
}
}
}
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));
}
}
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);
}
}
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));
}
}
}
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);
}
/** 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);
}
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));
}
}