boolean (@NotNull Object element, @NotNull DefaultMutableTreeNode node) { Object eachParent = element; DefaultMutableTreeNode eachParentNode = node; boolean valid; while (true) { if (eachParent == null) { valid = eachParentNode == null; break; } if (!eachParent.equals(getElementFor(eachParentNode))) { valid = false; break; } eachParent = getTreeStructure().getParentElement(eachParent); eachParentNode = (DefaultMutableTreeNode)eachParentNode.getParent(); } return valid; }