Example #1
0
 // Main command preview flow
 private ChangeListener<String> createUserInputListener() {
   return (observable, oldValue, newValue) -> {
     if (newValue.trim().isEmpty()) {
       ui.setPreviewStatus(FEEDBACK_READY);
     } else {
       ui.setPreviewStatus(previewCommand(newValue));
     }
   };
 }
Example #2
0
 // Listen for exit invoked by close button or system tray
 private ChangeListener<Boolean> createIsExitListener() {
   return (observable, oldValue, newValue) -> {
     if (newValue.booleanValue()) {
       if (!exit()) {
         ui.resetIsExit();
         ui.setPreviewStatus(Feedback.FEEDBACK_TRY_AGAIN);
       }
     }
   };
 }
Example #3
0
 // Main handle
 public void initUi(Stage stage) {
   ui = new UI(stage);
   ui.attachHandlersAndListeners(
       createKeyPressHandler(), createUserInputListener(), createIsExitListener());
   if (hasStartupError) {
     ui.createErrorDialog(ERROR_STARTUP_HEADER, ERROR_STARTUP_MESSAGE);
     exit();
   }
   initUiTaskList();
   ui.setPreviewStatus(FEEDBACK_READY);
 }
Example #4
0
  private void updateUiTaskList() {
    switch (currentView) {
      case SHOW_OUTSTANDING:
        ui.updateTaskList(taskEngine.getOutstandingTasks(), ScreenView.SCREEN_MAIN);
        break;

      case SHOW_DONE:
        ui.updateTaskList(taskEngine.getCompletedTasks(), ScreenView.SCREEN_DONE);
        break;

      case SHOW_ALL:
        ui.updateTaskList(taskEngine.getAllTasks(), ScreenView.SCREEN_MAIN_ALL);
        break;

      case SHOW_SUMMARY:
        ui.updateTaskList(taskEngine.getOutstandingTasks(), ScreenView.SCREEN_SUMMARY);
        break;

      case SHOW_SEARCH_RESULTS:
        ui.passSearchStringToSearchScreen(searchString);
        ui.updateTaskList(
            taskEngine.search(searchTerm, searchStartDate, searchEndDate, searchShowDone),
            ScreenView.SCREEN_SEARCH);
        break;
    }
  }
Example #5
0
  // Exit routine used by exit command, close button and system tray
  private boolean exit() {
    if (hasStartupError) {
      hideAndTerminate();
    }

    if (!taskEngine.hasPreviousOperation()) {
      hideAndTerminate(); // No write operations; safe to exit
    }

    boolean success = taskEngine.save(); // Try to write state to file
    if (success) {
      hideAndTerminate(); // Write success; safe to exit
    }

    // Write failure; create confirmation dialog to warn user
    boolean exitAnyway =
        ui.createErrorDialogWithConfirmation(
            ERROR_EXIT_HEADER, ERROR_EXIT_MESSAGE, ERROR_EXIT_BUTTON_LABEL);
    if (exitAnyway) {
      hideAndTerminate(); // User chose to exit anyway despite save failure
    }

    return false; // User pressed cancel
  }
Example #6
0
 // Simulate faster exit by hiding window first
 private void hideAndTerminate() {
   ui.hide();
   System.exit(0);
 }
Example #7
0
  // Process key press events
  private EventHandler<KeyEvent> createKeyPressHandler() {
    return (keyEvent) -> {

      // Remove initial splash overlay
      ui.hideSplashOverlay();

      switch (keyEvent.getCode()) {

          // Main command execution flow
        case ENTER:
          {

            // Whitespace command
            if (ui.getInput().trim().isEmpty()) {
              ui.clearInput();
              ui.hideHelpOverlay();
              return;
            }

            // Hide help unless it's a help or exit command
            if (!lastPreviewedCommand.getType().equals(CommandType.HELP)
                && !lastPreviewedCommand.getType().equals(CommandType.EXIT)) {
              ui.hideHelpOverlay();
            }

            // All the work happens here!
            String feedback = executeLastPreviewedCommand();

            // Clear input box and display feedback
            // ClearInput must come before setStatus as user input listener
            // resets status when input is cleared
            ui.clearInput();
            ui.setExecuteStatus(feedback);

            return;
          }

          // Edit description autocompletion
        case TAB:
          {
            if (!hasLastPreviewedCommand()) {
              return;
            }

            Command command = lastPreviewedCommand;
            if (command.getType() != CommandType.EDIT_PARTIAL) {
              return;
            }

            int lineNumber = lastPreviewedCommand.getLineNumber();

            if (!isValidLineNumber(lineNumber)) {
              return;
            }

            ui.setInput(
                ui.getInput().trim() + " " + getTaskFromLineNumber(lineNumber).getDescription());
            return;
          }

          // Scrolling
        case UP:
          {
            ui.scrollUpScreen();
            return;
          }
        case DOWN:
          {
            ui.scrollDownScreen();
            return;
          }

          // Show help
        case F1:
          {
            ui.showHelpOverlay();
            if (ui.getInput().isEmpty()) {
              ui.setPreviewStatus(FeedbackHelp.HELP);
            }
            return;
          }

          // Activate next help page using left/right keys
          // (but only when the input box is empty)
        case LEFT:
        case RIGHT:
          {
            if (ui.getInput().isEmpty()) {
              ui.nextHelpPage();
            }
            return;
          }

          // Hide help
        case ESCAPE:
          {
            ui.hideHelpOverlay();
            if (ui.getInput().trim().isEmpty()) {
              ui.setPreviewStatus(FEEDBACK_READY);
            }
            return;
          }

        default:
          break;
      }
    };
  }
Example #8
0
 private void initUiTaskList() {
   ui.initialUpdateTaskList(taskEngine.getOutstandingTasks());
   updateView(ViewType.SHOW_SUMMARY);
 }