Example #1
0
 /** Gets called when an action is undone */
 public void undoCallback() {
   if (undoBuffer.isPresent()) {
     TurboIssue issue = undoBuffer.get().getKey();
     Action<TurboIssue> action = undoBuffer.get().getValue();
     action
         .undo(issue)
         .thenApply(isSuccessful -> handleActionResult(issue, action, isSuccessful, true));
     undoBuffer = Optional.empty();
   }
 }
Example #2
0
 /**
  * Adds an action to the undo buffer.
  *
  * @param issue The TurboIssue to be acted on
  * @param action The Action that acts on the above TurboIssue
  */
 public void addAction(TurboIssue issue, Action<TurboIssue> action) {
   undoBuffer = Optional.of(new Pair<>(issue, action));
   action
       .act(issue)
       .thenApply(success -> handleActionResult(issue, action, success, false))
       .exceptionally((e) -> handleActionException(issue, action, e));
 }
Example #3
0
 /**
  * Shows an error dialog with a summary of the attempted action
  *
  * @param issue
  * @param action
  * @param errorMessage
  */
 private void showErrorDialog(TurboIssue issue, Action action, String errorMessage) {
   Platform.runLater(
       () ->
           DialogMessage.showErrorDialog(
               "Error Requesting GitHub",
               String.format(
                   "An error occurred while attempting to %s on:\n\n%s\n\n" + errorMessage,
                   action.getDescription(),
                   issue)));
 }
Example #4
0
 /**
  * Possibly shows a notification or an error dialog depending on {@code success} and {@code
  * isUndo}.
  *
  * @param issue the TurboIssue acted on
  * @param action the Action that acted on the issue
  * @param success whether the action was successful
  * @param isUndo whether action is an undo
  * @return {@code success}
  */
 private boolean handleActionResult(
     TurboIssue issue, Action<TurboIssue> action, Boolean success, boolean isUndo) {
   if (!success) {
     String errorMessage = "Please check if you have write permissions to " + issue.getRepoId();
     showErrorDialog(issue, action, errorMessage);
     return success;
   }
   if (!isUndo) {
     showNotification(issue.getId(), issue.getTitle(), action.getDescription());
     return success;
   }
   return success;
 }