public void redo() {
    if (currentVersion == getLastIndex()) return;

    ICommand command = history.get(++currentVersion);
    command.execute();
    updateState();
  }
  public String parse(String cmd, Hashtable resources) {
    mapping = CommandMapping.getInstance();
    String rueckgabe = "/error command unknown";

    // Wurde etwas eingegeben
    if (!cmd.equals("")) {
      Vector cmdparts = new Vector();
      Matcher mat = param.matcher(cmd);

      while (mat.find()) {
        cmdparts.add(mat.group(1).replace("\"", ""));
      }

      ICommand command = mapping.getCommand(resources, (String) cmdparts.get(0));

      if (command != null) {
        if (cmdparts.size() > 1) {
          for (int i = 1; i < cmdparts.size(); i++) {
            command.addParameter((String) cmdparts.get(i));
          }
        }
        if (command != null) rueckgabe = command.execute();
      }
    }

    return rueckgabe;
  }
  public void undo() {
    if (currentVersion < 0) return;

    ICommand command = history.get(currentVersion--);
    command.undo();
    updateState();
  }
Beispiel #4
0
  public String run(String[] args) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    for (ICommand command : _commandInterpreter.getCommands()) {
      pw.println(command.getName() + ": " + command.getDescription());
    }
    pw.println("exit: Quit the application");
    pw.flush();
    return sw.toString();
  }
  @Override
  public void execute() {
    final ICommand scriptCommand = new StreetScriptCommand(folder, city);
    scriptCommand.execute();

    ScriptGenerator.executeScript(scriptPrefix + "street_network.sql", city);

    final ICommand netCommand = new StreetNetCommand(folder, city, file);
    netCommand.execute();

    ScriptGenerator.executeScript(scriptPrefix + "street_nodes_import.sql", city);
    ScriptGenerator.executeScript(scriptPrefix + "street_edges_import.sql", city);
  }
  public void addCommand(ICommand command) {
    while (getLastIndex() > currentVersion) history.remove(getLastIndex());

    history.add(command);
    command.execute();

    currentVersion = getLastIndex();

    updateState();
  }
  /** Test for Bug #5102. Never reproduced but interesting little test, worth keeping around */
  public void testPR() throws Exception {
    // create a project with a RefreshLocalJavaFileBuilder and a SortBuilder on the classpath
    IProject project = getWorkspace().getRoot().getProject("P1");
    project.create(null);
    project.open(null);
    IProjectDescription desc = project.getDescription();
    ICommand one = desc.newCommand();
    one.setBuilderName(RefreshLocalJavaFileBuilder.BUILDER_NAME);
    ICommand two = desc.newCommand();
    two.setBuilderName(SortBuilder.BUILDER_NAME);
    desc.setBuildSpec(new ICommand[] {one, two});
    project.setDescription(desc, null);

    // do a full build
    project.build(IncrementalProjectBuilder.FULL_BUILD, null);

    // do an incremental build by creating a file
    IFile file = project.getFile("Foo");
    file.create(getRandomContents(), true, getMonitor());
  }
 @DoCommand
 protected Result doCommand(Context context, ICommand command, String... curArgs) {
   try {
     if (context.isInteractive()) {
       System.out.println(">>> Press ENTER to continue <<<");
       System.in.read();
     }
     return command.execute(context, curArgs);
   } catch (SeleneseCommandErrorException e) {
     return e.getError();
   } catch (Exception e) {
     return new Error(e);
   }
 }
 /**
  * Execute command list.
  *
  * @param context Selenese Runner context.
  * @param cresultList command result list for keeping all command results.
  * @return result of command list execution.
  */
 public Result execute(Context context, CommandResultList cresultList) {
   CommandListIterator parentIterator = context.getCommandListIterator();
   CommandListIterator commandListIterator = iterator(parentIterator);
   context.pushCommandListIterator(commandListIterator);
   CommandSequence sequence = commandListIterator.getCommandSequence();
   boolean isContinued = true;
   try {
     while (isContinued && commandListIterator.hasNext()) {
       ICommand command = commandListIterator.next();
       sequence.increment(command);
       List<Screenshot> ss = command.getScreenshots();
       int prevSSIndex = (ss == null) ? 0 : ss.size();
       String[] curArgs = context.getVarsMap().replaceVarsForArray(command.getArguments());
       evalCurArgs(context, curArgs);
       Result result = doCommand(context, command, curArgs);
       if (result.isAborted()) isContinued = false;
       else context.waitSpeed();
       ss = command.getScreenshots();
       List<Screenshot> newSS;
       if (ss == null || prevSSIndex == ss.size()) newSS = null;
       else newSS = new ArrayList<>(ss.subList(prevSSIndex, ss.size()));
       CommandResult cresult =
           new CommandResult(
               sequence.toString(),
               command,
               newSS,
               result,
               cresultList.getEndTime(),
               System.currentTimeMillis());
       cresultList.add(cresult);
     }
   } finally {
     context.popCommandListIterator();
   }
   return cresultList.getResult();
 }
  /*
   * (non-Javadoc)
   *
   * @see org.sythe.suf.message.command.ICommandManager#executeCommand(org.sythe.suf.message.ISender,
   * java.lang.String)
   */
  @Override
  public final void handleCommand(ISender sender, String commandString) {
    String[] words = commandString.split("[ ]");
    String commandName = words[0].toLowerCase();
    String[] arguments = new String[words.length - 1];

    // Copy the arguments over and leave the command name out
    System.arraycopy(words, 1, arguments, 0, arguments.length);

    // Don't need words anymore so get rid of it
    words = null;

    if (iCommands.containsKey(commandName)) {
      ICommand command = iCommands.get(commandName);
      if (command.checkPermission(sender)) {
        if (command.checkArgumentNumber(arguments.length)) {
          /*
           * Check all the arugments to make sure they are the correct type.
           * Compare i to both args.length and arguments.length because of optional arguments and not checking
           * for too many arguments.
           */
          for (int i = 0; (i < arguments.length) && (i < command.getTotalParameters()); i++) {
            String value = command.checkParameterTypes(arguments[i], i);
            if (value != null) {
              errorHandler.onParameterTypeError(sender, arguments[i], value);
              // Must return to not run the command after
              return;
            }
          }

          command.run(sender, arguments);
        } else {
          errorHandler.onParameterNumberError(
              sender, arguments.length, command.getRequiredParameters());
        }
      } else {
        errorHandler.onPermissionError(sender, sender.getPermission(), command.getPermission());
      }
    } else {
      errorHandler.onNameError(sender, commandName);
    }
  }
