Ejemplo n.º 1
0
 @Override
 public UpdateContainer doIt(Workspace workspace) throws CommandException {
   UpdateContainer undoEffects =
       workspace.getCommandHistory().undoOrRedoCommandsUntil(workspace, commandIdArg);
   UpdateContainer result = new UpdateContainer(new HistoryUpdate(workspace.getCommandHistory()));
   result.append(undoEffects);
   return result;
 }
 private List<Command> gatherAllOperateSelectionCommands(
     List<Command> commands, Workspace workspace) {
   List<Command> operationCommands = new ArrayList<Command>();
   for (Command c : commands) {
     if (c instanceof OperateSelectionCommand) {
       OperateSelectionCommand t = (OperateSelectionCommand) c;
       if (isSamehTableId(t.getHNodeId(), hNodeId, workspace)) {
         JSONObject obj = workspace.getCommandHistory().getCommandJSON(workspace, t);
         Command tmp = generateCommandFromJSON(workspace, obj);
         if (tmp != null) operationCommands.add(tmp);
       }
     }
   }
   return operationCommands;
 }
  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory factory = workspace.getFactory();
    SuperSelection superSel = getSuperSelection(worksheet);
    HTable hTable = factory.getHTable(factory.getHNode(hNodeId).getHTableId());
    Selection currentSel = superSel.getSelection(hTable.getId());
    if (currentSel != null) {
      currentSel.updateSelection();
    }
    CommandHistory history = workspace.getCommandHistory();
    List<Command> tmp =
        gatherAllOperateSelectionCommands(
            history.getCommandsFromWorksheetId(worksheetId), workspace);
    if (tmp.size() > 0) {
      JSONArray inputJSON = new JSONArray();
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "worksheetId", worksheetId, ParameterType.worksheetId));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject("hNodeId", hNodeId, ParameterType.hNodeId));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "operation", Operation.Intersect.name(), ParameterType.other));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "pythonCode", SelectionManager.defaultCode, ParameterType.other));
      inputJSON.put(CommandInputJSONUtil.createJsonObject("onError", "false", ParameterType.other));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "selectionName", superSel.getName(), ParameterType.other));
      Command t = null;
      try {
        t = new OperateSelectionCommandFactory().createCommand(inputJSON, workspace);
      } catch (Exception e) {

      }
      if (t != null) history._getHistory().add(t);
      history._getHistory().addAll(tmp);
    }
    UpdateContainer uc =
        WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(
            worksheetId, superSel);
    uc.add(new HistoryUpdate(history));
    return uc;
  }