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 int getChildIndex(InspectionTreeNode node, InspectionTreeNode child) {
   int idx = 0;
   Enumeration children = node.children();
   while (children.hasMoreElements()) {
     InspectionTreeNode ch = (InspectionTreeNode) children.nextElement();
     if (ch == child) break;
     idx++;
   }
   return idx;
 }
 private void restoreExpansionStatus(InspectionTreeNode node) {
   if (myExpandedUserObjects.contains(node.getUserObject())) {
     sortChildren(node);
     TreeNode[] pathToNode = node.getPath();
     expandPath(new TreePath(pathToNode));
     Enumeration children = node.children();
     while (children.hasMoreElements()) {
       InspectionTreeNode childNode = (InspectionTreeNode) children.nextElement();
       restoreExpansionStatus(childNode);
     }
   }
 }
 private static void addElementsInNode(InspectionTreeNode node, List<RefEntity> out) {
   if (!node.isValid()) return;
   if (node instanceof RefElementNode) {
     final RefEntity element = ((RefElementNode) node).getElement();
     if (!out.contains(element)) {
       out.add(0, element);
     }
   }
   if (node instanceof ProblemDescriptionNode) {
     final RefEntity element = ((ProblemDescriptionNode) node).getElement();
     if (!out.contains(element)) {
       out.add(0, element);
     }
   }
   final Enumeration children = node.children();
   while (children.hasMoreElements()) {
     InspectionTreeNode child = (InspectionTreeNode) children.nextElement();
     addElementsInNode(child, out);
   }
 }