Skip to content

Commit 0ed4488

Browse files
committed
CSSTUDIO-2072 Remove the possibility to represent Display Names on the clipboard by surrounding them with sinqle-quote characters. If a Display Name is not entered, use the default for the Display Name.
1 parent 6652661 commit 0ed4488

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

app/databrowser/src/main/java/org/csstudio/trends/databrowser3/Activator.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,14 @@ public static ImageView getIcon(final String base_name)
8686
return new ImageView(getImage(base_name));
8787
}
8888

89-
public static void addPVsToPlotDialog(List<String> names,
89+
public static void addPVsToPlotDialog(List<String> pvNames,
9090
UndoableActionManager undoableActionManager,
9191
Model model,
9292
Node nodeToPositionDialogOver)
9393
{
94-
List<Pair<String, String>> namesWithDisplayNames = new ArrayList<>();
95-
Optional<String> currentPVName = Optional.empty();
96-
for (String name : names) {
97-
if (name.startsWith("'") && name.endsWith("'") && name.length() >= 2) {
98-
if (currentPVName.isPresent()) {
99-
namesWithDisplayNames.add(new Pair<>(currentPVName.get(), name.substring(1,name.length()-1)));
100-
currentPVName = Optional.empty();
101-
}
102-
}
103-
else {
104-
if (currentPVName.isPresent()) {
105-
namesWithDisplayNames.add(new Pair<>(currentPVName.get(), currentPVName.get()));
106-
}
107-
currentPVName = currentPVName.of(name);
108-
}
109-
}
110-
if (currentPVName.isPresent()) {
111-
namesWithDisplayNames.add(new Pair<>(currentPVName.get(), currentPVName.get()));
112-
}
11394
// Offer potential PV name in dialog so user can edit/cancel
11495
// sim://sine sim://ramp sim://noise
115-
AddPVDialog addPVDialog = new AddPVDialog(namesWithDisplayNames.size(), model, false);
96+
AddPVDialog addPVDialog = new AddPVDialog(pvNames.size(), model, false);
11697

11798
{ // Set layout of addPVDialog:
11899
int addPVDialogWidth = 750;
@@ -132,15 +113,15 @@ public static void addPVsToPlotDialog(List<String> names,
132113
DialogHelper.positionDialog(addPVDialog, nodeToPositionDialogOver, (int) -addPVDialowWindow.getWidth()/2, (int) -addPVDialowWindow.getHeight()/2);
133114
}
134115

135-
for (int i=0; i<namesWithDisplayNames.size(); ++i) {
136-
addPVDialog.setNameAndDisplayName(i, namesWithDisplayNames.get(i));
116+
for (int i=0; i<pvNames.size(); ++i) {
117+
addPVDialog.setNameAndDisplayName(i, pvNames.get(i));
137118
}
138119

139120
if (!addPVDialog.showAndWait().orElse(false)) {
140121
return;
141122
}
142123

143-
for (int i=0; i<namesWithDisplayNames.size(); ++i) {
124+
for (int i=0; i<pvNames.size(); ++i) {
144125
AxisConfig axis = addPVDialog.getOrCreateAxis(model, undoableActionManager, addPVDialog.getAxisIndex(i));
145126
AddModelItemCommand.forPV(undoableActionManager,
146127
model,

app/databrowser/src/main/java/org/csstudio/trends/databrowser3/imports/SampleImportAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.io.File;
1111
import java.text.MessageFormat;
12+
import java.util.Optional;
1213

1314
import org.csstudio.trends.databrowser3.Activator;
1415
import org.csstudio.trends.databrowser3.Messages;
@@ -64,7 +65,7 @@ private void run()
6465
final ArchiveDataSource imported = new ArchiveDataSource(url, type);
6566
// Add PV Item with data to model
6667
AddModelItemCommand.forPV(op_manager, model,
67-
type, type, Preferences.scan_period, axis, imported);
68+
type, Optional.empty(), Preferences.scan_period, axis, imported);
6869
}
6970
catch (Exception ex)
7071
{

app/databrowser/src/main/java/org/csstudio/trends/databrowser3/ui/AddModelItemCommand.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.csstudio.trends.databrowser3.ui;
99

1010
import java.text.MessageFormat;
11+
import java.util.Optional;
1112

1213
import org.csstudio.trends.databrowser3.Messages;
1314
import org.csstudio.trends.databrowser3.model.ArchiveDataSource;
@@ -34,6 +35,7 @@ public class AddModelItemCommand extends UndoableAction
3435
* @param operations_manager OperationsManager where command will be reg'ed
3536
* @param model Model were PV is to be added
3637
* @param pv_name Name of new PV
38+
* @param optional_display_name Optional Display Name to associate with the PV
3739
* @param period scan period
3840
* @param axis Axis
3941
* @param archive Archive data source
@@ -43,7 +45,7 @@ public static AddModelItemCommand forPV(
4345
final UndoableActionManager operations_manager,
4446
final Model model,
4547
final String pv_name,
46-
final String display_name,
48+
final Optional<String> optional_display_name,
4749
final double period,
4850
final AxisConfig axis,
4951
final ArchiveDataSource archive)
@@ -53,7 +55,9 @@ public static AddModelItemCommand forPV(
5355
try
5456
{
5557
item = new PVItem(pv_name, period);
56-
item.setDisplayName(display_name);
58+
if (optional_display_name.isPresent()) {
59+
item.setDisplayName(optional_display_name.get());
60+
}
5761
if (archive != null)
5862
item.addArchiveDataSource(archive);
5963
else

app/databrowser/src/main/java/org/csstudio/trends/databrowser3/ui/AddPVDialog.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.text.MessageFormat;
1111
import java.util.ArrayList;
1212
import java.util.List;
13+
import java.util.Optional;
1314
import java.util.stream.Collectors;
1415

1516
import javafx.scene.control.Button;
@@ -237,12 +238,13 @@ private Node createContent(final Model model, final int count)
237238

238239
/** Set initial name. Only effective when called before dialog is opened.
239240
* @param i Index
240-
* @param nameAndDisplayName Suggested name
241+
* @param pvName Suggested name
241242
*/
242-
public void setNameAndDisplayName(final int i, final Pair<String, String> nameAndDisplayName)
243+
public void setNameAndDisplayName(final int i, final String pvName)
243244
{
244-
nameAndDisplayNames.get(i).getKey().setText(nameAndDisplayName.getKey());
245-
nameAndDisplayNames.get(i).getValue().setText(nameAndDisplayName.getValue());
245+
nameAndDisplayNames.get(i).getKey().setText(pvName);
246+
nameAndDisplayNames.get(i).getValue().setText("");
247+
nameAndDisplayNames.get(i).getValue().setPromptText("Default");
246248
}
247249

248250
/** @param i Index
@@ -254,11 +256,17 @@ public String getName(final int i)
254256
}
255257

256258
/** @param i Index
257-
* @return Display name associated with PV
259+
* @return Optionally, the display name to be associated with the PV in the Data Browser
258260
*/
259-
public String getDisplayName(final int i)
261+
public Optional<String> getDisplayName(final int i)
260262
{
261-
return nameAndDisplayNames.get(i).getValue().getText().trim();
263+
String trimmedDisplayName = nameAndDisplayNames.get(i).getValue().getText().trim();
264+
if (trimmedDisplayName.isEmpty()) {
265+
return Optional.empty();
266+
}
267+
else {
268+
return Optional.of(trimmedDisplayName);
269+
}
262270
}
263271

264272
/** @param i Index

app/databrowser/src/main/java/org/csstudio/trends/databrowser3/ui/Controller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public void droppedPVNames(List<ProcessVariable> names,
279279
DialogHelper.positionDialog(dlg, plot.getPlot(), -200, -200);
280280
for (int i=0; i<names.size(); ++i) {
281281
String pvName = names.get(i).getName();
282-
dlg.setNameAndDisplayName(i, new Pair(pvName, pvName));
282+
dlg.setNameAndDisplayName(i, pvName);
283283
}
284284
if (! dlg.showAndWait().orElse(false))
285285
return;

app/databrowser/src/main/java/org/csstudio/trends/databrowser3/ui/search/AddToPlotAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.csstudio.trends.databrowser3.ui.search;
99

1010
import java.util.List;
11+
import java.util.Optional;
1112

1213
import javafx.util.Pair;
1314
import org.csstudio.trends.databrowser3.Activator;
@@ -50,7 +51,7 @@ public AddToPlotAction(final Node node, final Model model, final UndoableActionM
5051
DialogHelper.positionDialog(dlg, node, 200, -200);
5152
for (int i=0; i<channels.size(); ++i) {
5253
String channelName = channels.get(i).getName();
53-
dlg.setNameAndDisplayName(i, new Pair(channelName, channelName));
54+
dlg.setNameAndDisplayName(i, channelName);
5455
}
5556
if (! dlg.showAndWait().orElse(false))
5657
return;
@@ -61,7 +62,7 @@ public AddToPlotAction(final Node node, final Model model, final UndoableActionM
6162
final AxisConfig axis = dlg.getOrCreateAxis(model, undo, dlg.getAxisIndex(i));
6263
AddModelItemCommand.forPV(undo, model,
6364
channel.getName(),
64-
channel.getName(),
65+
Optional.empty(),
6566
0.0,
6667
axis,
6768
channel.getArchiveDataSource());

0 commit comments

Comments
 (0)