From 66880c20c9b05390ba339841a505d277e920597a Mon Sep 17 00:00:00 2001 From: Dennis Hilhorst Date: Mon, 20 Oct 2025 16:15:33 +0200 Subject: [PATCH] improve SaR snapshot UI behavior --- .../ui/snapshot/SnapshotController.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java index 21ef50f53d..60c233b3cd 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java @@ -757,13 +757,18 @@ public void takeSnapshot() { */ private void resetMetaData() { tabTitleProperty.setValue(Messages.unnamedSnapshot); - snapshotNameProperty.setValue(null); - snapshotCommentProperty.setValue(null); createdDateTextProperty.setValue(null); lastModifiedDateTextProperty.setValue(null); createdByTextProperty.setValue(null); } + public static Throwable getRootCause(Throwable throwable) { + if (throwable.getCause() != null) + return getRootCause(throwable.getCause()); + + return throwable; + } + @SuppressWarnings("unused") public void saveSnapshot(ActionEvent actionEvent) { disabledUi.set(true); @@ -795,7 +800,8 @@ public void saveSnapshot(ActionEvent actionEvent) { Platform.runLater(() -> { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle(Messages.errorActionFailed); - alert.setContentText(e.getMessage()); + // get root cause of exception because the nested exception names are not very friendly + alert.setContentText(getRootCause(e).getMessage()); alert.setHeaderText(Messages.saveSnapshotErrorContent); DialogHelper.positionDialog(alert, borderPane, -150, -150); alert.showAndWait(); @@ -1101,7 +1107,14 @@ private void takeSnapshotReadPVs(Consumer> consumer) { }); showTakeSnapshotResult(snapshotItems); Snapshot snapshot = new Snapshot(); - snapshot.setSnapshotNode(Node.builder().nodeType(NodeType.SNAPSHOT).build()); + snapshot.setSnapshotNode( + Node.builder() + .nodeType(NodeType.SNAPSHOT) + // set name and description to preserve the name / comment fields + .name(snapshotNameProperty.getValue()) + .description(snapshotCommentProperty.getValue()) + .build() + ); SnapshotData snapshotData = new SnapshotData(); snapshotData.setSnapshotItems(snapshotItems); snapshot.setSnapshotData(snapshotData);