private static DefaultMutableTreeNode findMatchedChild( DefaultMutableTreeNode parent, PathElement pathElement) { for (int j = 0; j < parent.getChildCount(); j++) { final TreeNode child = parent.getChildAt(j); if (!(child instanceof DefaultMutableTreeNode)) continue; final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child; final Object userObject = childNode.getUserObject(); if (pathElement.matchedWithByObject(userObject)) return childNode; } for (int j = 0; j < parent.getChildCount(); j++) { final TreeNode child = parent.getChildAt(j); if (!(child instanceof DefaultMutableTreeNode)) continue; final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child; final Object userObject = childNode.getUserObject(); if (!(userObject instanceof NodeDescriptor)) continue; final NodeDescriptor nodeDescriptor = (NodeDescriptor) userObject; if (pathElement.matchedWith(nodeDescriptor)) return childNode; } if (parent.getChildCount() > 0) { int index = pathElement.myItemIndex; if (index >= parent.getChildCount()) { index = parent.getChildCount() - 1; } final TreeNode child = parent.getChildAt(index); if (child instanceof DefaultMutableTreeNode) { return (DefaultMutableTreeNode) child; } } return null; }
private static void writeExternal(final Element pathXmlElement, final List<PathElement> path) throws WriteExternalException { for (final PathElement aPath : path) { final Element pathXmlElementElement = new Element(PATH_ELEMENT); aPath.writeExternal(pathXmlElementElement); pathXmlElement.addContent(pathXmlElementElement); } }
private static List<PathElement> readPath(final Element xmlPathElement) throws InvalidDataException { final ArrayList<PathElement> result = new ArrayList<PathElement>(); final List elements = xmlPathElement.getChildren(PATH_ELEMENT); for (final Object element : elements) { Element xmlPathElementElement = (Element) element; final PathElement pathElement = new PathElement(); pathElement.readExternal(xmlPathElementElement); result.add(pathElement); } return result; }
private static boolean applyTo( final int positionInPath, final List<PathElement> path, final Object root, final TreeFacade tree) { if (!(root instanceof DefaultMutableTreeNode)) return false; final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) root; final Object userObject = treeNode.getUserObject(); final PathElement pathElement = path.get(positionInPath); if (userObject instanceof NodeDescriptor) { if (!pathElement.matchedWith((NodeDescriptor) userObject)) return false; } else { if (!pathElement.matchedWithByObject(userObject)) return false; } tree.expand(treeNode) .doWhenDone( new Runnable() { public void run() { if (positionInPath == path.size() - 1) { return; } for (int j = 0; j < treeNode.getChildCount(); j++) { final TreeNode child = treeNode.getChildAt(j); final boolean resultFromChild = applyTo(positionInPath + 1, path, child, tree); if (resultFromChild) { break; } } } }); return true; }