From a8c835c744d7c9b5883259410e825fa4514a7b80 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Tue, 15 Feb 2022 12:41:35 +0100 Subject: [PATCH] Support copy of multiple PVs to clipboard --- .../runtime/app/ContextMenuSupport.java | 34 ++++++++----------- .../ContextMenuPvAndValueToClipboard.java | 2 +- .../probe/ContextMenuPvToClipboard.java | 2 +- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/app/ContextMenuSupport.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/app/ContextMenuSupport.java index 59f73e68d3..cbd296a063 100644 --- a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/app/ContextMenuSupport.java +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/app/ContextMenuSupport.java @@ -47,11 +47,14 @@ import org.phoebus.ui.javafx.PrintAction; import org.phoebus.ui.spi.ContextMenuEntry; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.logging.Level; +import java.util.stream.Collectors; import static org.csstudio.display.builder.runtime.WidgetRuntime.logger; @@ -153,24 +156,22 @@ private void fillMenu(final Node node, final Widget widget) items.add(new SeparatorMenuItem()); - // Add PV-based contributions - String pv_name = ""; // Does widget have a PV name? final Optional> name_prop = widget.checkProperty(CommonWidgetProperties.propPVName); - if (name_prop.isPresent()) - pv_name = name_prop.get().getValue(); + List processVariables; + if (name_prop.isPresent()){ + processVariables = List.of(new ProcessVariable(name_prop.get().getValue())); + } else - { // See if there are runtime PVs, pick the first one - for (RuntimePV pv : runtime.getPVs()) - { - pv_name = pv.getName(); - break; - } + { // Add all PVs referenced by the widget. + Collection runtimePvs = runtime.getPVs(); + processVariables = + runtimePvs.stream().map(runtimePV -> new ProcessVariable(runtimePV.getName())).collect(Collectors.toList()); } - if (!pv_name.isEmpty()) + if (!processVariables.isEmpty()) { // Set the 'selection' to the PV of this widget - SelectionService.getInstance().setSelection(DisplayRuntimeApplication.NAME, List.of(new ProcessVariable(pv_name))); + SelectionService.getInstance().setSelection(DisplayRuntimeApplication.NAME, processVariables); // Add PV-based menu entries ContextMenuHelper.addSupportedEntries(node, menu); items.add(new SeparatorMenuItem()); @@ -205,16 +206,9 @@ private void fillMenu(final Node node, final Widget widget) items.add(new SaveSnapshotAction(model_parent)); - String display_info; try { final DisplayModel model = widget.getDisplayModel(); - final String name = model.getDisplayName(); - final String input = model.getUserData(DisplayModel.USER_DATA_INPUT_FILE); - if (Objects.equals(name, input)) - display_info = "Display '" + name + "'"; - else - display_info = "Display '" + name + "' (" + input + ")"; // Add context menu actions based on the selection (i.e. email, logbook, etc...) final Selection originalSelection = SelectionService.getInstance().getSelection(); @@ -237,7 +231,7 @@ private void fillMenu(final Node node, final Widget widget) } catch (Exception ex) { - display_info = "See attached display"; + logger.log(Level.WARNING, "Failed to construct context menu actions", ex); } items.add(new SeparatorMenuItem()); diff --git a/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvAndValueToClipboard.java b/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvAndValueToClipboard.java index 867e008ebb..11615ef796 100644 --- a/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvAndValueToClipboard.java +++ b/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvAndValueToClipboard.java @@ -86,7 +86,7 @@ protected String createText(final List pvs) logger.log(Level.WARNING, "Cannot show value for " + pv); } - buf.append("\n"); + buf.append(System.lineSeparator()); } return buf.toString(); } diff --git a/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvToClipboard.java b/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvToClipboard.java index 95393a1b3d..20ffe941f4 100644 --- a/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvToClipboard.java +++ b/app/probe/src/main/java/org/phoebus/applications/probe/ContextMenuPvToClipboard.java @@ -53,7 +53,7 @@ public Class getSupportedType() protected String createText(final List pvs) { - return pvs.stream().map(ProcessVariable::getName).collect(Collectors.joining(" ")); + return pvs.stream().map(ProcessVariable::getName).collect(Collectors.joining(System.lineSeparator())); } @Override