private void closeSolution(String slnId) {

    if (slnId == null) {
      return;
    }

    Map<String, IProject> projectMap = getProjectMap();

    SolutionEntry solutionEntry = session.getSolutions().get(session.getCurrentSolution());
    LinkedHashSet<String> openProjects = new LinkedHashSet<String>();
    Set<String> projectNames = solutionEntry.getProjectNames();
    for (String pName : projectNames) {
      if (projectMap.get(pName).isOpen()) {
        openProjects.add(pName);
      }
    }
    solutionEntry.setOpenProjects(openProjects.toArray(new String[0]));

    for (String pName : openProjects) {
      IProject p = projectMap.get(pName);
      try {
        p.close(null);
      } catch (CoreException e) {
        e.printStackTrace();
      }
    }
  }
  @Override
  public void registerSolution(String path, boolean openProjects) throws IOException {

    Solution sln = readSolutionFile(path);

    SolutionEntry entry = new SolutionEntry(sln);
    session.getSolutions().put(entry.getId(), entry);
    reloadSolution(entry.getId(), openProjects);
  }
  public List<WorkbenchCommand> createSolutionCommands(String id, boolean openProjects)
      throws IOException {

    SolutionEntry solutionEntry = session.getSolutions().get(id);
    SolutionEntry sln = new SolutionEntry(readSolutionFile(solutionEntry.getFile()));

    // load projects if necessary
    List<WorkbenchCommand> commands = new LinkedList<WorkbenchCommand>();

    // update tracking information
    commands.add(new WorkbenchCommandImpl.UpdateTrackingInformation(id));

    /*
     *  - find out which projects are not yet imported and create ImportCommands
     *  - compare old set of project ids for the case that some projects have been removed from
     */
    Project[] projectSpecs = sln.getProjects();
    Map<String, IProject> projectMap = getProjectMap();
    Map<String, IWorkingSet> workingSetMap = getWorkingSetMap();

    // import/open new projects
    for (Project project : projectSpecs) {
      commands.add(
          new WorkbenchCommandImpl.ImportProject(
              project.getName(), project.getProjectFile(), openProjects));
    }

    // create working sets
    Set<String> createdWorkingSets = new HashSet<String>();
    Map<String, Set<String>> workingSetTable = getWorkingSetTable();
    List<WorkbenchCommand> addProjectsToWS = new LinkedList<WorkbenchCommand>();

    for (Project p : projectSpecs) {
      String wsId = p.getWorkingSet();
      if (!createdWorkingSets.contains(wsId)) {
        commands.add(new WorkbenchCommandImpl.CreateWorkingSet(wsId));
        // track which working set has been created already
        createdWorkingSets.add(wsId);
      }
      addProjectsToWS.add(new WorkbenchCommandImpl.AddProjectToWorkingSet(p.getName(), wsId));
    }

    // add projects to working sets
    commands.addAll(addProjectsToWS);

    // create/update solution working set
    if (workingSetMap.containsKey(sln.getId())) {
      commands.add(new WorkbenchCommandImpl.UpdateSolutionWorkingSet(sln));
    } else {
      commands.add(new WorkbenchCommandImpl.CreateSolutionWorkingSet(sln));
    }

    return commands;
  }
  private void openSolution(String slnId) {
    Map<String, IProject> projectMap = getProjectMap();

    // close all projects that do not belong to this solution
    SolutionEntry solutionEntry = session.getSolutions().get(slnId);
    Set<String> openProjects = new HashSet<String>(Arrays.asList(solutionEntry.getOpenProjects()));
    for (String pName : openProjects) {
      IProject p = projectMap.get(pName);
      if (!p.isOpen()) {
        try {
          projectMap.get(pName).open(null);
        } catch (CoreException e) {
          e.printStackTrace();
        }
      }
    }
  }
  public List<WorkbenchCommand> removeSolutionCommands(String id) {

    // Note: everything that changes the (persistent) state of this plugin shall be encapsulated in
    // Commands
    //       to allow cancellation and roll backs
    SolutionEntry entry = session.getSolutions().get(id);

    Map<String, IProject> projectMap = getProjectMap();
    Set<String> projectIds = entry.getProjectNames();
    Map<String, Set<String>> wsTable = getWorkingSetTable();

    List<WorkbenchCommand> commands = new LinkedList<WorkbenchCommand>();

    // remove solution and corresponding working set
    commands.add(new WorkbenchCommandImpl.UnregisterSolution(id));

    // remove projects
    Project[] projects = entry.getProjects();
    for (Project p : projects) {
      if (projectMap.containsKey(p.getName())) {
        IProject project = projectMap.get(p.getName());
        commands.add(
            new WorkbenchCommandImpl.RemoveProjectFromWorkingSet(p.getName(), p.getWorkingSet()));
        commands.add(new WorkbenchCommandImpl.RemoveProject(project));
      }
    }

    // remove associated working sets
    if (wsTable.containsKey(id)) {
      Set<String> wsIds = wsTable.get(id);
      for (String wsId : wsIds) {
        commands.add(new WorkbenchCommandImpl.RemoveWorkingSet(wsId));
      }
    }

    commands.add(new WorkbenchCommandImpl.RemoveSolutionWorkingSet(id));

    return commands;
  }
 public List<Solution> getSolutions() {
   LinkedList<Solution> solutions = new LinkedList<Solution>();
   solutions.addAll(session.getSolutions().values());
   return solutions;
 }
 @Override
 public Set<String> getSolutionNames() {
   return session.getSolutions().keySet();
 }