Skip to content

Commit 0c7e77d

Browse files
committed
Updates to save&restore snapshot UI: indicate outcome of actions in table
1 parent e7cb9f2 commit 0c7e77d

17 files changed

Lines changed: 301 additions & 239 deletions

File tree

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
@SuppressWarnings("unused")
2323
public class Messages {
2424

25-
public static String actionFailedDisconnectedPV;
26-
public static String actionFailedInteractionFailed;
2725
public static String actionOpenFilterDescription;
2826
public static String actionOpenNodeDescription;
2927
public static String alertContinue;

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/RestoreUtil.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ private static void showAndLogRestore(Node node, List<RestoreResult> restoreResu
9292
StringBuilder stringBuilder = new StringBuilder();
9393
stringBuilder.append(restoreResultList.stream()
9494
.map(r -> r.getSnapshotItem().getConfigPv().getPvName()).collect(Collectors.joining(System.lineSeparator())));
95-
Platform.runLater(() -> {
96-
Alert alert = new Alert(Alert.AlertType.ERROR);
97-
alert.setHeaderText(Messages.restoreFailedPVs);
98-
alert.setContentText(stringBuilder.toString());
99-
alert.show();
100-
});
10195
Logger.getLogger(RestoreUtil.class.getName()).log(Level.WARNING,
10296
"Not all PVs could be restored for \"{0}\": . " + Messages.restoreFailedPVs + "\n{1}",
10397
new Object[]{node.getName(), stringBuilder.toString()});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (C) 2025 European Spallation Source ERIC.
3+
*/
4+
5+
package org.phoebus.applications.saveandrestore.ui.snapshot;
6+
7+
/**
8+
* UI helper enum indicating the result of a take snapshot or restore action.
9+
*/
10+
public enum ActionResult {
11+
PENDING, // User has not taken any action yet, or action in progress
12+
OK,
13+
FAILED
14+
}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/BaseSnapshotTableViewController.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.phoebus.applications.saveandrestore.ui.snapshot;
2121

22+
import javafx.application.Platform;
2223
import javafx.beans.property.ObjectProperty;
2324
import javafx.beans.property.ReadOnlyObjectWrapper;
2425
import javafx.collections.ObservableList;
@@ -44,6 +45,7 @@
4445
import org.phoebus.applications.saveandrestore.model.Snapshot;
4546
import org.phoebus.applications.saveandrestore.ui.VTypePair;
4647
import org.phoebus.core.types.TimeStampedProcessVariable;
48+
import org.phoebus.core.vtypes.VDisconnectedData;
4749
import org.phoebus.framework.jobs.JobManager;
4850
import org.phoebus.framework.selection.SelectionService;
4951
import org.phoebus.ui.application.ContextMenuHelper;
@@ -253,9 +255,6 @@ protected void setSelectionColumnVisible(boolean visible) {
253255
selectedColumn.visibleProperty().set(visible);
254256
}
255257

256-
protected String getPVKey(String pvName, boolean isReadonly) {
257-
return pvName + "_" + isReadonly;
258-
}
259258

260259
protected void showSnapshotInTable(Snapshot snapshot) {
261260
if (snapshots.isEmpty()) {
@@ -273,10 +272,17 @@ protected void showSnapshotInTable(Snapshot snapshot) {
273272
tableEntry.setSnapshotValue(entry.getValue(), 0);
274273
tableEntry.setStoredReadbackValue(entry.getReadbackValue(), 0);
275274
tableEntry.setReadbackValue(entry.getReadbackValue());
276-
String key = getPVKey(name, entry.getConfigPv().isReadOnly());
275+
if (entry.getValue() == null || entry.getValue().equals(VDisconnectedData.INSTANCE)) {
276+
tableEntry.setActionResult(ActionResult.FAILED);
277+
} else if (entry.getConfigPv().getReadbackPvName() != null &&
278+
(entry.getReadbackValue() == null || entry.getReadbackValue().equals(VDisconnectedData.INSTANCE))) {
279+
tableEntry.setActionResult(ActionResult.FAILED);
280+
} else {
281+
tableEntry.setActionResult(ActionResult.OK);
282+
}
277283
tableEntry.readbackNameProperty().set(entry.getConfigPv().getReadbackPvName());
278284
tableEntry.readOnlyProperty().set(entry.getConfigPv().isReadOnly());
279-
tableEntryItems.put(key, tableEntry);
285+
tableEntryItems.put(name, tableEntry);
280286
});
281287

282288
updateTable(null);
@@ -291,35 +297,37 @@ protected void showSnapshotInTable(Snapshot snapshot) {
291297
public void updateTable(List<TableEntry> entries) {
292298
final ObservableList<TableEntry> items = snapshotTableView.getItems();
293299
final boolean notHide = !snapshotController.isHideEqualItems();
294-
items.clear();
295-
tableEntryItems.forEach((key, value) -> {
296-
// there is no harm if this is executed more than once, because only one line is allowed for these
297-
// two properties (see SingleListenerBooleanProperty for more details)
298-
value.liveStoredEqualProperty().addListener((a, o, n) -> {
299-
if (snapshotController.isHideEqualItems()) {
300-
if (n) {
301-
snapshotTableView.getItems().remove(value);
302-
} else {
303-
snapshotTableView.getItems().add(value);
300+
Platform.runLater(() -> {
301+
items.clear();
302+
tableEntryItems.forEach((key, value) -> {
303+
// there is no harm if this is executed more than once, because only one line is allowed for these
304+
// two properties (see SingleListenerBooleanProperty for more details)
305+
value.liveStoredEqualProperty().addListener((a, o, n) -> {
306+
if (snapshotController.isHideEqualItems()) {
307+
if (n) {
308+
snapshotTableView.getItems().remove(value);
309+
} else {
310+
snapshotTableView.getItems().add(value);
311+
}
304312
}
313+
});
314+
if (notHide || !value.liveStoredEqualProperty().get()) {
315+
items.add(value);
305316
}
306317
});
307-
if (notHide || !value.liveStoredEqualProperty().get()) {
308-
items.add(value);
309-
}
310318
});
311319
}
312320

313321
protected void connectPVs() {
314322
JobManager.schedule("Connect PVs", monitor -> {
315323
tableEntryItems.values().forEach(e -> {
316-
SaveAndRestorePV pv = pvs.get(getPVKey(e.getConfigPv().getPvName(), e.getConfigPv().isReadOnly()));
324+
SaveAndRestorePV pv = pvs.get(e.getConfigPv().getPvName());
317325
if (pv == null) {
318-
pvs.put(getPVKey(e.getConfigPv().getPvName(), e.getConfigPv().isReadOnly()), new SaveAndRestorePV(e));
326+
pvs.put(e.getConfigPv().getPvName(), new SaveAndRestorePV(e));
319327
} else {
320328
pv.setSnapshotTableEntry(e);
321329
}
322330
});
323-
});
331+
});
324332
}
325333
}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.phoebus.applications.saveandrestore.model.ConfigurationData;
3030
import org.phoebus.applications.saveandrestore.model.Node;
3131
import org.phoebus.applications.saveandrestore.model.NodeType;
32-
import org.phoebus.applications.saveandrestore.model.RestoreResult;
3332
import org.phoebus.applications.saveandrestore.model.Snapshot;
3433
import org.phoebus.applications.saveandrestore.model.SnapshotData;
3534
import org.phoebus.applications.saveandrestore.model.SnapshotItem;
@@ -42,7 +41,6 @@
4241
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreService;
4342
import org.phoebus.applications.saveandrestore.ui.SnapshotMode;
4443
import org.phoebus.applications.saveandrestore.ui.WebSocketMessageHandler;
45-
import org.phoebus.core.vtypes.VDisconnectedData;
4644
import org.phoebus.framework.jobs.JobManager;
4745
import org.phoebus.saveandrestore.util.VNoData;
4846
import org.phoebus.security.tokens.ScopedAuthenticationToken;
@@ -168,7 +166,6 @@ public void initializeViewForNewSnapshot(Node configurationNode) {
168166
snapshot.setSnapshotData(snapshotData);
169167
snapshotProperty.set(snapshot);
170168
setTabImage(snapshot.getSnapshotNode());
171-
//Platform.runLater(() -> snapshotTableViewController.showSnapshotInTable(snapshot));
172169
});
173170
}
174171

@@ -181,23 +178,12 @@ public void takeSnapshot() {
181178
disabledUi.set(false);
182179
if (snapshot.isPresent()) {
183180
snapshotProperty.set(snapshot.get());
184-
snapshotTableViewController.showSnapshotInTable(snapshot.get());
185-
if (snapshot.get().getSnapshotData().getSnapshotItems().stream()
186-
.filter(i -> i.getValue().equals(VDisconnectedData.INSTANCE) ||
187-
(i.getConfigPv().getReadbackPvName() != null &&
188-
i.getReadbackValue().equals(VDisconnectedData.INSTANCE))).findFirst().isPresent()) {
189-
snapshotControlsViewController.setActionResult(SnapshotControlsViewController.ActionResult.TAKE_SNAPSHOT_DISCONNECTED_PV,
190-
snapshot.get().getSnapshotData().getSnapshotItems());
191-
} else {
192-
snapshotControlsViewController.setActionResult(SnapshotControlsViewController.ActionResult.TAKE_SNAPSHOT_OK);
193-
}
194181
}
195182
});
196183
}
197184

198185
@SuppressWarnings("unused")
199186
public void saveSnapshot(ActionEvent actionEvent) {
200-
201187
disabledUi.set(true);
202188
JobManager.schedule("Save Snapshot", monitor -> {
203189
List<SnapshotItem> snapshotItems = snapshotProperty.get().getSnapshotData().getSnapshotItems();
@@ -396,23 +382,17 @@ public void loadSnapshot(Node snapshotNode) {
396382
snapshotControlsViewController.setSnapshotNode(snapshotNode);
397383
snapshotControlsViewController.setSnapshotRestorableProperty(true);
398384
snapshotTableViewController.setSelectionColumnVisible(true);
399-
385+
snapshotTableViewController.setActionResult(ActionResult.PENDING);
400386
loadSnapshotInternal(snapshotNode);
401387
}
402388

403389
public void restore() {
390+
disabledUi.setValue(true);
404391
snapshotTableViewController.restore(snapshotControlsViewController.getRestoreMode(), snapshotProperty.get(), restoreResultList -> {
392+
disabledUi.setValue(false);
405393
if (snapshotControlsViewController.logAction()) {
406394
eventReceivers.forEach(r -> r.snapshotRestored(snapshotProperty.get().getSnapshotNode(), restoreResultList, this::showLoggingError));
407395
}
408-
if (restoreResultList != null && !restoreResultList.isEmpty()) {
409-
List<SnapshotItem> snapshotItems =
410-
restoreResultList.stream().map(RestoreResult::getSnapshotItem).toList();
411-
snapshotControlsViewController.setActionResult(SnapshotControlsViewController.ActionResult.RESTORE_FAILED, snapshotItems);
412-
} else {
413-
snapshotControlsViewController.setActionResult(SnapshotControlsViewController.ActionResult.RESTORE_OK);
414-
LOGGER.log(Level.INFO, "Successfully restored snapshot \"" + snapshotProperty.get().getSnapshotNode().getName() + "\"");
415-
}
416396
});
417397
}
418398

0 commit comments

Comments
 (0)