Skip to content

Commit

Permalink
Merge pull request #2142 from ControlSystemStudio/CSSTUDIO-1614
Browse files Browse the repository at this point in the history
Support copy of multiple PVs to clipboard
  • Loading branch information
georgweiss authored Feb 18, 2022
2 parents 3127f90 + a8c835c commit b6bc534
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<WidgetProperty<String>> name_prop = widget.checkProperty(CommonWidgetProperties.propPVName);
if (name_prop.isPresent())
pv_name = name_prop.get().getValue();
List<ProcessVariable> 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<RuntimePV> 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());
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected String createText(final List<ProcessVariable> pvs)
logger.log(Level.WARNING, "Cannot show value for " + pv);
}

buf.append("\n");
buf.append(System.lineSeparator());
}
return buf.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Class<?> getSupportedType()

protected String createText(final List<ProcessVariable> pvs)
{
return pvs.stream().map(ProcessVariable::getName).collect(Collectors.joining(" "));
return pvs.stream().map(ProcessVariable::getName).collect(Collectors.joining(System.lineSeparator()));
}

@Override
Expand Down

0 comments on commit b6bc534

Please sign in to comment.