Beispiel #11
0
 public void execute() {
   for (ICommand command : getCommands()) {
     command.execute();
   }
 }
Beispiel #12
0
  /**
   * *************************************************************** @Description - A method used to
   * execute input commands entered by the user. It also will display command input errors if
   * needed.
   *
   * @param The text command entered in by the user through the command line. @Returns - (N/A)
   *     <p>**************************************************************
   */
  @Override
  public boolean processCommand(String input) {

    // --- Variable Declarations  ---------------------------//

    // determines if system should exit program
    boolean exit = false;

    /* The identifier received for the command to be executed. */
    char commandID;

    /* Keeps track of document modifications for saving. */
    boolean docChange = false;

    // --- Main Routine -------------------------------------//

    // Error check that the command is valid.
    if ((input.length() > 1 && input.charAt(1) == ' ') || input.length() == 1) {

      error = false;
      // Extract the first character from the command.
      commandID = input.charAt(0);
      commandID = Character.toLowerCase(commandID);

      // Go through and match a command to run.
      switch (commandID) {

          // Insert before current line.
        case 'b':
          saved = false;
          command = new BeforeLine();
          command.executeCommand(input, CurrentLine);
          break;

          // Insert after current line.
        case 'i':
          saved = false;
          command = new AfterLine();
          command.executeCommand(input, CurrentLine);
          break;

          // Move current line down a position.
        case 'm':
          command = new MoveIndicatorDown();
          error = command.executeCommand(input, CurrentLine);
          break;

          // Move current line up 1 position.
        case 'u':
          command = new MoveIndicatorUp();
          error = command.executeCommand(input, CurrentLine);
          break;

          // Remove the current line.
        case 'r':
          saved = false;
          command = new RemoveCurrentLine();
          command.executeCommand(input, CurrentLine);
          break;

          // Display the project buffer.
        case 'd':
          clearConsole();
          command = new DisplayAllLines();
          displayOff = command.executeCommand(input, CurrentLine);
          break;

          // Clear and remove all lines in buffer.
        case 'c':
          if (!saved) {
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            System.out.println(
                "  The document has yet to be saved."
                    + "\n Would you like to save it before you exit?[y/n]");
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

            BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));

            try {
              String save = inputReader.readLine();
              save = save.toLowerCase();
              if (save.equals("y")) {
                try {
                  System.out.println("\nEnter save command: s <filename>:");
                  save = inputReader.readLine();
                  command = new SaveFile();
                  error = command.executeCommand(save, CurrentLine);
                } catch (IOException e) {
                  System.out.println(
                      "!!> Oops, There was an error " + "trying to run this command.");
                  e.printStackTrace();
                }
              }

            } catch (IOException e) {
              System.out.println("!!> Oops, There was an error " + "trying to run this command.");
              e.printStackTrace();
            }
          }

          saved = false;
          command = new ClearLines();
          command.executeCommand(input, CurrentLine);

          break;

          // Save file contents to a file directory.
        case 's':
          command = new SaveFile();
          error = command.executeCommand(input, CurrentLine);
          saved = true;
          break;

          // Load a files contents from a directory.
        case 'l':
          if (!saved) {
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            System.out.println(
                "  The document has yet to be saved."
                    + "\n Would you like to save it before you exit?[y/n]");
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

            BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));

            try {
              String save = inputReader.readLine();
              save = save.toLowerCase();
              if (save.equals("y")) {
                try {
                  System.out.println("\nEnter save command: s <filename>:");
                  save = inputReader.readLine();
                  command = new SaveFile();
                  error = command.executeCommand(save, CurrentLine);
                } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                  error = true;
                }
              }

            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              error = true;
            }
          }

          command = new ClearLines();
          command.executeCommand(input, CurrentLine);
          command = new LoadFile();
          error = command.executeCommand(input, CurrentLine);

          break;

          // Display list of commands.
        case 'h':
          error = true;
          command = new Help();
          command.executeCommand(input, CurrentLine);
          break;

          // Exit the editor.
        case 'x':
          if (input.equals("x")) {
            // Check and see if the document has yet to be saved.
            if (!saved) {
              System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
              System.out.println(
                  "  The document has yet to be saved."
                      + "\n Would you like to save it before you exit?[y/n]");
              System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

              BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));

              try {
                String save = inputReader.readLine();
                save = save.toLowerCase();
                if (save.equals("y")) {
                  try {
                    System.out.println("\nEnter save command: s <filename>:");
                    save = inputReader.readLine();
                    command = new SaveFile();
                    error = command.executeCommand(save, CurrentLine);
                  } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }

              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }

            System.out.println("Good bye!");
            exit = true;
          } else {
            error = true;
            System.out.println(
                "Incorrect Input Format. " + "\nShould be of form: [command] " + "[data_entry]");
            System.out.print("\n: ");
          }

          break;

          // Insert after last line.
        case 'e':
          command = new AfterLast();
          command.executeCommand(input, CurrentLine);
          break;

          // Cut command.
        case 'o':
          Cut cutCommand = new Cut();
          cutCommand.executeCommand(input, CurrentLine, clipBoardLine, documentLineCount);
          break;

        case 'p':
          Paste pasteCommand = new Paste();
          pasteCommand.executeCommand(input, CurrentLine, CurrentLine);
          break;

          // Invalid command entered.
        default:
          error = true;
          System.out.println(
              "Incorrect Input Format. " + "\nShould be of form: [command] [data_entry]");
          System.out.print("\n: ");
          break;
      }

      if (displayOff) {
        error = true;
        System.out.print(": ");
      }

      // Update document flag data.
      documentLineCount = textData.size();

      // Update the edit flag.
      docChange = commandID == 's' ? true : docChange;

    }

    // Nothing was entered into the buffer.
    else {
      error = true;
      System.out.println("Command does not match an existing command, enter 'h' for help. ");
      System.out.print(": ");
    }

    return exit;
  }
Beispiel #13
0
 public void invokeCommand() {
   System.out.println("Refer to command for execution");
   mCommand.execute();
 }