private void restorePath(ArrayList<Object> newPath, int idx) { if (idx >= myPath.length) return; InspectionTreeNode oldNode = (InspectionTreeNode) myPath[idx]; InspectionTreeNode newRoot = (InspectionTreeNode) newPath.get(idx - 1); InspectionResultsViewComparator comparator = InspectionResultsViewComparator.getInstance(); Enumeration children = newRoot.children(); while (children.hasMoreElements()) { InspectionTreeNode child = (InspectionTreeNode) children.nextElement(); if (comparator.compare(child, oldNode) == 0) { newPath.add(child); restorePath(newPath, idx + 1); return; } } // Exactly same element not found. Trying to select somewhat near. int count = newRoot.getChildCount(); if (count > 0) { if (myIndicies[idx] < count) { newPath.add(newRoot.getChildAt(myIndicies[idx])); } else { newPath.add(newRoot.getChildAt(count - 1)); } } }
private void sortChildren(InspectionTreeNode node) { final List<TreeNode> children = TreeUtil.childrenToArray(node); Collections.sort(children, InspectionResultsViewComparator.getInstance()); node.removeAllChildren(); TreeUtil.addChildrenTo(node, children); ((DefaultTreeModel) getModel()).reload(node); }