/** Main actions invoked by key "Enter" */ private void enterKeyEvent() { String input = txtCommandInput.getText(); // If the input is empty, return to the normal task list. if (input == null || input.isEmpty() || input.trim().length() == 0) { logic.setIsSearchOp(false); taskTableView.setItems(mainApp.getTaskData()); } else { // for command stack pastCommands.push(input); // Differentiate different command types.Handle help windows here. if (input.equalsIgnoreCase("exit")) { mainApp.exit(); txtCommandInput.clear(); } else if (input.equalsIgnoreCase("help")) { mainApp.indexHelp(); txtCommandInput.clear(); } else if (input.equalsIgnoreCase("sos")) { mainApp.sos(); txtCommandInput.clear(); } else if (input.equalsIgnoreCase("basic") || input.equalsIgnoreCase("`hb")) { mainApp.basic(); txtCommandInput.clear(); } else if (input.equalsIgnoreCase("advance") || input.equalsIgnoreCase("`ha")) { mainApp.advance(); txtCommandInput.clear(); } else if (input.equalsIgnoreCase("shortcut") || input.equalsIgnoreCase("shortcuts") || input.equalsIgnoreCase("shortform") || input.equalsIgnoreCase("shortforms") || input.equalsIgnoreCase("`sc")) { mainApp.shortForm(); txtCommandInput.clear(); } else if (input.equalsIgnoreCase("credit") || input.equalsIgnoreCase("`cd")) { mainApp.credit(); txtCommandInput.clear(); } else { // if the command does not belong to any commands above, pass it to the parser and logic String inputCommand = txtCommandInput.getText().trim(); logger.log(Level.INFO, "Here comes a command."); execute(inputCommand); } } }
/** * This is the method to pass the package from parser to the logic for execution. * * @param input User's input string */ private void execute(String input) { CommandPackage cmdPack = cmdParser.getCommandPackage(input); logger.log(Level.INFO, "CommandParser parses the command."); if (cmdPack == null) { System.out.println("input: " + input); feedback.setText(invalidMsg); } else { assert (cmdPack != null); try { System.out.println(input); String result = logic.executeCommand(cmdPack); feedback.setText(result); txtCommandInput.clear(); taskTableView.setItems(mainApp.getTaskData()); logger.log(Level.INFO, "Update the table view."); } catch (InvalidCommandException e) { feedback.setText(e.getMessage()); } } }
/** The constructor. The constructor is called before the initialize() method. */ public TaskViewController() { logic = LogicClass.getInstance(); cmdParser = CommandParser.getInstance(); }