Skip to content

Commit 2df512a

Browse files
committed
Get the description from VType first or PV using DisplayProvider
interface, add a list of PV in the PVTable using TextArea
1 parent 85ce312 commit 2df512a

File tree

5 files changed

+92
-38
lines changed

5 files changed

+92
-38
lines changed

app/pvtable/src/main/java/org/phoebus/applications/pvtable/model/PVTableItem.java

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.epics.vtype.Alarm;
1919
import org.epics.vtype.AlarmSeverity;
2020
import org.epics.vtype.AlarmStatus;
21+
import org.epics.vtype.Display;
22+
import org.epics.vtype.DisplayProvider;
2123
import org.epics.vtype.Time;
2224
import org.epics.vtype.VByteArray;
2325
import org.epics.vtype.VEnum;
@@ -30,6 +32,7 @@
3032
import org.phoebus.core.vtypes.VTypeHelper;
3133
import org.phoebus.pv.PV;
3234
import org.phoebus.pv.PVPool;
35+
import org.phoebus.pv.PVPool.TypedName;
3336

3437
import io.reactivex.rxjava3.disposables.Disposable;
3538

@@ -51,7 +54,7 @@ public class PVTableItem
5154
private volatile VType value;
5255

5356
/** Value of the PV's description */
54-
private volatile String desc_value = "";
57+
private volatile String desc_value = null;
5558
private volatile String desc_name = "";
5659

5760
/** Saved (snapshot) value */
@@ -126,16 +129,24 @@ private void createPVs(final String name)
126129
updateValue(null);
127130
return;
128131
}
132+
PV new_pv = null;
129133
try
130134
{
131135
updateValue(VString.of("", Alarm.disconnected(), Time.now()));
132-
final PV new_pv = PVPool.getPV(name);
136+
new_pv = PVPool.getPV(name);
133137
value_flow = new_pv.onValueEvent()
134138
.throttleLatest(Settings.max_update_period_ms, TimeUnit.MILLISECONDS)
135139
.subscribe(this::updateValue);
136140
permission_flow = new_pv.onAccessRightsEvent()
137141
.subscribe(writable -> listener.tableItemChanged(PVTableItem.this));
138142
pv.set(new_pv);
143+
// read the value for getting description
144+
if (new_pv != null) {
145+
VType newVal = new_pv.read();
146+
if(newVal != null){
147+
updateValue(newVal);
148+
}
149+
}
139150
}
140151
catch (Exception ex)
141152
{
@@ -145,28 +156,23 @@ private void createPVs(final String name)
145156
Time.now()));
146157
}
147158

