Skip to content

Commit ff4be72

Browse files
committed
Refactoring/cleanup
1 parent 0aaabd5 commit ff4be72

File tree

3 files changed

+90
-38
lines changed

3 files changed

+90
-38
lines changed

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SaveAndRestorePV.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ public class SaveAndRestorePV {
4545
private PV readbackPv;
4646
private VType pvValue = VDisconnectedData.INSTANCE;
4747
private VType readbackValue = VDisconnectedData.INSTANCE;
48-
private TableEntry snapshotTableEntry;
48+
//private TableEntry snapshotTableEntry;
4949

5050
/**
5151
* The time between updates of dynamic data in the table, in ms.
5252
*/
5353
private static final long TABLE_UPDATE_INTERVAL = 500;
5454

5555
protected SaveAndRestorePV(TableEntry snapshotTableEntry) {
56-
this.snapshotTableEntry = snapshotTableEntry;
56+
//this.snapshotTableEntry = snapshotTableEntry;
5757
this.pvName = patchPvName(snapshotTableEntry.pvNameProperty().get());
5858
this.readbackPvName = patchPvName(snapshotTableEntry.readbackNameProperty().get());
5959

6060
try {
6161
pv = PVPool.getPV(pvName);
6262
pv.onValueEvent().throttleLatest(TABLE_UPDATE_INTERVAL, TimeUnit.MILLISECONDS).subscribe(value -> {
6363
pvValue = org.phoebus.pv.PV.isDisconnected(value) ? VDisconnectedData.INSTANCE : value;
64-
this.snapshotTableEntry.setLiveValue(pvValue);
64+
snapshotTableEntry.setLiveValue(pvValue);
6565
});
6666

6767
if (readbackPvName != null && !readbackPvName.isEmpty()) {
@@ -70,11 +70,11 @@ protected SaveAndRestorePV(TableEntry snapshotTableEntry) {
7070
.throttleLatest(TABLE_UPDATE_INTERVAL, TimeUnit.MILLISECONDS)
7171
.subscribe(value -> {
7272
this.readbackValue = org.phoebus.pv.PV.isDisconnected(value) ? VDisconnectedData.INSTANCE : value;
73-
this.snapshotTableEntry.setReadbackValue(this.readbackValue);
73+
snapshotTableEntry.setReadbackValue(this.readbackValue);
7474
});
7575
} else {
7676
// If configuration does not define read-back PV, then UI should show "no data" rather than "disconnected"
77-
this.snapshotTableEntry.setReadbackValue(VNoData.INSTANCE);
77+
snapshotTableEntry.setReadbackValue(VNoData.INSTANCE);
7878
}
7979
} catch (Exception e) {
8080
Logger.getLogger(SaveAndRestorePV.class.getName()).log(Level.INFO, "Error connecting to PV", e);
@@ -99,11 +99,14 @@ public void countDown() {
9999
this.countDownLatch.countDown();
100100
}
101101

102+
/*
102103
public void setSnapshotTableEntry(TableEntry snapshotTableEntry) {
103104
this.snapshotTableEntry = snapshotTableEntry;
104105
this.snapshotTableEntry.setLiveValue(pv.read());
105106
}
106107
108+
*/
109+
107110
void dispose() {
108111
if (pv != null) {
109112
PVPool.releasePV(pv);

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public class SnapshotController extends SaveAndRestoreBaseController implements
280280
@FXML
281281
protected VBox progressIndicator;
282282

283-
protected final Map<String, SaveAndRestorePV> pvs = new HashMap<>();
283+
//protected final Map<String, SaveAndRestorePV> pvs = new HashMap<>();
284284

285285
protected Node configurationNode;
286286

@@ -347,6 +347,7 @@ public class SnapshotController extends SaveAndRestoreBaseController implements
347347
* determine which elements in the {@link Map} to actually represent.
348348
*/
349349
protected final Map<String, TableEntry> tableEntryItems = new LinkedHashMap<>();
350+
//protected final List<TableEntry> tableEntries = new ArrayList<>();
350351

351352
public SnapshotController(SnapshotTab snapshotTab) {
352353
snapshotTab.textProperty().bind(tabTitleProperty);
@@ -484,10 +485,17 @@ public void initialize() {
484485
this.showDeltaPercentage.set(n));
485486

486487
hideEqualItemsButton.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/hide_show_equal_items.png"))));
488+
hideEqualItemsButton.selectedProperty().bindBidirectional(hideEqualItemsProperty);
489+
hideEqualItemsProperty.addListener((obs, o, n) -> updateTable());
490+
/*
487491
hideEqualItemsProperty.bind(hideEqualItemsButton.selectedProperty());
488492
hideEqualItemsButton.selectedProperty()
489493
.addListener((a, o, n) ->
494+
495+
490496
hideEqualItems());
497+
498+
*/
491499

492500
logAction.selectedProperty().bindBidirectional(logActionProperty);
493501

@@ -876,7 +884,8 @@ public boolean handleTabClosed() {
876884
* Releases PV resources.
877885
*/
878886
private void dispose() {
879-
pvs.values().forEach(SaveAndRestorePV::dispose);
887+
//pvs.values().forEach(SaveAndRestorePV::dispose);
888+
tableEntryItems.values().forEach(tableEntry -> tableEntry.getSaveAndRestorePV().dispose());
880889
}
881890

882891
private void showLoggingError(String cause) {
@@ -1265,11 +1274,14 @@ private void applyPreserveSelection(boolean preserve) {
12651274
}
12661275
}
12671276

1277+
/*
12681278
private void hideEqualItems() {
12691279
ArrayList<TableEntry> arrayList = new ArrayList<>(tableEntryItems.values());
12701280
Platform.runLater(() -> updateTable(arrayList));
12711281
}
12721282
1283+
*/
1284+
12731285
/**
12741286
* Restores a snapshot from client or service.
12751287
*
@@ -1418,29 +1430,28 @@ private void addSnapshot(Snapshot snapshot) {
14181430
for (int s = 1; s < snapshots.size(); s++) {
14191431
Node snapshotNode = snapshots.get(s).getSnapshotNode();
14201432
String snapshotName = snapshotNode.getName();
1421-
14221433
List<SnapshotItem> entries = snapshot.getSnapshotData().getSnapshotItems();
14231434
String nodeName;
14241435
TableEntry tableEntry;
14251436
// Base snapshot data
14261437
List<TableEntry> baseSnapshotTableEntries = new ArrayList<>(tableEntryItems.values());
1427-
SnapshotItem entry;
1438+
SnapshotItem snpshotItem;
14281439
for (int i = 0; i < entries.size(); i++) {
1429-
entry = entries.get(i);
1430-
nodeName = entry.getConfigPv().getPvName();
1440+
snpshotItem = entries.get(i);
1441+
nodeName = snpshotItem.getConfigPv().getPvName();
14311442
tableEntry = tableEntryItems.get(nodeName);
14321443
// tableEntry is null if the added snapshot has more items than the base snapshot.
14331444
if (tableEntry == null) {
1434-
tableEntry = new TableEntry();
1445+
tableEntry = new TableEntry(snpshotItem);
14351446
tableEntry.idProperty().setValue(tableEntryItems.size() + i + 1);
1436-
tableEntry.pvNameProperty().setValue(nodeName);
1437-
tableEntry.setConfigPv(entry.getConfigPv());
1447+
//tableEntry.pvNameProperty().setValue(nodeName);
1448+
//tableEntry.setConfigPv(snpshotItem.getConfigPv());
14381449
tableEntryItems.put(nodeName, tableEntry);
1439-
tableEntry.readbackNameProperty().set(entry.getConfigPv().getReadbackPvName());
1450+
//tableEntry.readbackNameProperty().set(snpshotItem.getConfigPv().getReadbackPvName());
14401451
}
1441-
tableEntry.setSnapshotValue(entry.getValue(), snapshots.size());
1442-
tableEntry.setStoredReadbackValue(entry.getReadbackValue(), snapshots.size());
1443-
tableEntry.readOnlyProperty().set(entry.getConfigPv().isReadOnly());
1452+
tableEntry.setSnapshotValue(snpshotItem.getValue(), snapshots.size());
1453+
tableEntry.setStoredReadbackValue(snpshotItem.getReadbackValue(), snapshots.size());
1454+
//tableEntry.readOnlyProperty().set(snpshotItem.getConfigPv().isReadOnly());
14441455
baseSnapshotTableEntries.remove(tableEntry);
14451456
}
14461457
// If added snapshot has more items than base snapshot, the base snapshot's values for those
@@ -1487,8 +1498,8 @@ private void addSnapshot(Snapshot snapshot) {
14871498

14881499
snapshotTableView.getColumns().addAll(columns);
14891500

1490-
connectPVs();
1491-
updateTable(null);
1501+
//connectPVs();
1502+
updateTable();
14921503
}
14931504

14941505
private void showSnapshotInTable() {
@@ -1498,36 +1509,43 @@ private void showSnapshotInTable() {
14981509
snapshots.set(0, snapshot);
14991510
}
15001511
AtomicInteger counter = new AtomicInteger(0);
1501-
snapshot.getSnapshotData().getSnapshotItems().forEach(entry -> {
1502-
TableEntry tableEntry = new TableEntry();
1503-
String name = entry.getConfigPv().getPvName();
1512+
snapshot.getSnapshotData().getSnapshotItems().forEach(snapshotItem -> {
1513+
TableEntry tableEntry = new TableEntry(snapshotItem);
1514+
String name = snapshotItem.getConfigPv().getPvName();
15041515
tableEntry.idProperty().setValue(counter.incrementAndGet());
1505-
tableEntry.pvNameProperty().setValue(name);
1506-
tableEntry.setConfigPv(entry.getConfigPv());
1507-
tableEntry.setSnapshotValue(entry.getValue(), 0);
1508-
tableEntry.setStoredReadbackValue(entry.getReadbackValue(), 0);
1509-
tableEntry.setReadbackValue(entry.getReadbackValue());
1510-
if (entry.getValue() == null || entry.getValue().equals(VDisconnectedData.INSTANCE)) {
1516+
//tableEntry.pvNameProperty().setValue(name);
1517+
//tableEntry.setConfigPv(snapshotItem.getConfigPv());
1518+
tableEntry.setSnapshotValue(snapshotItem.getValue(), 0);
1519+
tableEntry.setStoredReadbackValue(snapshotItem.getReadbackValue(), 0);
1520+
//tableEntry.setReadbackValue(snapshotItem.getReadbackValue());
1521+
/*
1522+
if (snapshotItem.getValue() == null || snapshotItem.getValue().equals(VDisconnectedData.INSTANCE)) {
15111523
tableEntry.setActionResult(ActionResult.FAILED);
15121524
}
15131525
else {
15141526
tableEntry.setActionResult(ActionResult.OK);
15151527
}
1516-
if (entry.getConfigPv().getReadbackPvName() != null){
1517-
if(entry.getReadbackValue() == null || entry.getReadbackValue().equals(VDisconnectedData.INSTANCE)) {
1528+
if (snapshotItem.getConfigPv().getReadbackPvName() != null){
1529+
if(snapshotItem.getReadbackValue() == null || snapshotItem.getReadbackValue().equals(VDisconnectedData.INSTANCE)) {
15181530
tableEntry.setActionResultReadback(ActionResult.FAILED);
15191531
}
15201532
else{
15211533
tableEntry.setActionResultReadback(ActionResult.OK);
15221534
}
15231535
}
1524-
tableEntry.readbackNameProperty().set(entry.getConfigPv().getReadbackPvName());
1525-
tableEntry.readOnlyProperty().set(entry.getConfigPv().isReadOnly());
1536+
1537+
*/
1538+
//tableEntry.readbackNameProperty().set(snapshotItem.getConfigPv().getReadbackPvName());
1539+
//tableEntry.readOnlyProperty().set(snapshotItem.getConfigPv().isReadOnly());
15261540
tableEntryItems.put(name, tableEntry);
15271541
});
15281542

1529-
updateTable(null);
1530-
connectPVs();
1543+
updateTable();
1544+
//connectPVs();
1545+
}
1546+
1547+
private void updateTable(){
1548+
updateTable(tableEntryItems.values().stream().toList());
15311549
}
15321550

15331551
/**
@@ -1540,7 +1558,7 @@ private void updateTable(List<TableEntry> entries) {
15401558
final boolean notHide = hideEqualItemsProperty.not().get();
15411559
Platform.runLater(() -> {
15421560
items.clear();
1543-
tableEntryItems.forEach((key, value) -> {
1561+
entries.forEach(value -> {
15441562
// there is no harm if this is executed more than once, because only one line is allowed for these
15451563
// two properties (see SingleListenerBooleanProperty for more details)
15461564
value.liveStoredEqualProperty().addListener((a, o, n) -> {
@@ -1579,6 +1597,7 @@ private int measureStringWidth(String text, Font font) {
15791597
* Attempts to connect to all the PVs of the configuration/snapshot and binds the created {@link SaveAndRestorePV} objects
15801598
* to the {@link TableEntry} objects matched on PV name.
15811599
*/
1600+
/*
15821601
private void connectPVs() {
15831602
JobManager.schedule("Connect PVs", monitor -> tableEntryItems.values().forEach(e -> {
15841603
SaveAndRestorePV pv = pvs.get(e.getConfigPv().getPvName());
@@ -1590,6 +1609,8 @@ private void connectPVs() {
15901609
}));
15911610
}
15921611
1612+
*/
1613+
15931614
/**
15941615
*
15951616
* @param configurationData {@link ConfigurationData} obejct of a {@link org.phoebus.applications.saveandrestore.model.Configuration}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/TableEntry.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.epics.vtype.VNumberArray;
2929
import org.epics.vtype.VType;
3030
import org.phoebus.applications.saveandrestore.model.ConfigPv;
31+
import org.phoebus.applications.saveandrestore.model.SnapshotItem;
3132
import org.phoebus.applications.saveandrestore.ui.SingleListenerBooleanProperty;
3233
import org.phoebus.saveandrestore.util.Threshold;
3334
import org.phoebus.saveandrestore.util.Utilities;
@@ -101,13 +102,13 @@ public class TableEntry {
101102
*/
102103
private final ObjectProperty<ActionResult> actionResultReadback = new SimpleObjectProperty<>(this, "actionResultReadback", ActionResult.PENDING);
103104

104-
105+
private SaveAndRestorePV saveAndRestorePV;
105106
private ConfigPv configPv;
106107

107108
/**
108109
* Construct a new table entry.
109110
*/
110-
public TableEntry() {
111+
public TableEntry(SnapshotItem snapshotItem) {
111112
//when read only is set to true, unselect this PV
112113
readOnly.addListener((a, o, n) -> {
113114
if (n) {
@@ -120,14 +121,41 @@ public TableEntry() {
120121
selected.set(false);
121122
}
122123
});
124+
readOnlyProperty().setValue(snapshotItem.getConfigPv().isReadOnly());
125+
pvNameProperty().set(snapshotItem.getConfigPv().getPvName());
126+
readbackNameProperty().set(snapshotItem.getConfigPv().getReadbackPvName());
127+
setReadbackValue(snapshotItem.getReadbackValue());
128+
if (snapshotItem.getValue() == null || snapshotItem.getValue().equals(VDisconnectedData.INSTANCE)) {
129+
setActionResult(ActionResult.FAILED);
130+
}
131+
else {
132+
setActionResult(ActionResult.OK);
133+
}
134+
if (snapshotItem.getConfigPv().getReadbackPvName() != null){
135+
if(snapshotItem.getReadbackValue() == null || snapshotItem.getReadbackValue().equals(VDisconnectedData.INSTANCE)) {
136+
setActionResultReadback(ActionResult.FAILED);
137+
}
138+
else{
139+
setActionResultReadback(ActionResult.OK);
140+
}
141+
}
142+
this.configPv = snapshotItem.getConfigPv();
143+
this.saveAndRestorePV = new SaveAndRestorePV(this);
144+
}
145+
146+
public SaveAndRestorePV getSaveAndRestorePV(){
147+
return saveAndRestorePV;
123148
}
124149

150+
/*
125151
public void setConfigPv(ConfigPv configPv) {
126152
this.configPv = configPv;
127153
pvName.setValue(configPv.getPvName());
128154
readbackName.setValue(configPv.getReadbackPvName());
129155
}
130156
157+
*/
158+
131159
public ConfigPv getConfigPv() {
132160
return configPv;
133161
}

0 commit comments

Comments
 (0)