/**
   * @return set with ALL projects managed by hg, <b>not only</b> projects for which we know remote
   *     repo locations
   * @throws HgException
   */
  private Map<HgRoot, List<IResource>> loadRepos() throws HgException {
    rootRepos.clear();
    List<IProject> projects = getAllProjects();
    Map<HgRoot, List<IResource>> roots = ResourceUtils.groupByRoot(projects);

    for (Entry<HgRoot, List<IResource>> entry : roots.entrySet()) {
      HgRoot hgRoot = entry.getKey();
      loadRepos(hgRoot);
    }
    return roots;
  }
  /**
   * The action has been activated. The argument of the method represents the 'real' action sitting
   * in the workbench UI.
   *
   * @see IWorkbenchWindowActionDelegate#run
   */
  public void run(IAction action) {
    Shell shell = window != null ? window.getShell() : MercurialEclipsePlugin.getActiveShell();
    if (!confirmRemove(shell)) {
      return;
    }
    List<IResource> resources = ResourceUtils.getResources(selection);
    Map<HgRoot, List<IResource>> byRoot = ResourceUtils.groupByRoot(resources);

    try {
      HgRemoveClient.removeResourcesLater(byRoot);
    } finally {
      for (Map.Entry<HgRoot, List<IResource>> mapEntry : byRoot.entrySet()) {
        HgRoot hgRoot = mapEntry.getKey();
        new RefreshStatusJob("Refreshing " + hgRoot.getName(), hgRoot).schedule();
      }
    }
  }
  private void saveProjectRepos() {
    List<IProject> projects = getAllProjects();

    Map<HgRoot, List<IResource>> byRoot = ResourceUtils.groupByRoot(projects);
    Set<HgRoot> roots = byRoot.keySet();

    for (HgRoot hgRoot : roots) {
      String key = getRootKey(hgRoot);
      Set<IHgRepositoryLocation> repoSet = rootRepos.get(hgRoot);
      if (repoSet == null) {
        continue;
      }
      synchronized (entriesLock) {
        repoSet = new LinkedHashSet<IHgRepositoryLocation>(repoSet);
      }
      saveRepositories(key, repoSet);
    }
  }