private void restoreUsageExpandState(final Collection<UsageState> states) {
   // always expand the last level group
   final DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot();
   for (int i = root.getChildCount() - 1; i >= 0; i--) {
     final DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i);
     if (child instanceof GroupNode) {
       final TreePath treePath = new TreePath(child.getPath());
       myTree.expandPath(treePath);
     }
   }
   myTree.getSelectionModel().clearSelection();
   for (final UsageState usageState : states) {
     usageState.restore();
   }
 }
 private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) {
   if (!myTree.isExpanded(pathFrom)) {
     return;
   }
   final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent();
   final int childCount = node.getChildCount();
   for (int idx = 0; idx < childCount; idx++) {
     final TreeNode child = node.getChildAt(idx);
     if (child instanceof UsageNode) {
       final Usage usage = ((UsageNode) child).getUsage();
       states.add(
           new UsageState(
               usage,
               myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child))));
     } else {
       captureUsagesExpandState(pathFrom.pathByAddingChild(child), states);
     }
   }
 }