From 2d18a934f6ba2e09c24e3e352a5eba599bb39c2b Mon Sep 17 00:00:00 2001 From: shroffk Date: Tue, 25 Nov 2025 11:11:03 -0500 Subject: [PATCH 1/2] preserve the selection for the alarm tree --- .../alarm/ui/tree/AlarmTreeView.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java index 83a3efd6aa..f8f8e64086 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java @@ -19,10 +19,12 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.stream.Collectors; +import javafx.collections.FXCollections; import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.client.AlarmClientLeaf; @@ -127,6 +129,9 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener /** Is change indicator shown, and future been submitted to clear it? */ private final AtomicReference> ongoing_change = new AtomicReference<>(); + /** A flag used to help reserve selections during updates, it flags if any of the selections are to be updated */ + private final AtomicBoolean selectionChanged = new AtomicBoolean(false); + /** Clear the change indicator */ private final Runnable clear_change_indicator = () -> Platform.runLater(() -> @@ -529,6 +534,11 @@ private void performUpdates() items_to_update.clear(); } + // Remember selection + final ObservableList>> updatedSelectedItems = + FXCollections.observableArrayList(tree_view.getSelectionModel().getSelectedItems()); + selectionChanged.set(false); + // How to update alarm tree cells when data changed? // `setValue()` with a truly new value (not 'equal') should suffice, // but there are two problems: @@ -552,6 +562,11 @@ private void performUpdates() // Create new TreeItem for that value final AlarmTreeItem value = view_item.getValue(); final TreeItem> update = new TreeItem<>(value); + if (updatedSelectedItems.contains(view_item)) { + updatedSelectedItems.remove(view_item); + updatedSelectedItems.add(update); + selectionChanged.set(true); + } // Move child links to new item final ArrayList>> children = new ArrayList<>(view_item.getChildren()); view_item.getChildren().clear(); @@ -561,6 +576,12 @@ private void performUpdates() path2view.put(value.getPathName(), update); parent.getChildren().set(index, update); } + // Restore selection + if (selectionChanged.get()) { + tree_view.getSelectionModel().clearSelection(); + updatedSelectedItems.forEach(item -> tree_view.getSelectionModel().select(item)); + selectionChanged.set(false); + } } /** Context menu, details depend on selected items */ From 4356591578ad6ac22bbd60fd0664233f05ca862d Mon Sep 17 00:00:00 2001 From: shroffk Date: Tue, 25 Nov 2025 11:20:11 -0500 Subject: [PATCH 2/2] remove the flag since it is inconsistent --- .../applications/alarm/ui/tree/AlarmTreeView.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java index f8f8e64086..179b971ce0 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java @@ -129,9 +129,6 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener /** Is change indicator shown, and future been submitted to clear it? */ private final AtomicReference> ongoing_change = new AtomicReference<>(); - /** A flag used to help reserve selections during updates, it flags if any of the selections are to be updated */ - private final AtomicBoolean selectionChanged = new AtomicBoolean(false); - /** Clear the change indicator */ private final Runnable clear_change_indicator = () -> Platform.runLater(() -> @@ -537,7 +534,6 @@ private void performUpdates() // Remember selection final ObservableList>> updatedSelectedItems = FXCollections.observableArrayList(tree_view.getSelectionModel().getSelectedItems()); - selectionChanged.set(false); // How to update alarm tree cells when data changed? // `setValue()` with a truly new value (not 'equal') should suffice, @@ -565,7 +561,6 @@ private void performUpdates() if (updatedSelectedItems.contains(view_item)) { updatedSelectedItems.remove(view_item); updatedSelectedItems.add(update); - selectionChanged.set(true); } // Move child links to new item final ArrayList>> children = new ArrayList<>(view_item.getChildren()); @@ -577,11 +572,8 @@ private void performUpdates() parent.getChildren().set(index, update); } // Restore selection - if (selectionChanged.get()) { - tree_view.getSelectionModel().clearSelection(); - updatedSelectedItems.forEach(item -> tree_view.getSelectionModel().select(item)); - selectionChanged.set(false); - } + tree_view.getSelectionModel().clearSelection(); + updatedSelectedItems.forEach(item -> tree_view.getSelectionModel().select(item)); } /** Context menu, details depend on selected items */