public void restoreExpansionState(JTree tree) {

    for (int i = 0; i < tree.getRowCount(); i++) {
      TreePath path = tree.getPathForRow(i);
      Object entryObject = path.getLastPathComponent();
      if (entryObject instanceof Entry) {
        Entry entry = (Entry) entryObject;
        String absoluteLocation = entry.getLocation().getAbsoluteLocation();
        if (expandedRepositories.contains(absoluteLocation)
            || expandedNodes.contains(absoluteLocation)) {
          tree.expandPath(path);
        }
      }
    }
    restoreSelectionPath(tree);
  }