From f8374a21298dcfb22b39e23a4744d2f0c9ba9d86 Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Tue, 17 Nov 2026 13:47:03 +0000 Subject: [PATCH 01/10] Add alarm tree copy/cut/paste --- .../alarm/client/AlarmClientLeaf.java | 12 ++- .../applications/alarm/ui/Messages.java | 5 ++ .../alarm/ui/tree/AlarmTreeView.java | 20 +++++ .../alarm/ui/tree/CopyItemAction.java | 28 ++++++ .../alarm/ui/tree/CutItemAction.java | 28 ++++++ .../alarm/ui/tree/DuplicatePVAction.java | 20 +---- .../alarm/ui/tree/PasteItemAction.java | 82 ++++++++++++++++++ .../alarm/ui/tree/RenameDialog.java | 63 ++++++++++++++ app/alarm/ui/src/main/resources/icons/cut.png | Bin 0 -> 510 bytes .../applications/alarm/ui/messages.properties | 5 ++ 10 files changed, 245 insertions(+), 18 deletions(-) create mode 100644 app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CopyItemAction.java create mode 100644 app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CutItemAction.java create mode 100644 app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java create mode 100644 app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java create mode 100644 app/alarm/ui/src/main/resources/icons/cut.png diff --git a/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientLeaf.java b/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientLeaf.java index 2c0260bfe9..ed50d91567 100644 --- a/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientLeaf.java +++ b/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientLeaf.java @@ -52,9 +52,9 @@ public AlarmClientLeaf(final String parent_path, final String name) * a detached copy is used to send the request. * @return {@link AlarmClientLeaf} with same configuration, but no parent */ - public AlarmClientLeaf createDetachedCopy() + public AlarmClientLeaf createDetachedCopy(final String newName) { - final AlarmClientLeaf pv = new AlarmClientLeaf(null, getName()); + final AlarmClientLeaf pv = new AlarmClientLeaf(null, newName); pv.setDescription(getDescription()); pv.setEnabled(getEnabled()); pv.setLatching(isLatching()); @@ -69,6 +69,14 @@ public AlarmClientLeaf createDetachedCopy() return pv; } + /** When requesting a configuration update, + * a detached copy is used to send the request. + * @return {@link AlarmClientLeaf} with same configuration, but no parent + */ + public AlarmClientLeaf createDetachedCopy() { + return createDetachedCopy(getName()); + } + /** @return Return description */ @Override public String getDescription() diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java index 1a8d67bb5e..f3fdbb4e28 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java @@ -43,9 +43,14 @@ public class Messages public static String headerConfirmDisableWithEnableDate; public static String headerConfirmEnable; public static String indefinitely; + public static String itemAlreadyExists; public static String MenuPath; public static String moveItemFailed; + public static String nameCannotBeEmpty; + public static String pasteItemFailed; public static String promptTitle; + public static String renameLabel; + public static String renameTitle; public static String removeComponentFailed; public static String renameItemFailed; public static String totalPVs; 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 f3d65c9801..8466095ffe 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 @@ -23,6 +23,8 @@ import java.util.logging.Level; import java.util.stream.Collectors; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; @@ -140,6 +142,9 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener items.remove(changing); }); + private final SimpleObjectProperty> clipboard = new SimpleObjectProperty<>(null); + private final SimpleBooleanProperty isClipboardCut = new SimpleBooleanProperty(false); + // Javadoc for TreeItem shows example for overriding isLeaf() and getChildren() // to dynamically create TreeItem as TreeView requests information. // @@ -440,6 +445,11 @@ public void itemRemoved(final AlarmTreeItem item) blockItemChanges(); // System.out.println(Thread.currentThread() + " Removed " + item.getPathName()); + // Clear clipboard if we are removing clipboard's item + if (clipboard.get() != null && clipboard.get().equals(item)) { + clipboard.set(null); + } + // Remove item and all sub-items from model2ui final TreeItem> view_item = removeViewItems(item); if (view_item == null) @@ -604,6 +614,15 @@ else if (selection.size() == 1) menu_items.add(new ConfigureComponentAction(tree_view, model, item)); menu_items.add(new SeparatorMenuItem()); + menu_items.add(new CopyItemAction(tree_view, clipboard, isClipboardCut, item)); + menu_items.add(new CutItemAction(tree_view, clipboard, isClipboardCut, item)); + + final PasteItemAction pasteItem = new PasteItemAction( + tree_view, model, item instanceof AlarmClientNode ? item : item.getParent(), clipboard, isClipboardCut.get() + ); + pasteItem.setDisable(clipboard.get() == null); + menu_items.add(pasteItem); + if (item instanceof AlarmClientNode) menu_items.add(new AddComponentAction(tree_view, model, item)); @@ -614,6 +633,7 @@ else if (selection.size() == 1) menu_items.add(new MoveTreeItemAction(tree_view, model, item)); } + if (selection.size() >= 1) { menu_items.add(new EnableComponentAction(tree_view, model, selection)); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CopyItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CopyItemAction.java new file mode 100644 index 0000000000..7c8a9ff00e --- /dev/null +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CopyItemAction.java @@ -0,0 +1,28 @@ +package org.phoebus.applications.alarm.ui.tree; + +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.scene.Node; +import javafx.scene.control.MenuItem; +import org.phoebus.applications.alarm.AlarmSystem; +import org.phoebus.applications.alarm.model.AlarmTreeItem; +import org.phoebus.ui.javafx.ImageCache; + + +@SuppressWarnings("nls") +public class CopyItemAction extends MenuItem +{ + /** @param node Node to position dialog + * @param clipboard Property containing the clipboard + * @param isCut Property indicating whether the clipboard item should be removed when pasted + * @param item Parent item in alarm tree + */ + public CopyItemAction(final Node node, final SimpleObjectProperty> clipboard, final SimpleBooleanProperty isCut, final AlarmTreeItem item) + { + super("Copy Item", ImageCache.getImageView(AlarmSystem.class, "/icons/copy.png")); + setOnAction(event -> { + clipboard.set(item); + isCut.set(false); + }); + } +} diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CutItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CutItemAction.java new file mode 100644 index 0000000000..4a7057f56a --- /dev/null +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/CutItemAction.java @@ -0,0 +1,28 @@ +package org.phoebus.applications.alarm.ui.tree; + +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.scene.Node; +import javafx.scene.control.MenuItem; +import org.phoebus.applications.alarm.AlarmSystem; +import org.phoebus.applications.alarm.model.AlarmTreeItem; +import org.phoebus.ui.javafx.ImageCache; + + +@SuppressWarnings("nls") +public class CutItemAction extends MenuItem +{ + /** @param node Node to position dialog + * @param clipboard Property containing the clipboard + * @param isCut Property indicating whether the clipboard item should be removed when pasted + * @param item Parent item in alarm tree + */ + public CutItemAction(final Node node, final SimpleObjectProperty> clipboard, final SimpleBooleanProperty isCut, final AlarmTreeItem item) + { + super("Cut Item", ImageCache.getImageView(AlarmSystem.class, "/icons/cut.png")); + setOnAction(event -> { + clipboard.set(item); + isCut.set(true); + }); + } +} diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java index d93214df08..302aeb37a3 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java @@ -40,27 +40,15 @@ public DuplicatePVAction(final Node node, final AlarmClient model, final AlarmCl setOnAction(event -> { // Prompt for new PV name - final TextInputDialog dialog = new TextInputDialog(); - dialog.setTitle(getText()); - dialog.setHeaderText("Enter name for duplicate of\n" + original.getPathName()); + final RenameDialog dialog = new RenameDialog(original.getParent(), original.getName()); + dialog.setHeaderText("Enter name for duplicate"); DialogHelper.positionDialog(dialog, node, -100, -50); final String new_name = dialog.showAndWait().orElse(null); - if (new_name == null || new_name.isEmpty()) + if (new_name == null) return; // Create near copy of original PV, but with new name - final AlarmClientLeaf template = new AlarmClientLeaf(null, new_name); - template.setDescription(original.getDescription()); - template.setEnabled(original.isEnabled()); - template.setLatching(original.isLatching()); - template.setAnnunciating(original.isAnnunciating()); - template.setDelay(original.getDelay()); - template.setCount(original.getCount()); - template.setFilter(original.getFilter()); - template.setGuidance(original.getGuidance()); - template.setDisplays(original.getDisplays()); - template.setCommands(original.getCommands()); - template.setActions(original.getActions()); + final AlarmClientLeaf template = original.createDetachedCopy(new_name); // Request adding new PV JobManager.schedule(getText(), monitor -> { diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java new file mode 100644 index 0000000000..7ee386f159 --- /dev/null +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -0,0 +1,82 @@ +package org.phoebus.applications.alarm.ui.tree; + +import javafx.beans.property.SimpleObjectProperty; +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.Label; +import javafx.scene.control.MenuItem; +import javafx.scene.control.TextField; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import org.phoebus.applications.alarm.AlarmSystem; +import org.phoebus.applications.alarm.client.AlarmClient; +import org.phoebus.applications.alarm.model.AlarmTreeItem; +import org.phoebus.applications.alarm.model.AlarmTreePath; +import org.phoebus.applications.alarm.ui.Messages; +import org.phoebus.framework.jobs.JobManager; +import org.phoebus.ui.dialog.DialogHelper; +import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; +import org.phoebus.ui.javafx.ImageCache; + +import java.util.Optional; + + +@SuppressWarnings("nls") +public class PasteItemAction extends MenuItem +{ + + /** @param node Node to position dialog + * @param model {@link AlarmClient} + * @param parent Parent to paste the item into + * @param clipboard Property containing the clipboard + * @param isCut Property indicating whether the clipboard item should be removed when pasted + */ + public PasteItemAction( + final Node node, + final AlarmClient model, + final AlarmTreeItem parent, + final SimpleObjectProperty> clipboard, + final boolean isCut) + { + super("Paste Item", ImageCache.getImageView(AlarmSystem.class, "/icons/paste.png")); + + setOnAction(event -> { + final AlarmTreeItem item = clipboard.get(); + + String newName = item.getName(); + if (parent.getChildren().stream().anyMatch(child -> child.getName().equals(item.getName()))) { + // Item already exists in the parent node we're copying to; prompt for rename + final RenameDialog dialog = new RenameDialog(parent, item.getName()); + dialog.setHeaderText("'" + parent.getName() + "' already has an item '" + item.getName() + "'"); + DialogHelper.positionDialog(dialog, node, -100, -50); + final Optional name = dialog.showAndWait(); + if (name.isPresent()) { + newName = name.get(); + } else { + return; + } + } + + final String finalNewName = newName; // lambda variables must be final + JobManager.schedule("Paste alarm tree item", _ -> { + try { + final String newPath = AlarmTreePath.makePath(parent.getPathName(), finalNewName); + // Move the item. + model.sendItemConfigurationUpdate(newPath, item); + // Move the item's children. + AlarmTreeHelper.rebuildTree(model, item, newPath); + if (isCut) { + // Delete the old item. This deletes the old item's children as well. + model.removeComponent(item); + } + } catch (final Exception ex) { + ExceptionDetailsErrorDialog.openError(Messages.error, Messages.pasteItemFailed, ex); + } + }); + }); + } +} diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java new file mode 100644 index 0000000000..c883c22fa7 --- /dev/null +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java @@ -0,0 +1,63 @@ +package org.phoebus.applications.alarm.ui.tree; + +import javafx.geometry.Pos; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import org.phoebus.applications.alarm.model.AlarmTreeItem; +import org.phoebus.applications.alarm.ui.Messages; + + +public class RenameDialog extends Dialog { + + public RenameDialog(final AlarmTreeItem parent, final String oldName) { + super(); + + setTitle(Messages.renameTitle); + + final Label renameLabel = new Label(Messages.renameLabel); + + final TextField input = new TextField(); + input.setText(oldName); + input.setPrefWidth(600.0); + HBox.setHgrow(input, Priority.ALWAYS); + + final HBox inputBox = new HBox(renameLabel, input); + inputBox.setAlignment(Pos.CENTER_LEFT); + + final Label errorLabel = new Label(Messages.itemAlreadyExists); + errorLabel.setTextFill(Color.RED); + errorLabel.setMaxWidth(Double.MAX_VALUE); + + // Show error and disable OK if the label matches any child + input.textProperty().addListener(_ -> { + if (input.getText().isEmpty()) { + errorLabel.setText(Messages.nameCannotBeEmpty); + errorLabel.setVisible(true); + errorLabel.setManaged(false); + getDialogPane().lookupButton(ButtonType.OK).setDisable(true); + return; + } + + final boolean childExists = parent.getChildren().stream().anyMatch(child -> input.getText().equals(child.getName())); + errorLabel.setText(Messages.itemAlreadyExists); + errorLabel.setVisible(childExists); + errorLabel.setManaged(childExists); + getDialogPane().lookupButton(ButtonType.OK).setDisable(childExists); + }); + + getDialogPane().setContent(new VBox(inputBox, errorLabel)); + getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); + + // Default to error hidden (as it can be confusing otherwise) and OK disabled + errorLabel.setVisible(false); + getDialogPane().lookupButton(ButtonType.OK).setDisable(true); + + setResultConverter(buttonType -> buttonType == ButtonType.OK ? input.getText() : null); + } +} diff --git a/app/alarm/ui/src/main/resources/icons/cut.png b/app/alarm/ui/src/main/resources/icons/cut.png new file mode 100644 index 0000000000000000000000000000000000000000..e2a59bc600e9e42bb790a32dd1913d81c858de69 GIT binary patch literal 510 zcmVqUg8O8>;uama^D`PJ6x2`qACcAiG{0`zpX8G6r(u~* z(?PC*8<0C`$NG#3Thl@8xUS9Nk!|a@2BkJ+MP@c{jLB{Ll2qLDFQu&SRd`m@rhtSB z1q`Q0c5Hm_(6AqDqDRAe1^23DUkV$i|1WQw^FO(``)^!9=eL05dNZ7X2}X4~gXy9u&AB)xuhcGaZMarqtR@rJTd(Gm-tyv2t#vKN0=&Rj5EAz?l^ zihR==MAFLop2y{P9wRQk9FPJA2#P1~)X3>t{j+%Tw%;XFcWf{2*(^d*0?M1T{cuw2 z%7zAD_{4W@>5l5$SWmR(G@xzK9UJe%(?k7Q3-{VJ`-wIH6e~at*BvU?Xn+FOqImgy zA#BFN{-!T Date: Tue, 17 Nov 2026 14:05:20 +0000 Subject: [PATCH 02/10] Small cleanup --- .../applications/alarm/ui/tree/AlarmTreeView.java | 2 +- .../applications/alarm/ui/tree/PasteItemAction.java | 9 --------- .../phoebus/applications/alarm/ui/tree/RenameDialog.java | 2 -- 3 files changed, 1 insertion(+), 12 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 c9101413dc..396c4a9099 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 @@ -456,7 +456,7 @@ public void itemRemoved(final AlarmTreeItem item) indicateChange(); // Clear clipboard if we are removing clipboard's item - if (clipboard.get() != null && clipboard.get().equals(item)) { + if (clipboard.get() != null && clipboard.get().getPathName().equals(item.getPathName())) { clipboard.set(null); } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index 7ee386f159..c301e82f06 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -1,17 +1,8 @@ package org.phoebus.applications.alarm.ui.tree; import javafx.beans.property.SimpleObjectProperty; -import javafx.geometry.Pos; import javafx.scene.Node; -import javafx.scene.control.ButtonType; -import javafx.scene.control.Dialog; -import javafx.scene.control.Label; import javafx.scene.control.MenuItem; -import javafx.scene.control.TextField; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Priority; -import javafx.scene.layout.VBox; -import javafx.scene.paint.Color; import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.model.AlarmTreeItem; diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java index c883c22fa7..569381a9f6 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java @@ -39,7 +39,6 @@ public RenameDialog(final AlarmTreeItem parent, final String oldName) { if (input.getText().isEmpty()) { errorLabel.setText(Messages.nameCannotBeEmpty); errorLabel.setVisible(true); - errorLabel.setManaged(false); getDialogPane().lookupButton(ButtonType.OK).setDisable(true); return; } @@ -47,7 +46,6 @@ public RenameDialog(final AlarmTreeItem parent, final String oldName) { final boolean childExists = parent.getChildren().stream().anyMatch(child -> input.getText().equals(child.getName())); errorLabel.setText(Messages.itemAlreadyExists); errorLabel.setVisible(childExists); - errorLabel.setManaged(childExists); getDialogPane().lookupButton(ButtonType.OK).setDisable(childExists); }); From 6212f775d7829e78dfe699f79ecec83d5abf9d9b Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Tue, 17 Nov 2026 14:54:27 +0000 Subject: [PATCH 03/10] Refine rename dialog and more cleanup --- .../alarm/ui/tree/AlarmTreeView.java | 6 ++-- .../alarm/ui/tree/MoveTreeItemAction.java | 4 --- .../alarm/ui/tree/PasteItemAction.java | 9 +++-- .../alarm/ui/tree/RenameDialog.java | 35 +++++++++++++------ 4 files changed, 34 insertions(+), 20 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 396c4a9099..5324c49ad6 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 @@ -621,11 +621,9 @@ else if (selection.size() == 1) menu_items.add(new CopyItemAction(tree_view, clipboard, isClipboardCut, item)); menu_items.add(new CutItemAction(tree_view, clipboard, isClipboardCut, item)); - final PasteItemAction pasteItem = new PasteItemAction( + menu_items.add(new PasteItemAction( tree_view, model, item instanceof AlarmClientNode ? item : item.getParent(), clipboard, isClipboardCut.get() - ); - pasteItem.setDisable(clipboard.get() == null); - menu_items.add(pasteItem); + )); if (item instanceof AlarmClientNode) menu_items.add(new AddComponentAction(tree_view, model, item)); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java index 93ac6d881b..e3ed3abd04 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java @@ -70,10 +70,6 @@ public MoveTreeItemAction(TreeView> node, return; } - // Tree view keeps the selection indices, which will point to wrong content - // after those items have been removed. - node.getSelectionModel().clearSelection(); - final String new_path = path; // On a background thread, send the item configuration updates for the item to be moved and all its children. JobManager.schedule(getText(), monitor -> diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index c301e82f06..75773fd9f0 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -5,6 +5,7 @@ import javafx.scene.control.MenuItem; import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; +import org.phoebus.applications.alarm.client.AlarmClientNode; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreePath; import org.phoebus.applications.alarm.ui.Messages; @@ -35,6 +36,8 @@ public PasteItemAction( { super("Paste Item", ImageCache.getImageView(AlarmSystem.class, "/icons/paste.png")); + setDisable(clipboard.get() == null); + setOnAction(event -> { final AlarmTreeItem item = clipboard.get(); @@ -59,9 +62,11 @@ public PasteItemAction( // Move the item. model.sendItemConfigurationUpdate(newPath, item); // Move the item's children. - AlarmTreeHelper.rebuildTree(model, item, newPath); + if (item instanceof AlarmClientNode) { + AlarmTreeHelper.rebuildTree(model, item, newPath); + } + // Delete the old item. This deletes the old item's children as well. if (isCut) { - // Delete the old item. This deletes the old item's children as well. model.removeComponent(item); } } catch (final Exception ex) { diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java index 569381a9f6..6586dc817d 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java @@ -12,9 +12,17 @@ import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.ui.Messages; +import java.util.function.Consumer; + public class RenameDialog extends Dialog { + /** + * + * @param parent The parent of the item being renamed - use to check for name clashes + * @param oldName The old name of the item being renamed + * @param allowOldName Whether the new name can be the same as the old name + */ public RenameDialog(final AlarmTreeItem parent, final String oldName) { super(); @@ -34,27 +42,34 @@ public RenameDialog(final AlarmTreeItem parent, final String oldName) { errorLabel.setTextFill(Color.RED); errorLabel.setMaxWidth(Double.MAX_VALUE); - // Show error and disable OK if the label matches any child + final Consumer updateError = newError -> { + errorLabel.setText(newError); + getDialogPane().lookupButton(ButtonType.OK).setDisable(newError != null); + }; + input.textProperty().addListener(_ -> { + // Disable OK if name has not changed + if (input.getText().equals(oldName)) { + updateError.accept(""); // disable OK but don't show an error + return; + } + + // Show error and disable OK if text is empty if (input.getText().isEmpty()) { - errorLabel.setText(Messages.nameCannotBeEmpty); - errorLabel.setVisible(true); - getDialogPane().lookupButton(ButtonType.OK).setDisable(true); + updateError.accept(Messages.nameCannotBeEmpty); return; } + // Show error and disable OK if the label matches any child final boolean childExists = parent.getChildren().stream().anyMatch(child -> input.getText().equals(child.getName())); - errorLabel.setText(Messages.itemAlreadyExists); - errorLabel.setVisible(childExists); - getDialogPane().lookupButton(ButtonType.OK).setDisable(childExists); + updateError.accept(childExists ? Messages.itemAlreadyExists : null); }); getDialogPane().setContent(new VBox(inputBox, errorLabel)); getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); - // Default to error hidden (as it can be confusing otherwise) and OK disabled - errorLabel.setVisible(false); - getDialogPane().lookupButton(ButtonType.OK).setDisable(true); + // Default to error hidden and OK disabled + updateError.accept(""); setResultConverter(buttonType -> buttonType == ButtonType.OK ? input.getText() : null); } From e8764d72467a7c3fd7969d94510ebcee15f88f50 Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Tue, 17 Nov 2026 15:45:30 +0000 Subject: [PATCH 04/10] More cleanup + consolidate moving into helper --- .../applications/alarm/ui/Messages.java | 7 +- .../alarm/ui/tree/AlarmTreeHelper.java | 43 +++++----- .../alarm/ui/tree/MoveTreeItemAction.java | 7 +- .../alarm/ui/tree/PasteItemAction.java | 17 ++-- .../alarm/ui/tree/RenameDialog.java | 4 +- .../alarm/ui/tree/RenameTreeItemAction.java | 86 ++++++------------- .../applications/alarm/ui/messages.properties | 8 +- 7 files changed, 64 insertions(+), 108 deletions(-) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java index f3fdbb4e28..5d23ecc068 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java @@ -36,6 +36,7 @@ public class Messages public static String displays; public static String enableAlarmFailed; public static String enableAlarms; + public static String enterNameForDuplicate; public static String guidance; public static String headerAlreadyDisabled; public static String headerAlreadyEnabled; @@ -47,10 +48,12 @@ public class Messages public static String MenuPath; public static String moveItemFailed; public static String nameCannotBeEmpty; + public static String pasteItem; public static String pasteItemFailed; public static String promptTitle; - public static String renameLabel; - public static String renameTitle; + public static String renameItem; + public static String renameDialogLabel; + public static String renameDialogTitle; public static String removeComponentFailed; public static String renameItemFailed; public static String totalPVs; diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java index 25e77114a6..1d3c2865a9 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java @@ -15,13 +15,11 @@ import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.client.AlarmClientLeaf; +import org.phoebus.applications.alarm.client.AlarmClientNode; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreePath; import org.phoebus.applications.alarm.ui.Messages; -import org.phoebus.ui.dialog.DialogHelper; -import javafx.scene.control.TextInputDialog; -import javafx.scene.control.TreeView; import org.phoebus.util.time.TimestampFormats; /** @author Evan Smith @@ -56,27 +54,26 @@ public static void rebuildTree(AlarmClient model, AlarmTreeItem parent, Strin } } - /** Prompt the screen with a dialog box. - * @param title Title string of the dialog box. - * @param header Header string of the dialog box. - * @param default_text Default text contents of dialog box. - * @param node Node where the dialog box will be located. - * @return String The entered string or null if the entry was empty. + /** Moves the provided item and all its children to a new path. + * + * @param model AlarmClient used to communicate to the AlarmServer + * @param item AlarmTreeItem to move + * @param path Path that the parents' children will now be located at. + * @param removeOldItem Whether the old item should be removed once it is moved */ - public static String prompt(String title, String header, final String default_text, final TreeView> node) - { - // Prompt for new name - final TextInputDialog prompt = new TextInputDialog(default_text); - DialogHelper.positionDialog(prompt, node, -200, -100); - prompt.setTitle(title); - prompt.setHeaderText(header); - prompt.getDialogPane().setPrefWidth(500); - prompt.setResizable(true); - final String input = prompt.showAndWait().orElse(""); - if (input.isEmpty()) - return null; - return input; - } + public static void moveItem(AlarmClient model, AlarmTreeItem item, String newPath, boolean removeOldItem) throws Exception + { + // Add the new item + model.sendItemConfigurationUpdate(newPath, item); + // ...and rebuild all its children + if (item instanceof AlarmClientNode) { + rebuildTree(model, item, newPath); + } + // Remove the item and all its children + if (removeOldItem) { + model.removeComponent(item); + } + } /** Validate the passed path string by checking if the path name is valid. * diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java index e3ed3abd04..725d1bbf1d 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java @@ -75,12 +75,7 @@ public MoveTreeItemAction(TreeView> node, JobManager.schedule(getText(), monitor -> { try { - // Move the item. - model.sendItemConfigurationUpdate(new_path, item); - // Move the item's children. - AlarmTreeHelper.rebuildTree(model, item, new_path); - // Delete the old item. This deletes the old item's children as well. - model.removeComponent(item); + AlarmTreeHelper.moveItem(model, item, new_path, true); } catch (Exception e) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.moveItemFailed, diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index 75773fd9f0..be6f11ae93 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -14,6 +14,7 @@ import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; +import java.text.MessageFormat; import java.util.Optional; @@ -34,18 +35,19 @@ public PasteItemAction( final SimpleObjectProperty> clipboard, final boolean isCut) { - super("Paste Item", ImageCache.getImageView(AlarmSystem.class, "/icons/paste.png")); + super(Messages.pasteItem, ImageCache.getImageView(AlarmSystem.class, "/icons/paste.png")); setDisable(clipboard.get() == null); setOnAction(event -> { final AlarmTreeItem item = clipboard.get(); + // Get new name, prompting user if any child of the new parent already has the same name String newName = item.getName(); if (parent.getChildren().stream().anyMatch(child -> child.getName().equals(item.getName()))) { // Item already exists in the parent node we're copying to; prompt for rename final RenameDialog dialog = new RenameDialog(parent, item.getName()); - dialog.setHeaderText("'" + parent.getName() + "' already has an item '" + item.getName() + "'"); + dialog.setHeaderText(MessageFormat.format(Messages.itemAlreadyExists, parent.getName(), item.getName())); DialogHelper.positionDialog(dialog, node, -100, -50); final Optional name = dialog.showAndWait(); if (name.isPresent()) { @@ -59,16 +61,7 @@ public PasteItemAction( JobManager.schedule("Paste alarm tree item", _ -> { try { final String newPath = AlarmTreePath.makePath(parent.getPathName(), finalNewName); - // Move the item. - model.sendItemConfigurationUpdate(newPath, item); - // Move the item's children. - if (item instanceof AlarmClientNode) { - AlarmTreeHelper.rebuildTree(model, item, newPath); - } - // Delete the old item. This deletes the old item's children as well. - if (isCut) { - model.removeComponent(item); - } + AlarmTreeHelper.moveItem(model, item, newPath, isCut); } catch (final Exception ex) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.pasteItemFailed, ex); } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java index 6586dc817d..dbb1b5e65b 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java @@ -26,9 +26,9 @@ public class RenameDialog extends Dialog { public RenameDialog(final AlarmTreeItem parent, final String oldName) { super(); - setTitle(Messages.renameTitle); + setTitle(Messages.renameDialogTitle); - final Label renameLabel = new Label(Messages.renameLabel); + final Label renameLabel = new Label(Messages.renameDialogLabel); final TextField input = new TextField(); input.setText(oldName); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java index 40e5f13191..1df7d11859 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java @@ -15,6 +15,7 @@ import org.phoebus.applications.alarm.model.BasicState; import org.phoebus.applications.alarm.ui.Messages; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.ui.dialog.DialogHelper; import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; @@ -36,68 +37,31 @@ public RenameTreeItemAction(final TreeView> node, final AlarmClient model, final AlarmTreeItem item) { - super("Rename Item", ImageCache.getImageView(AlarmSystem.class, "/icons/rename.png")); + super(Messages.renameItem, ImageCache.getImageView(AlarmSystem.class, "/icons/rename.png")); - if (item instanceof AlarmClientNode) - { - setOnAction(event -> - { - //Prompt for new name - final String new_name = AlarmTreeHelper.prompt(getText(), "Enter new name for Node", item.getName(), node); - if (null == new_name) - return; - // Tree view keeps the selection indices, which will point to wrong content - // after those items have been removed - if (node instanceof TreeView) - ((TreeView) node).getSelectionModel().clearSelection(); + setOnAction(event -> + { + // Prompt for new name + final RenameDialog dialog = new RenameDialog(item.getParent(), item.getName()); + dialog.setHeaderText(Messages.enterNameForDuplicate); + DialogHelper.positionDialog(dialog, node, -100, -50); + final String new_name = dialog.showAndWait().orElse(null); + if (new_name == null) + return; - // Delete old, rebuild child links, and add new name in background thread. - JobManager.schedule(getText(), monitor -> - { - final AlarmTreeItem parent = item.getParent(); - // Remove the item and all its children. - // Add the new item, and then rebuild all its children. - try { - final String new_path = AlarmTreePath.makePath(parent.getPathName(), new_name); - model.sendItemConfigurationUpdate(new_path, item); - AlarmTreeHelper.rebuildTree(model, item, new_path); - model.removeComponent(item); - } catch (Exception e) { - ExceptionDetailsErrorDialog.openError(Messages.error, - Messages.renameItemFailed, - e); - } - }); - }); - } - else - { - setOnAction(event -> - { - //Prompt for new name - final String new_name = AlarmTreeHelper.prompt(getText(), "Enter new name for PV", item.getName(), node); - if (null == new_name) - return; - // Tree view keeps the selection indices, which will point to wrong content - // after those items have been removed - if (node instanceof TreeView) - ((TreeView) node).getSelectionModel().clearSelection(); - - // Delete old, add new name in background thread - JobManager.schedule(getText(), monitor -> - { - final AlarmTreeItem parent = item.getParent(); - try { - final String new_path = AlarmTreePath.makePath(parent.getPathName(), new_name); - model.sendItemConfigurationUpdate(new_path, item); - model.removeComponent(item); - } catch (Exception e) { - ExceptionDetailsErrorDialog.openError(Messages.error, - Messages.renameItemFailed, - e); - } - }); - }); - } + // Delete old, rebuild child links, and add new name in background thread. + JobManager.schedule(getText(), monitor -> + { + final AlarmTreeItem parent = item.getParent(); + try { + final String new_path = AlarmTreePath.makePath(parent.getPathName(), new_name); + AlarmTreeHelper.moveItem(model, item, new_path, true); + } catch (final Exception ex) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.renameItemFailed, + ex); + } + }); + }); } } diff --git a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties index d79444b426..57a9140133 100644 --- a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties +++ b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties @@ -26,6 +26,7 @@ Annunciator=Annunciator alarmCount=Alarm Count [within delay]: alarmCountTooltip=Alarms are indicated when they occur this often within the delay alarmDelay=Alarm Delay [seconds]: +alreadyHasItem='{0}' already has an item '{1}' annunciate=Annunciate annunciateTooltip=Request audible alarm annunciation (using the description)? automatedActions=Automated Actions: @@ -54,6 +55,7 @@ displays=Displays: enabled=Enabled enablingFilter=Enabling Filter: enablingFilterTooltip=Optional expression for enabling the alarm +enterNameForDuplicate=Enter name for duplicate error=Error enableAlarmFailed=Failed to enable alarm enableAlarms=Enable Alarms @@ -74,14 +76,16 @@ moveItemFailed=Failed to move item nameCannotBeEmpty=Name cannot be empty option=Option partlyDisabled2=(Partly disabled) +pasteItem=Paste Item pasteItemFailed=Failed to paste component path=Path: promptTitle=Absolute Date is set to a point in time in the past relativeDateLabel=Relative Date: relativeDateTooltip=Select a predefined duration for disabling the alarm removeComponentFailed=Failed to remove component -renameTitle=Rename -renameLabel=Rename: +renameDialogTitle=Rename +renameDialogLabel=Rename: +renameItem=Rename item renameItemFailed=Failed to rename item timer=Timer title=Title From 8e95ffd3a2e1f27f0c1160957df7457db76223ab Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Tue, 17 Nov 2026 16:36:00 +0000 Subject: [PATCH 05/10] Allow user to choose deep/shallow pasting --- .../alarm/client/AlarmClientNode.java | 14 +++++++++ .../alarm/ui/tree/PasteItemAction.java | 31 ++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientNode.java b/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientNode.java index e5ec601250..315238ab63 100644 --- a/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientNode.java +++ b/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClientNode.java @@ -7,6 +7,7 @@ *******************************************************************************/ package org.phoebus.applications.alarm.client; +import java.util.ArrayList; import java.util.concurrent.CopyOnWriteArrayList; import org.phoebus.applications.alarm.model.AlarmTreeItemWithState; @@ -27,4 +28,17 @@ public AlarmClientNode(final String parent_path, final String name) super(parent_path, name, new CopyOnWriteArrayList<>()); state = new BasicState(SeverityLevel.OK); } + + /** @return {@link AlarmClientNode} with same configuration, but no parent or children */ + public AlarmClientNode createDetachedCopy() + { + final AlarmClientNode node = new AlarmClientNode(null, getName()); + + node.setGuidance(new ArrayList<>(getGuidance())); + node.setDisplays(new ArrayList<>(getDisplays())); + node.setCommands(new ArrayList<>(getCommands())); + node.setActions(new ArrayList<>(getActions())); + + return node; + } } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index be6f11ae93..624ad9abbe 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -2,6 +2,8 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Node; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; import javafx.scene.control.MenuItem; import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; @@ -40,11 +42,12 @@ public PasteItemAction( setDisable(clipboard.get() == null); setOnAction(event -> { - final AlarmTreeItem item = clipboard.get(); + AlarmTreeItem item = clipboard.get(); + final String itemName = item.getName(); // Get new name, prompting user if any child of the new parent already has the same name String newName = item.getName(); - if (parent.getChildren().stream().anyMatch(child -> child.getName().equals(item.getName()))) { + if (parent.getChildren().stream().anyMatch(child -> child.getName().equals(itemName))) { // Item already exists in the parent node we're copying to; prompt for rename final RenameDialog dialog = new RenameDialog(parent, item.getName()); dialog.setHeaderText(MessageFormat.format(Messages.itemAlreadyExists, parent.getName(), item.getName())); @@ -57,11 +60,31 @@ public PasteItemAction( } } - final String finalNewName = newName; // lambda variables must be final + // Prompt user whether they want to paste the children too + if (item instanceof final AlarmClientNode alarmNode && !alarmNode.getChildren().isEmpty()) { + final Dialog dialog = new Dialog<>(); + DialogHelper.positionDialog(dialog, node, -100, -50); + dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.NO, ButtonType.YES); + dialog.setTitle("Copy children?"); + dialog.setHeaderText("Copy the children of this node too?"); + + final ButtonType result = dialog.showAndWait().orElse(null); + if (result == null || result == ButtonType.CANCEL) { + return; + } + if (result == ButtonType.NO) { + item = alarmNode.createDetachedCopy(); + } + } + + // Finally paste the item (on a separate thread of course) + // lambda variables must be final + final AlarmTreeItem finalItem = item; + final String finalNewName = newName; JobManager.schedule("Paste alarm tree item", _ -> { try { final String newPath = AlarmTreePath.makePath(parent.getPathName(), finalNewName); - AlarmTreeHelper.moveItem(model, item, newPath, isCut); + AlarmTreeHelper.moveItem(model, finalItem, newPath, isCut); } catch (final Exception ex) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.pasteItemFailed, ex); } From 90889d148490a7efb38da6d605b96c0fc6c250f6 Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Wed, 18 Nov 2026 12:30:55 +0000 Subject: [PATCH 06/10] Allow cross-config pasting, forbid cross-config cut/paste, and forbid cut/paste into child --- .../applications/alarm/ui/Messages.java | 4 +++ .../alarm/ui/tree/AlarmTreeView.java | 4 +-- .../alarm/ui/tree/PasteItemAction.java | 29 +++++++++++++++++-- .../applications/alarm/ui/messages.properties | 6 +++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java index 5d23ecc068..f6c64ce06b 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java @@ -22,6 +22,10 @@ public class Messages public static String Annunciator; public static String commands; public static String configure; + public static String cutPasteAcrossConfigs; + public static String copyChildrenDialogTitle; + public static String copyChildrenDialogHeader; + public static String cutPasteIntoChild; public static String delayTooltip0; public static String delayTooltip1; public static String delayTooltip2; 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 5324c49ad6..9c0f0ca1bc 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 @@ -151,8 +151,8 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener items.remove(changing); }); - private final SimpleObjectProperty> clipboard = new SimpleObjectProperty<>(null); - private final SimpleBooleanProperty isClipboardCut = new SimpleBooleanProperty(false); + private static final SimpleObjectProperty> clipboard = new SimpleObjectProperty<>(null); + private static final SimpleBooleanProperty isClipboardCut = new SimpleBooleanProperty(false); // Javadoc for TreeItem shows example for overriding isLeaf() and getChildren() // to dynamically create TreeItem as TreeView requests information. diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index 624ad9abbe..161762c5f5 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -2,6 +2,7 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Node; +import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; import javafx.scene.control.Dialog; import javafx.scene.control.MenuItem; @@ -45,6 +46,30 @@ public PasteItemAction( AlarmTreeItem item = clipboard.get(); final String itemName = item.getName(); + // Cross-config cut/paste is forbidden. (Why? User cuts from config A -> switches to + // config B -> pastes to config B -> config A is no longer loaded so how can we remove + // the old item?) + final String itemConfig = AlarmTreePath.splitPath(item.getPathName())[0]; + final String modelConfig = AlarmTreePath.splitPath(model.getRoot().getPathName())[0]; + if (isCut && !itemConfig.equals(modelConfig)) { + final Alert alert = new Alert(Alert.AlertType.ERROR); + DialogHelper.positionDialog(alert, node, -100, -50); + alert.setTitle(Messages.pasteItemFailed); + alert.setHeaderText(Messages.cutPasteAcrossConfigs); + alert.show(); + return; + } + + // Cutting+pasting a node into one of its children is forbidden for obvious reasons + if (parent.getPathName().startsWith(item.getPathName())) { + final Alert alert = new Alert(Alert.AlertType.ERROR); + DialogHelper.positionDialog(alert, node, -100, -50); + alert.setTitle(Messages.pasteItemFailed); + alert.setHeaderText(Messages.cutPasteIntoChild); + alert.show(); + return; + } + // Get new name, prompting user if any child of the new parent already has the same name String newName = item.getName(); if (parent.getChildren().stream().anyMatch(child -> child.getName().equals(itemName))) { @@ -65,8 +90,8 @@ public PasteItemAction( final Dialog dialog = new Dialog<>(); DialogHelper.positionDialog(dialog, node, -100, -50); dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.NO, ButtonType.YES); - dialog.setTitle("Copy children?"); - dialog.setHeaderText("Copy the children of this node too?"); + dialog.setTitle(Messages.copyChildrenDialogTitle); + dialog.setHeaderText(Messages.copyChildrenDialogHeader); final ButtonType result = dialog.showAndWait().orElse(null); if (result == null || result == ButtonType.CANCEL) { diff --git a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties index 57a9140133..96563feb97 100644 --- a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties +++ b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties @@ -34,6 +34,10 @@ behavior=Behavior: behaviorTooltip=Enable alarms? See also 'Enabling Filter' commands=Commands: configure=Configure +copyChildrenDialogTitle=Copy children? +copyChildrenDialogHeader=Copy the children of this node too? +cutPasteAcrossConfigs=You cannot cut and paste a component across configs.\n Instead, copy the component across and then delete the original. +cutPasteIntoChild=You cannot cut and paste a component into one of its children dateTimePickerTooltip=Select a date until which the alarm should be disabled delay=Delay delayTooltip0=Alarms are indicated when they persist for at least this long.\n{0} @@ -77,7 +81,7 @@ nameCannotBeEmpty=Name cannot be empty option=Option partlyDisabled2=(Partly disabled) pasteItem=Paste Item -pasteItemFailed=Failed to paste component +pasteItemFailed=Failed to paste item path=Path: promptTitle=Absolute Date is set to a point in time in the past relativeDateLabel=Relative Date: From a39c48e8d2d237fa21449c3af865accb297232f6 Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Wed, 18 Nov 2026 15:04:19 +0000 Subject: [PATCH 07/10] Disallow duplicate PVs, always prompt for rename --- .../applications/alarm/ui/Messages.java | 5 +- .../alarm/ui/tree/DuplicatePVAction.java | 2 +- .../alarm/ui/tree/PasteItemAction.java | 26 ++++----- .../alarm/ui/tree/RenameDialog.java | 55 ++++++++++++------- .../alarm/ui/tree/RenameTreeItemAction.java | 5 +- .../applications/alarm/ui/messages.properties | 5 +- 6 files changed, 53 insertions(+), 45 deletions(-) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java index f6c64ce06b..d74510c5dd 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java @@ -40,7 +40,7 @@ public class Messages public static String displays; public static String enableAlarmFailed; public static String enableAlarms; - public static String enterNameForDuplicate; + public static String enterNewName; public static String guidance; public static String headerAlreadyDisabled; public static String headerAlreadyEnabled; @@ -48,13 +48,14 @@ public class Messages public static String headerConfirmDisableWithEnableDate; public static String headerConfirmEnable; public static String indefinitely; - public static String itemAlreadyExists; public static String MenuPath; public static String moveItemFailed; public static String nameCannotBeEmpty; + public static String nodeAlreadyExists; public static String pasteItem; public static String pasteItemFailed; public static String promptTitle; + public static String pvAlreadyExists; public static String renameItem; public static String renameDialogLabel; public static String renameDialogTitle; diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java index 302aeb37a3..de5ca31157 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java @@ -40,7 +40,7 @@ public DuplicatePVAction(final Node node, final AlarmClient model, final AlarmCl setOnAction(event -> { // Prompt for new PV name - final RenameDialog dialog = new RenameDialog(original.getParent(), original.getName()); + final RenameDialog dialog = new RenameDialog(model, original.getParent(), original); dialog.setHeaderText("Enter name for duplicate"); DialogHelper.positionDialog(dialog, node, -100, -50); final String new_name = dialog.showAndWait().orElse(null); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index 161762c5f5..0fe950fb47 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -61,7 +61,7 @@ public PasteItemAction( } // Cutting+pasting a node into one of its children is forbidden for obvious reasons - if (parent.getPathName().startsWith(item.getPathName())) { + if (parent.getPathName().startsWith(item.getPathName() + "/")) { final Alert alert = new Alert(Alert.AlertType.ERROR); DialogHelper.positionDialog(alert, node, -100, -50); alert.setTitle(Messages.pasteItemFailed); @@ -70,20 +70,15 @@ public PasteItemAction( return; } - // Get new name, prompting user if any child of the new parent already has the same name - String newName = item.getName(); - if (parent.getChildren().stream().anyMatch(child -> child.getName().equals(itemName))) { - // Item already exists in the parent node we're copying to; prompt for rename - final RenameDialog dialog = new RenameDialog(parent, item.getName()); - dialog.setHeaderText(MessageFormat.format(Messages.itemAlreadyExists, parent.getName(), item.getName())); - DialogHelper.positionDialog(dialog, node, -100, -50); - final Optional name = dialog.showAndWait(); - if (name.isPresent()) { - newName = name.get(); - } else { - return; - } + // Get new name + final RenameDialog renameDialog = new RenameDialog(model, parent, item); + renameDialog.setHeaderText(MessageFormat.format(Messages.enterNewName, parent.getName(), item.getName())); + DialogHelper.positionDialog(renameDialog, node, -100, -50); + final Optional name = renameDialog.showAndWait(); + if (!name.isPresent()) { + return; } + final String newName = name.get(); // Prompt user whether they want to paste the children too if (item instanceof final AlarmClientNode alarmNode && !alarmNode.getChildren().isEmpty()) { @@ -105,10 +100,9 @@ public PasteItemAction( // Finally paste the item (on a separate thread of course) // lambda variables must be final final AlarmTreeItem finalItem = item; - final String finalNewName = newName; JobManager.schedule("Paste alarm tree item", _ -> { try { - final String newPath = AlarmTreePath.makePath(parent.getPathName(), finalNewName); + final String newPath = AlarmTreePath.makePath(parent.getPathName(), newName); AlarmTreeHelper.moveItem(model, finalItem, newPath, isCut); } catch (final Exception ex) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.pasteItemFailed, ex); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java index dbb1b5e65b..aff4b22168 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java @@ -9,21 +9,20 @@ import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; +import org.phoebus.applications.alarm.client.AlarmClient; +import org.phoebus.applications.alarm.client.AlarmClientLeaf; +import org.phoebus.applications.alarm.client.AlarmClientNode; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.ui.Messages; +import java.util.HashSet; +import java.util.Set; import java.util.function.Consumer; public class RenameDialog extends Dialog { - /** - * - * @param parent The parent of the item being renamed - use to check for name clashes - * @param oldName The old name of the item being renamed - * @param allowOldName Whether the new name can be the same as the old name - */ - public RenameDialog(final AlarmTreeItem parent, final String oldName) { + public RenameDialog(final AlarmClient model, final AlarmTreeItem parent, final AlarmTreeItem item) { super(); setTitle(Messages.renameDialogTitle); @@ -31,14 +30,13 @@ public RenameDialog(final AlarmTreeItem parent, final String oldName) { final Label renameLabel = new Label(Messages.renameDialogLabel); final TextField input = new TextField(); - input.setText(oldName); input.setPrefWidth(600.0); HBox.setHgrow(input, Priority.ALWAYS); final HBox inputBox = new HBox(renameLabel, input); inputBox.setAlignment(Pos.CENTER_LEFT); - final Label errorLabel = new Label(Messages.itemAlreadyExists); + final Label errorLabel = new Label(Messages.nodeAlreadyExists); errorLabel.setTextFill(Color.RED); errorLabel.setMaxWidth(Double.MAX_VALUE); @@ -47,30 +45,45 @@ public RenameDialog(final AlarmTreeItem parent, final String oldName) { getDialogPane().lookupButton(ButtonType.OK).setDisable(newError != null); }; + final Set allPvs = getAllPvs(model.getRoot()); // Done once at start so we don't have to keep calling it in listener input.textProperty().addListener(_ -> { - // Disable OK if name has not changed - if (input.getText().equals(oldName)) { - updateError.accept(""); // disable OK but don't show an error - return; - } - // Show error and disable OK if text is empty if (input.getText().isEmpty()) { updateError.accept(Messages.nameCannotBeEmpty); return; } - // Show error and disable OK if the label matches any child - final boolean childExists = parent.getChildren().stream().anyMatch(child -> input.getText().equals(child.getName())); - updateError.accept(childExists ? Messages.itemAlreadyExists : null); + if (item instanceof AlarmClientNode) { + // Show error and disable OK if the new name matches any child + final boolean childExists = parent.getChildren().stream().anyMatch(child -> input.getText().equals(child.getName())); + updateError.accept(childExists ? Messages.nodeAlreadyExists : null); + } else { + // SHow error and disable OK if the PV already exists in the config + final boolean pvExists = allPvs.contains(input.getText()); + updateError.accept(pvExists ? Messages.pvAlreadyExists : null); + } }); + getDialogPane().setContent(new VBox(inputBox, errorLabel)); getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); - // Default to error hidden and OK disabled - updateError.accept(""); - setResultConverter(buttonType -> buttonType == ButtonType.OK ? input.getText() : null); + + input.setText(item.getName()); + errorLabel.setText(""); // It can be confusing if an error is shown immediately when the UI loads + } + + /** Recursively finds all the PVs in a config and adds them to `pvs` */ + private static Set getAllPvs(final AlarmTreeItem item) { + final Set pvs = new HashSet<>(); + if (item instanceof AlarmClientLeaf) { + pvs.add(item.getName()); + } else { + for (final AlarmTreeItem child : item.getChildren()) { + pvs.addAll(getAllPvs(child)); + } + } + return pvs; } } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java index 1df7d11859..5788971f0c 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java @@ -9,7 +9,6 @@ import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; -import org.phoebus.applications.alarm.client.AlarmClientNode; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreePath; import org.phoebus.applications.alarm.model.BasicState; @@ -42,8 +41,8 @@ public RenameTreeItemAction(final TreeView> node, setOnAction(event -> { // Prompt for new name - final RenameDialog dialog = new RenameDialog(item.getParent(), item.getName()); - dialog.setHeaderText(Messages.enterNameForDuplicate); + final RenameDialog dialog = new RenameDialog(model, item.getParent(), item); + dialog.setHeaderText(Messages.enterNewName); DialogHelper.positionDialog(dialog, node, -100, -50); final String new_name = dialog.showAndWait().orElse(null); if (new_name == null) diff --git a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties index 96563feb97..0c4dc265f5 100644 --- a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties +++ b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties @@ -59,10 +59,10 @@ displays=Displays: enabled=Enabled enablingFilter=Enabling Filter: enablingFilterTooltip=Optional expression for enabling the alarm -enterNameForDuplicate=Enter name for duplicate error=Error enableAlarmFailed=Failed to enable alarm enableAlarms=Enable Alarms +enterNewName=Enter new name guidance=Guidance: headerAlreadyDisabled=All PVs in the selected section are already disabled headerAlreadyEnabled=All PVs in the selected section are already enabled @@ -72,18 +72,19 @@ headerConfirmEnable=Enable all PVs in the selected section of the alarm hierarch indefinitely=Indefinitely info=Info invalidDate=You have selected a date that is either invalid or in the past -itemAlreadyExists=Item already exists latch=Latch latchTooltip=Latch alarm until acknowledged? MenuPath=Alarm moveItemFailed=Failed to move item nameCannotBeEmpty=Name cannot be empty +nodeAlreadyExists=Node already exists option=Option partlyDisabled2=(Partly disabled) pasteItem=Paste Item pasteItemFailed=Failed to paste item path=Path: promptTitle=Absolute Date is set to a point in time in the past +pvAlreadyExists=PV already exists in this config relativeDateLabel=Relative Date: relativeDateTooltip=Select a predefined duration for disabling the alarm removeComponentFailed=Failed to remove component From 9e56b56b613e8a0a290d95aad555b0a10f4ea217 Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Thu, 19 Nov 2026 09:44:21 +0000 Subject: [PATCH 08/10] Fix many copy-cut-paste edge cases --- .../applications/alarm/ui/Messages.java | 1 + .../alarm/ui/tree/AlarmTreeHelper.java | 21 ---- .../alarm/ui/tree/AlarmTreeView.java | 6 +- .../alarm/ui/tree/MoveTreeItemAction.java | 10 +- .../alarm/ui/tree/PasteItemAction.java | 104 +++++++++++++----- .../alarm/ui/tree/RenameDialog.java | 19 +--- .../alarm/ui/tree/RenameTreeItemAction.java | 10 +- .../applications/alarm/ui/messages.properties | 5 +- 8 files changed, 104 insertions(+), 72 deletions(-) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java index d74510c5dd..6699b2a163 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java @@ -52,6 +52,7 @@ public class Messages public static String moveItemFailed; public static String nameCannotBeEmpty; public static String nodeAlreadyExists; + public static String nodePvsAlreadyExist; public static String pasteItem; public static String pasteItemFailed; public static String promptTitle; diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java index 1d3c2865a9..42ee26368c 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java @@ -54,27 +54,6 @@ public static void rebuildTree(AlarmClient model, AlarmTreeItem parent, Strin } } - /** Moves the provided item and all its children to a new path. - * - * @param model AlarmClient used to communicate to the AlarmServer - * @param item AlarmTreeItem to move - * @param path Path that the parents' children will now be located at. - * @param removeOldItem Whether the old item should be removed once it is moved - */ - public static void moveItem(AlarmClient model, AlarmTreeItem item, String newPath, boolean removeOldItem) throws Exception - { - // Add the new item - model.sendItemConfigurationUpdate(newPath, item); - // ...and rebuild all its children - if (item instanceof AlarmClientNode) { - rebuildTree(model, item, newPath); - } - // Remove the item and all its children - if (removeOldItem) { - model.removeComponent(item); - } - } - /** Validate the passed path string by checking if the path name is valid. * *

