コード例 #1
0
  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;
  }
コード例 #2
0
  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;
  }