Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support copy of multiple PVs to clipboard #2142

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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