A path name is considered valid if the path to the item's new location exists in the tree, 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 9c0f0ca1bc..4b41cb2867 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 @@ -621,9 +621,9 @@ else if (selection.size() == 1) menu_items.add(new CopyItemAction(tree_view, clipboard, isClipboardCut, item)); menu_items.add(new CutItemAction(tree_view, clipboard, isClipboardCut, item)); - menu_items.add(new PasteItemAction( - tree_view, model, item instanceof AlarmClientNode ? item : item.getParent(), clipboard, isClipboardCut.get() - )); + final AlarmTreeItem parent = item instanceof AlarmClientNode ? item : item.getParent(); + final TreeItem> viewParent = path2view.get(parent.getPathName()); + menu_items.add(new PasteItemAction(tree_view, model, viewParent, clipboard, isClipboardCut.get())); if (item instanceof AlarmClientNode) menu_items.add(new AddComponentAction(tree_view, model, item)); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java index 725d1bbf1d..9b9539e1df 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java @@ -9,6 +9,7 @@ import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; +import org.phoebus.applications.alarm.client.AlarmClientNode; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreePath; import org.phoebus.applications.alarm.ui.Messages; @@ -75,7 +76,14 @@ public MoveTreeItemAction(TreeView> node, JobManager.schedule(getText(), monitor -> { try { - AlarmTreeHelper.moveItem(model, item, new_path, true); + // Add the new item + model.sendItemConfigurationUpdate(new_path, item); + // ...and rebuild all its children + if (item instanceof AlarmClientNode) { + AlarmTreeHelper.rebuildTree(model, item, new_path); + } + // Remove the item and all its children + model.removeComponent(item); } catch (Exception e) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.moveItemFailed, diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index 0fe950fb47..c9357dd032 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -3,9 +3,11 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Node; import javafx.scene.control.Alert; -import javafx.scene.control.ButtonType; -import javafx.scene.control.Dialog; +import javafx.scene.control.Label; import javafx.scene.control.MenuItem; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TreeItem; +import javafx.scene.layout.VBox; import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.client.AlarmClientNode; @@ -19,6 +21,8 @@ import java.text.MessageFormat; import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; @SuppressWarnings("nls") @@ -34,16 +38,18 @@ public class PasteItemAction extends MenuItem public PasteItemAction( final Node node, final AlarmClient model, - final AlarmTreeItem parent, + final TreeItem> viewParent, final SimpleObjectProperty> clipboard, final boolean isCut) { super(Messages.pasteItem, ImageCache.getImageView(AlarmSystem.class, "/icons/paste.png")); - setDisable(clipboard.get() == null); + final AlarmTreeItem parent = viewParent.getValue(); + + setDisable(clipboard.get() == null || isCut && parent.getPathName().equals(clipboard.get().getParent().getPathName())); setOnAction(event -> { - AlarmTreeItem item = clipboard.get(); + final AlarmTreeItem item = clipboard.get(); final String itemName = item.getName(); // Cross-config cut/paste is forbidden. (Why? User cuts from config A -> switches to @@ -61,7 +67,7 @@ public PasteItemAction( } // Cutting+pasting a node into one of its children is forbidden for obvious reasons - if (parent.getPathName().startsWith(item.getPathName() + "/")) { + if (isCut && (parent.getPathName().equals(item.getPathName()) || parent.getPathName().startsWith(item.getPathName() + "/"))) { final Alert alert = new Alert(Alert.AlertType.ERROR); DialogHelper.positionDialog(alert, node, -100, -50); alert.setTitle(Messages.pasteItemFailed); @@ -70,40 +76,78 @@ public PasteItemAction( return; } - // Get new name - final RenameDialog renameDialog = new RenameDialog(model, parent, item); - renameDialog.setHeaderText(MessageFormat.format(Messages.enterNewName, parent.getName(), item.getName())); - DialogHelper.positionDialog(renameDialog, node, -100, -50); - final Optional name = renameDialog.showAndWait(); - if (!name.isPresent()) { - return; + // Figure out if this item needs renaming + final boolean needsRename; + final Set allPvsInNewConfig = AlarmTreeHelper.getLeafItems(model.getRoot()) + .stream() + .map(AlarmTreeItem::getName) + .collect(Collectors.toSet()); + if (item instanceof AlarmClientNode) { + // Needs to be renamed if new name matches any child + needsRename = parent.getChildren().stream().anyMatch(child -> item.getName().equals(child.getName())); + } else { + // Needs to be renamed if we are not cutting and the PV already exists in the config + needsRename = !isCut && allPvsInNewConfig.contains(item.getName()); } - final String newName = name.get(); - // Prompt user whether they want to paste the children too - if (item instanceof final AlarmClientNode alarmNode && !alarmNode.getChildren().isEmpty()) { - final Dialog dialog = new Dialog<>(); - DialogHelper.positionDialog(dialog, node, -100, -50); - dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.NO, ButtonType.YES); - dialog.setTitle(Messages.copyChildrenDialogTitle); - dialog.setHeaderText(Messages.copyChildrenDialogHeader); - - final ButtonType result = dialog.showAndWait().orElse(null); - if (result == null || result == ButtonType.CANCEL) { + // Get final name + final String finalName; + if (needsRename) { + final RenameDialog renameDialog = new RenameDialog(model, parent, item); + renameDialog.setHeaderText(MessageFormat.format(Messages.enterNewName, parent.getName(), item.getName())); + DialogHelper.positionDialog(renameDialog, node, -100, -50); + final Optional name = renameDialog.showAndWait(); + if (!name.isPresent()) { return; } - if (result == ButtonType.NO) { - item = alarmNode.createDetachedCopy(); + finalName = name.get(); + } else { + finalName = item.getName(); + } + + // Special case: if a node is pasted across configs, some of the PVs in that node + // may already exist. But the user still may have intended to copy across all the + // PVs and so we should not just fail silently. Best-effort copying is unlikely + // to be helpful here, and likely to cause unintended behaviour, so we do not offer + // that option and just display an error instead. + if (!itemConfig.equals(modelConfig) && item instanceof AlarmClientNode) { + final Set duplicatePvs = AlarmTreeHelper.getLeafItems(item) + .stream() + .map(AlarmTreeItem::getName) + .collect(Collectors.toSet()); + duplicatePvs.retainAll(allPvsInNewConfig); + if (!duplicatePvs.isEmpty()) { + final Alert alert = new Alert(Alert.AlertType.ERROR); + DialogHelper.positionDialog(alert, node, -100, -50); + alert.setTitle(Messages.pasteItemFailed); + alert.setHeaderText(Messages.nodePvsAlreadyExist); + final VBox pvPane = new VBox(); + for (final String pv : duplicatePvs) { + pvPane.getChildren().add(new Label(pv)); + } + final ScrollPane scrollPane = new ScrollPane(pvPane); + scrollPane.setPrefHeight(400.0); + alert.getDialogPane().setContent(scrollPane); + alert.show(); + return; } } + // Expand the node which we're adding to in anticipation of new children being added + viewParent.setExpanded(true); + // Finally paste the item (on a separate thread of course) - // lambda variables must be final - final AlarmTreeItem finalItem = item; + final AlarmTreeItem finalItem = item; // lambda variables must be final JobManager.schedule("Paste alarm tree item", _ -> { try { - final String newPath = AlarmTreePath.makePath(parent.getPathName(), newName); - AlarmTreeHelper.moveItem(model, finalItem, newPath, isCut); + final String newPath = AlarmTreePath.makePath(parent.getPathName(), finalName); + model.sendItemConfigurationUpdate(newPath, item); + if ((isCut || !itemConfig.equals(modelConfig)) && item instanceof AlarmClientNode) { + AlarmTreeHelper.rebuildTree(model, item, newPath); + } + if (isCut) { + model.removeComponent(item); + } } catch (final Exception ex) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.pasteItemFailed, ex); } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java index aff4b22168..8d57a8c03a 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java @@ -18,6 +18,7 @@ import java.util.HashSet; import java.util.Set; import java.util.function.Consumer; +import java.util.stream.Collectors; public class RenameDialog extends Dialog { @@ -45,7 +46,10 @@ public RenameDialog(final AlarmClient model, final AlarmTreeItem parent, fina getDialogPane().lookupButton(ButtonType.OK).setDisable(newError != null); }; - final Set allPvs = getAllPvs(model.getRoot()); // Done once at start so we don't have to keep calling it in listener + final Set allPvs = AlarmTreeHelper.getLeafItems(model.getRoot()) + .stream() + .map(AlarmTreeItem::getName) + .collect(Collectors.toSet()); // Done once at start so we don't have to keep calling it in listener input.textProperty().addListener(_ -> { // Show error and disable OK if text is empty if (input.getText().isEmpty()) { @@ -73,17 +77,4 @@ public RenameDialog(final AlarmClient model, final AlarmTreeItem parent, fina input.setText(item.getName()); errorLabel.setText(""); // It can be confusing if an error is shown immediately when the UI loads } - - /** Recursively finds all the PVs in a config and adds them to `pvs` */ - private static Set getAllPvs(final AlarmTreeItem item) { - final Set pvs = new HashSet<>(); - if (item instanceof AlarmClientLeaf) { - pvs.add(item.getName()); - } else { - for (final AlarmTreeItem child : item.getChildren()) { - pvs.addAll(getAllPvs(child)); - } - } - return pvs; - } } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java index 5788971f0c..4587788b21 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java @@ -9,6 +9,7 @@ import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; +import org.phoebus.applications.alarm.client.AlarmClientNode; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreePath; import org.phoebus.applications.alarm.model.BasicState; @@ -54,7 +55,14 @@ public RenameTreeItemAction(final TreeView> node, final AlarmTreeItem parent = item.getParent(); try { final String new_path = AlarmTreePath.makePath(parent.getPathName(), new_name); - AlarmTreeHelper.moveItem(model, item, new_path, true); + // Add the new item + model.sendItemConfigurationUpdate(new_path, item); + // ...and rebuild all its children + if (item instanceof AlarmClientNode) { + AlarmTreeHelper.rebuildTree(model, item, new_path); + } + // Remove the item and all its children + model.removeComponent(item); } catch (final Exception ex) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.renameItemFailed, diff --git a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties index 0c4dc265f5..5be41bd626 100644 --- a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties +++ b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties @@ -36,8 +36,8 @@ commands=Commands: configure=Configure copyChildrenDialogTitle=Copy children? copyChildrenDialogHeader=Copy the children of this node too? -cutPasteAcrossConfigs=You cannot cut and paste a component across configs.\n Instead, copy the component across and then delete the original. -cutPasteIntoChild=You cannot cut and paste a component into one of its children +cutPasteAcrossConfigs=You cannot cut and paste a component across configs.\nInstead, copy the component across and then delete the original. +cutPasteIntoChild=You cannot cut and paste a component into itself or one of its children dateTimePickerTooltip=Select a date until which the alarm should be disabled delay=Delay delayTooltip0=Alarms are indicated when they persist for at least this long.\n{0} @@ -77,6 +77,7 @@ latchTooltip=Latch alarm until acknowledged? MenuPath=Alarm moveItemFailed=Failed to move item nameCannotBeEmpty=Name cannot be empty +nodePvsAlreadyExist=The node you're pasting has some PVs which already exist in the config: nodeAlreadyExists=Node already exists option=Option partlyDisabled2=(Partly disabled) From fbf8834a07c0055b283ee2653846efbc60665dc5 Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Thu, 19 Nov 2026 10:14:05 +0000 Subject: [PATCH 09/10] Cleanup --- .../applications/alarm/ui/Messages.java | 3 +- .../alarm/ui/tree/AlarmTreeHelper.java | 13 ++++++- .../alarm/ui/tree/DuplicatePVAction.java | 4 +- .../alarm/ui/tree/MoveTreeItemAction.java | 4 ++ .../alarm/ui/tree/PasteItemAction.java | 37 ++++++++++--------- .../alarm/ui/tree/RenameDialog.java | 5 +-- .../alarm/ui/tree/RenameTreeItemAction.java | 4 ++ .../applications/alarm/ui/messages.properties | 4 +- 8 files changed, 45 insertions(+), 29 deletions(-) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java index 6699b2a163..d9d3f45a83 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java @@ -23,8 +23,6 @@ public class Messages public static String commands; public static String configure; public static String cutPasteAcrossConfigs; - public static String copyChildrenDialogTitle; - public static String copyChildrenDialogHeader; public static String cutPasteIntoChild; public static String delayTooltip0; public static String delayTooltip1; @@ -40,6 +38,7 @@ public class Messages public static String displays; public static String enableAlarmFailed; public static String enableAlarms; + public static String enterNameForDuplicate; public static String enterNewName; public static String guidance; public static String headerAlreadyDisabled; diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java index 42ee26368c..858e50b399 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeHelper.java @@ -15,7 +15,6 @@ import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.client.AlarmClientLeaf; -import org.phoebus.applications.alarm.client.AlarmClientNode; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreePath; import org.phoebus.applications.alarm.ui.Messages; @@ -129,6 +128,18 @@ private static Stream streamLeafItems(final AlarmTreeItem al } } + /** + * Collects the names of {@link AlarmClientLeaf}s items. + * @param root The start node from where to get {@link AlarmClientLeaf}s. If this is an {@link AlarmClientLeaf}, it + * will be returned as the sole item in the {@link Set} + * @return A {@link Set} of the names of all {@link AlarmClientLeaf}s. + */ + public static Set getLeafNames(final AlarmTreeItem root) { + return streamLeafItems(root) + .map(AlarmTreeItem::getName) + .collect(Collectors.toSet()); + } + /** * * @param items {@link List} of {@link AlarmTreeItem}s that may be a mix of leaves and non-leaves, e.g. a user diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java index de5ca31157..1e76f8ef61 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/DuplicatePVAction.java @@ -12,6 +12,7 @@ import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.client.AlarmClientLeaf; import org.phoebus.applications.alarm.model.AlarmTreePath; +import org.phoebus.applications.alarm.ui.Messages; import org.phoebus.framework.jobs.JobManager; import org.phoebus.ui.dialog.DialogHelper; import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; @@ -19,7 +20,6 @@ import javafx.scene.Node; import javafx.scene.control.MenuItem; -import javafx.scene.control.TextInputDialog; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,7 +41,7 @@ public DuplicatePVAction(final Node node, final AlarmClient model, final AlarmCl { // Prompt for new PV name final RenameDialog dialog = new RenameDialog(model, original.getParent(), original); - dialog.setHeaderText("Enter name for duplicate"); + dialog.setHeaderText(Messages.enterNameForDuplicate); DialogHelper.positionDialog(dialog, node, -100, -50); final String new_name = dialog.showAndWait().orElse(null); if (new_name == null) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java index 9b9539e1df..6ccf660968 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java @@ -71,6 +71,10 @@ public MoveTreeItemAction(TreeView> node, return; } + // Tree view keeps the selection indices, which will point to wrong content + // after those items have been removed + node.getSelectionModel().clearSelection(); + final String new_path = path; // On a background thread, send the item configuration updates for the item to be moved and all its children. JobManager.schedule(getText(), monitor -> diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index c9357dd032..b447d21ee1 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -52,12 +52,14 @@ public PasteItemAction( final AlarmTreeItem item = clipboard.get(); final String itemName = item.getName(); + final String itemConfig = AlarmTreePath.splitPath(item.getPathName())[0]; + final String modelConfig = AlarmTreePath.splitPath(model.getRoot().getPathName())[0]; + final boolean isCrossConfig = !itemConfig.equals(modelConfig); + // Cross-config cut/paste is forbidden. (Why? User cuts from config A -> switches to // config B -> pastes to config B -> config A is no longer loaded so how can we remove // the old item?) - final String itemConfig = AlarmTreePath.splitPath(item.getPathName())[0]; - final String modelConfig = AlarmTreePath.splitPath(model.getRoot().getPathName())[0]; - if (isCut && !itemConfig.equals(modelConfig)) { + if (isCut && isCrossConfig) { final Alert alert = new Alert(Alert.AlertType.ERROR); DialogHelper.positionDialog(alert, node, -100, -50); alert.setTitle(Messages.pasteItemFailed); @@ -67,7 +69,9 @@ public PasteItemAction( } // Cutting+pasting a node into one of its children is forbidden for obvious reasons - if (isCut && (parent.getPathName().equals(item.getPathName()) || parent.getPathName().startsWith(item.getPathName() + "/"))) { + final boolean isPasteIntoSelf = parent.getPathName().equals(item.getPathName()); + final boolean isPasteIntoChild = parent.getPathName().startsWith(item.getPathName() + "/"); + if (isCut && (isPasteIntoSelf || isPasteIntoChild)) { final Alert alert = new Alert(Alert.AlertType.ERROR); DialogHelper.positionDialog(alert, node, -100, -50); alert.setTitle(Messages.pasteItemFailed); @@ -78,15 +82,12 @@ public PasteItemAction( // Figure out if this item needs renaming final boolean needsRename; - final Set allPvsInNewConfig = AlarmTreeHelper.getLeafItems(model.getRoot()) - .stream() - .map(AlarmTreeItem::getName) - .collect(Collectors.toSet()); + final Set allPvsInNewConfig = AlarmTreeHelper.getLeafNames(model.getRoot()); if (item instanceof AlarmClientNode) { // Needs to be renamed if new name matches any child needsRename = parent.getChildren().stream().anyMatch(child -> item.getName().equals(child.getName())); } else { - // Needs to be renamed if we are not cutting and the PV already exists in the config + // Needs to be renamed if pasting would result in a duplicate PV needsRename = !isCut && allPvsInNewConfig.contains(item.getName()); } @@ -110,23 +111,23 @@ public PasteItemAction( // PVs and so we should not just fail silently. Best-effort copying is unlikely // to be helpful here, and likely to cause unintended behaviour, so we do not offer // that option and just display an error instead. - if (!itemConfig.equals(modelConfig) && item instanceof AlarmClientNode) { - final Set duplicatePvs = AlarmTreeHelper.getLeafItems(item) - .stream() - .map(AlarmTreeItem::getName) - .collect(Collectors.toSet()); + if (isCrossConfig && item instanceof AlarmClientNode) { + final Set duplicatePvs = AlarmTreeHelper.getLeafNames(item); duplicatePvs.retainAll(allPvsInNewConfig); + if (!duplicatePvs.isEmpty()) { final Alert alert = new Alert(Alert.AlertType.ERROR); DialogHelper.positionDialog(alert, node, -100, -50); alert.setTitle(Messages.pasteItemFailed); alert.setHeaderText(Messages.nodePvsAlreadyExist); + final VBox pvPane = new VBox(); for (final String pv : duplicatePvs) { pvPane.getChildren().add(new Label(pv)); } final ScrollPane scrollPane = new ScrollPane(pvPane); scrollPane.setPrefHeight(400.0); + alert.getDialogPane().setContent(scrollPane); alert.show(); return; @@ -142,11 +143,13 @@ public PasteItemAction( try { final String newPath = AlarmTreePath.makePath(parent.getPathName(), finalName); model.sendItemConfigurationUpdate(newPath, item); - if ((isCut || !itemConfig.equals(modelConfig)) && item instanceof AlarmClientNode) { - AlarmTreeHelper.rebuildTree(model, item, newPath); - } if (isCut) { + // If we're cutting, there's never any risk of duplicate PVs so we can copy all the children too + AlarmTreeHelper.rebuildTree(model, item, newPath); model.removeComponent(item); + } else if (isCrossConfig && item instanceof AlarmClientNode) { + // Cross-config pasting should copy all the children + AlarmTreeHelper.rebuildTree(model, item, newPath); } } catch (final Exception ex) { ExceptionDetailsErrorDialog.openError(Messages.error, Messages.pasteItemFailed, ex); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java index 8d57a8c03a..ce10dacf43 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameDialog.java @@ -46,10 +46,7 @@ public RenameDialog(final AlarmClient model, final AlarmTreeItem parent, fina getDialogPane().lookupButton(ButtonType.OK).setDisable(newError != null); }; - final Set allPvs = AlarmTreeHelper.getLeafItems(model.getRoot()) - .stream() - .map(AlarmTreeItem::getName) - .collect(Collectors.toSet()); // Done once at start so we don't have to keep calling it in listener + final Set allPvs = AlarmTreeHelper.getLeafNames(model.getRoot()); input.textProperty().addListener(_ -> { // Show error and disable OK if text is empty if (input.getText().isEmpty()) { diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java index 4587788b21..e4fa3cf6db 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java @@ -49,6 +49,10 @@ public RenameTreeItemAction(final TreeView> node, if (new_name == null) return; + // Tree view keeps the selection indices, which will point to wrong content + // after those items have been removed + node.getSelectionModel().clearSelection(); + // Delete old, rebuild child links, and add new name in background thread. JobManager.schedule(getText(), monitor -> { diff --git a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties index 5be41bd626..ce5acaaca2 100644 --- a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties +++ b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties @@ -26,7 +26,6 @@ Annunciator=Annunciator alarmCount=Alarm Count [within delay]: alarmCountTooltip=Alarms are indicated when they occur this often within the delay alarmDelay=Alarm Delay [seconds]: -alreadyHasItem='{0}' already has an item '{1}' annunciate=Annunciate annunciateTooltip=Request audible alarm annunciation (using the description)? automatedActions=Automated Actions: @@ -34,8 +33,6 @@ behavior=Behavior: behaviorTooltip=Enable alarms? See also 'Enabling Filter' commands=Commands: configure=Configure -copyChildrenDialogTitle=Copy children? -copyChildrenDialogHeader=Copy the children of this node too? cutPasteAcrossConfigs=You cannot cut and paste a component across configs.\nInstead, copy the component across and then delete the original. cutPasteIntoChild=You cannot cut and paste a component into itself or one of its children dateTimePickerTooltip=Select a date until which the alarm should be disabled @@ -62,6 +59,7 @@ enablingFilterTooltip=Optional expression for enabling the alarm error=Error enableAlarmFailed=Failed to enable alarm enableAlarms=Enable Alarms +enterNameForDuplicate=Enter name for duplicate enterNewName=Enter new name guidance=Guidance: headerAlreadyDisabled=All PVs in the selected section are already disabled From 8744c54365c4183b0f2efa27bd65b50bdfa03fa4 Mon Sep 17 00:00:00 2001 From: Percy Baker Date: Thu, 19 Nov 2026 10:47:42 +0000 Subject: [PATCH 10/10] use max instead of pref height --- .../org/phoebus/applications/alarm/ui/tree/PasteItemAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java index b447d21ee1..033b4f1781 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/PasteItemAction.java @@ -126,7 +126,7 @@ public PasteItemAction( pvPane.getChildren().add(new Label(pv)); } final ScrollPane scrollPane = new ScrollPane(pvPane); - scrollPane.setPrefHeight(400.0); + scrollPane.setMaxHeight(400.0); alert.getDialogPane().setContent(scrollPane); alert.show();