Skip to content

Commit

Permalink
CSSTUDIO-1987 If a save operation fails, do not process the remaining…
Browse files Browse the repository at this point in the history
… save actions.
  • Loading branch information
abrahamwolk committed Aug 9, 2023
1 parent 680f578 commit 80f2e25
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,12 @@ public static boolean confirmationDialogWhenUnsavedChangesExist(List<Stage> stag
monitor);
}

private enum SaveStatus {
SUCCESS,
FAILURE,
NOTHING
};

public static boolean confirmationDialogWhenUnsavedChangesExist(SortedMap<String, SortedMap<String, List<DockItemWithInput>>> windowNrToApplicationNameToDockItemsWithInput,
String question,
String closeActionName,
Expand Down Expand Up @@ -1440,7 +1446,7 @@ public static boolean confirmationDialogWhenUnsavedChangesExist(SortedMap<String
exitPhoebusWithoutSavingUnsavedChanges_button.setTooltip(new Tooltip(exitPhoebusWithoutSavingUnsavedChanges_button.getText()));
List<Consumer<Boolean>> setCheckBoxStatusActions = new LinkedList<>();
List<Supplier<Boolean>> getCheckBoxStatusActions = new LinkedList<>();
List<Supplier<Boolean>> saveActions = new LinkedList<>();
List<Supplier<SaveStatus>> saveActions = new LinkedList<>();

Runnable enableAndDisableButtons = () -> {
if (getCheckBoxStatusActions.stream().anyMatch(getCheckBoxStatus -> getCheckBoxStatus.get())) {
Expand Down Expand Up @@ -1501,7 +1507,7 @@ public static boolean confirmationDialogWhenUnsavedChangesExist(SortedMap<String

hBox.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEvent -> checkBox.setSelected(!checkBox.isSelected())); // Enable toggling checkbox by clicking on its label.

Supplier<Boolean> saveIfCheckboxEnabled = () -> {
Supplier<SaveStatus> saveIfCheckboxEnabled = () -> {
if (checkBox.isSelected()) {

Text saving = new Text("[" + Messages.UnsavedChanges_saving + "]");
Expand All @@ -1520,7 +1526,7 @@ public static boolean confirmationDialogWhenUnsavedChangesExist(SortedMap<String
saved.setFill(Color.GREEN);
saved.setStyle("-fx-font-weight: bold;");
hBox.getChildren().set(0, saved);
return true;
return SaveStatus.SUCCESS;
}
else {
Text savingFailed_text = new Text("[" + Messages.UnsavedChanges_savingFailed + "]");
Expand All @@ -1530,11 +1536,11 @@ public static boolean confirmationDialogWhenUnsavedChangesExist(SortedMap<String
HBox savingFailed = new HBox(checkBox, savingFailed_text);
savingFailed.setSpacing(6);
hBox.getChildren().set(0, savingFailed);
return false;
return SaveStatus.FAILURE;
}
}
else {
return false;
return SaveStatus.NOTHING;
}
};
saveActions.add(saveIfCheckboxEnabled);
Expand Down Expand Up @@ -1569,12 +1575,16 @@ public static boolean confirmationDialogWhenUnsavedChangesExist(SortedMap<String
saveSelectedItems_button.addEventFilter(ActionEvent.ACTION, event -> {
event.consume();

List<Supplier<Boolean>> saveActionsThatHaveBeenCompleted = new LinkedList<>();
List<Supplier<SaveStatus>> saveActionsThatHaveBeenCompleted = new LinkedList<>();
for (var saveAction : saveActions) {
boolean result = saveAction.get();
if (result) {
SaveStatus result = saveAction.get();
if (result == SaveStatus.SUCCESS) {
saveActionsThatHaveBeenCompleted.add(saveAction);
}
else if (result == SaveStatus.FAILURE) {
break;
}
// If result == SaveStatus.NOTHING, continue.
}

for (var saveActionThatHasBeenCompleted : saveActionsThatHaveBeenCompleted) {
Expand Down

0 comments on commit 80f2e25

Please sign in to comment.