/**
  * Calculate what the selection path should be once the specified node has been removed from the
  * tree.
  */
 private TreePath calculatePostRemoveSelectionPath(PreferencesNode node) {
   PreferencesNode parentNode = (PreferencesNode) node.getParent();
   int childCount = parentNode.getChildCount();
   if (childCount == 1) {
     // the only child is to be removed - select the parent
     return new TreePath(parentNode.getPath());
   }
   int nodeIndex = parentNode.getIndex(node);
   if (nodeIndex == childCount - 1) {
     // the last child in the list is to be removed - select the previous child
     return new TreePath(((PreferencesNode) parentNode.getChildAt(nodeIndex - 1)).getPath());
   }
   // by default, select the next child
   return new TreePath(((PreferencesNode) parentNode.getChildAt(nodeIndex + 1)).getPath());
 }