148-
// For CA PVs, check the .DESC field
149-
// Hardcoded knowledge to avoid non-record PVs.
150-
if (Settings.show_description &&
151-
! (name.startsWith("sim:") ||
152-
name.startsWith("loc:")))
153-
{
154-
// Determine DESC field.
155-
//Bug when a pv name contains a . caracters
156-
desc_name = name + DOT + DESC_FIELD;
157-
if(!name.endsWith(DOT + DESC_FIELD) && name.contains(DOT)) {
158-
// If name already includes a field
159-
// It can be a EPICS fields such as .VAL .EGU ...
160-
// EPICS fields are always in Upper Case
161-
// EPICS fields are 4 characters length max
159+
// First try to get description from value or pv
160+
updateDescription();
161+
// If still no description found and channel access source
162+
final TypedName type_name = TypedName.analyze(name);
163+
String dataType = type_name != null ? type_name.type : null;
164+
boolean channelAccess = dataType.equals("ca");
165+
if (Settings.show_description && desc_value == null && channelAccess) {
166+
// For CA PVs, check the .DESC field
167+
// Hardcoded knowledge to avoid non-record PVs.
168+
// First get default datasource
169+
desc_name = name + DOT + DESC_FIELD; // by default add .DESC
170+
if (!name.endsWith(DOT + DESC_FIELD) && name.contains(DOT)) {
162171
final int sep = name.lastIndexOf('.');
163172
String fieldVal = name.substring(sep + 1);
164-
//System.out.println("fieldVal=" + fieldVal);
165-
//Test if it in uppercase and max length 4
166-
boolean isEpicsField = fieldVal.toUpperCase().equals(fieldVal) && fieldVal.length() < 5;
167-
if(isEpicsField) {
168-
desc_name = name.replace(fieldVal, DESC_FIELD);
169-
}
173+
// then replace by .DESC
174+
// Determine DESC field include dot in case of variable name such as variableEGUName
175+
desc_name = name.replace(DOT + fieldVal, DOT + DESC_FIELD);
170176
}
171177

172178
try
@@ -190,6 +196,24 @@ private void createPVs(final String name)
190196
}
191197
}
192198
}
199+
200+
private void updateDescription() {
201+
if(desc_value == null) {
202+
//update description from value or pv
203+
VType currentValue = getValue();
204+
if(currentValue != null) {
205+
PV thePV = pv.get();
206+
Display display = thePV instanceof DisplayProvider ? ((DisplayProvider) thePV).getDisplay() : null;
207+
display = display == null && currentValue instanceof DisplayProvider ? ((DisplayProvider) currentValue).getDisplay(): display;
208+
if (display != null) {
209+
String description = display.getDescription();
210+
desc_value = description != null ? description : null;
211+
desc_name = desc_value != null ? "Description of " + name + " PV" : "no description";
212+
desc_flow = value_flow;
213+
}
214+
}
215+
}
216+
}
193217

194218
/** @return <code>true</code> if item is selected to be restored */
195219
public boolean isSelected()
@@ -255,9 +279,8 @@ public VType getValue()
255279
}
256280

257281
/** @return Description */
258-
public String getDescription()
259-
{
260-
return desc_value;
282+
public String getDescription() {
283+
return desc_value == null ? "" : desc_value;
261284
}
262285

263286
/** @return description pv name **/
@@ -305,14 +328,17 @@ public void setValue(String new_value)
305328
throw new Exception("Not connected");
306329

307330
final VType pv_type = the_pv.read();
308-
if (pv_type instanceof VNumber)
309-
{
310-
if (Settings.show_units)
311-
{ // Strip units so that only the number gets written
312-
final String units = ((VNumber)pv_type).getDisplay().getUnit();
313-
if (units.length() > 0 && new_value.endsWith(units))
331+
Display display = the_pv instanceof DisplayProvider ? ((DisplayProvider) the_pv).getDisplay() : null;
332+
display = display == null && pv_type instanceof DisplayProvider ? ((DisplayProvider) pv_type).getDisplay():null;
333+
334+
if (display != null && Settings.show_units) {
335+
// Strip units so that only the number gets written
336+
final String units = display.getUnit();
337+
if (units.length() > 0 && new_value.endsWith(units))
314338
new_value = new_value.substring(0, new_value.length() - units.length()).trim();
315339
}
340+
if (pv_type instanceof VNumber)
341+
{
316342
the_pv.write(Double.parseDouble(new_value));
317343
}
318344
else if (pv_type instanceof VEnum)

app/pvtable/src/main/java/org/phoebus/applications/pvtable/ui/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Messages
1414
{
1515
/** Externalized strings */
1616
public static String Alarm,
17+
AddPVList,
1718
Description,
1819
CheckAll,
1920
CheckAll_TT,

app/pvtable/src/main/java/org/phoebus/applications/pvtable/ui/PVTable.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
import javafx.scene.control.TableRow;
7070
import javafx.scene.control.TableView;
7171
import javafx.scene.control.TableView.TableViewSelectionModel;
72+
import javafx.scene.control.TextArea;
7273
import javafx.scene.control.TextField;
74+
import javafx.scene.control.TextInputControl;
7375
import javafx.scene.control.ToolBar;
7476
import javafx.scene.control.Tooltip;
7577
import javafx.scene.control.cell.TextFieldTableCell;
@@ -93,6 +95,7 @@ public class PVTable extends VBox
9395
private static final String comment_style = "-fx-text-fill: blue;";
9496
private static final String new_item_style = "-fx-text-fill: gray;";
9597
private static final String changed_style = "-fx-background-color: -fx-table-cell-border-color, cyan;-fx-background-insets: 0, 0 0 1 0;";
98+
private static final String SPLIT_PV = "[ \\t\\n\\r,]+";
9699

97100
/** When sorting, keep the 'NEW_ITEM' row at the bottom **/
98101
private static final Comparator<TableItemProxy> SORT_NEW_ITEM_LAST = (a, b) ->
@@ -184,8 +187,9 @@ protected void updateItem(final String item, final boolean empty)
184187
/** Table cell for 'name' column, colors comments */
185188
private static class PVNameTableCell extends TextFieldTableCell<TableItemProxy, String>
186189
{
187-
private TextField textField;
188-
190+
private TextInputControl textField;
191+
private static ContextMenu contextMenu;
192+
189193
public PVNameTableCell()
190194
{
191195
super(new DefaultStringConverter());
@@ -195,11 +199,26 @@ public PVNameTableCell()
195199
public void startEdit()
196200
{
197201
super.startEdit();
198-
textField = new TextField();
199-
textField.setOnAction(event -> commitEdit(textField.getText()));
202+
final int index = getIndex();
203+
boolean newPv = index == getTableView().getItems().size() - 1;
204+
if(newPv) {
205+
textField = new TextArea();
206+
textField.setMaxHeight(100);
207+
if(contextMenu == null) {
208+
MenuItem addPVMenu = new MenuItem(Messages.AddPVList);
209+
addPVMenu.setOnAction(event -> commitEdit(textField.getText()));
210+
contextMenu = new ContextMenu(addPVMenu);
211+
}
212+
textField.setContextMenu(contextMenu);
213+
}
214+
else {
215+
textField = new TextField();
216+
((TextField)textField).setOnAction(event -> commitEdit(textField.getText()));
217+
}
200218
PVAutocompleteMenu.INSTANCE.attachField(textField);
201219
showCurrentValue();
202220
}
221+
203222

204223
private void showCurrentValue()
205224
{
@@ -775,8 +794,14 @@ private void createTableColumns()
775794
final TableItemProxy proxy = event.getRowValue();
776795
if (proxy == TableItemProxy.NEW_ITEM)
777796
{
778-
if (!new_name.isEmpty())
779-
model.addItem(new_name);
797+
if (!new_name.isEmpty()) {
798+
//Can be a list of pv
799+
final String[] pvs = new_name.split(SPLIT_PV);
800+
//Add a list
801+
for(String pv : pvs) {
802+
model.addItem(pv);
803+
}
804+
}
780805
// else: No name entered, do nothing
781806
}
782807
else
@@ -976,7 +1001,7 @@ else if (db.hasString())
9761001

9771002
private void addPVsFromString(final PVTableItem existing, final String pv_text)
9781003
{
979-
final String[] pvs = pv_text.split("[ \\t\\n\\r,]+");
1004+
final String[] pvs = pv_text.split(SPLIT_PV);
9801005
for (String pv : pvs)
9811006
if (! pv.isEmpty())
9821007
model.addItemAbove(existing, pv);

app/pvtable/src/main/resources/org/phoebus/applications/pvtable/ui/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Alarm=Alarm
2+
AddPVList=Add a list of pv
23
Description=Description
34
CheckAll=Check All
45
CheckAll_TT=Check all PVs in table

app/pvtable/src/main/resources/org/phoebus/applications/pvtable/ui/messages_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Alarm=Alarme
2+
AddPVList=Ajout d une liste de pv
23
Description=Description
34
CheckAll=Tout sélectionner
45
CheckAll_TT=Sélectionner tous les PVs dans le tableau

0 commit comments

Comments
 (0)