Skip to content

Commit fc30d08

Browse files
committed
Update table cell rendering in snapshot view
1 parent 9b8f817 commit fc30d08

File tree

5 files changed

+160
-63
lines changed

5 files changed

+160
-63
lines changed

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

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import javafx.scene.text.Text;
5252
import javafx.util.converter.DoubleStringConverter;
5353
import org.epics.vtype.Alarm;
54+
import org.epics.vtype.AlarmSeverity;
5455
import org.epics.vtype.Display;
5556
import org.epics.vtype.Time;
5657
import org.epics.vtype.VEnum;
@@ -271,6 +272,12 @@ public class SnapshotController extends SaveAndRestoreBaseController implements
271272
@FXML
272273
protected TableColumn<TableEntry, ?> baseSnapshotColumn;
273274

275+
@FXML
276+
private TableColumn<TableEntry, AlarmSeverity> storedSeverityColumn;
277+
278+
@FXML
279+
private TableColumn<TableEntry, AlarmSeverity> liveSeverityColumn;
280+
274281
@FXML
275282
protected TooltipTableColumn<VType> baseSnapshotValueColumn;
276283

@@ -357,7 +364,6 @@ public SnapshotController(SnapshotTab snapshotTab) {
357364
}
358365

359366

360-
361367
@FXML
362368
public void initialize() {
363369

@@ -396,7 +402,7 @@ public void initialize() {
396402

397403
saveSnapshotButton.disableProperty().bind(Bindings.createBooleanBinding(() ->
398404
// TODO: support save (=update) a composite snapshot from the snapshot view. In the meanwhile, disable save button.
399-
snapshotDataDirty.not().get() ||
405+
snapshotDataDirty.not().get() ||
400406
snapshotNameProperty.isEmpty().get() ||
401407
snapshotCommentProperty.isEmpty().get() ||
402408
userIdentity.isNull().get(),
@@ -468,7 +474,7 @@ public void initialize() {
468474

469475
showLiveReadbackButton.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/show_live_readback_column.png"))));
470476
showLiveReadbackButton.selectedProperty()
471-
.addListener((a, o, n) ->{
477+
.addListener((a, o, n) -> {
472478
this.showReadbacks.set(n);
473479
actionResultReadbackColumn.visibleProperty().setValue(actionResultReadbackColumn.getGraphic() != null);
474480
});
@@ -668,6 +674,9 @@ protected void updateItem(TableEntry item, boolean empty) {
668674
storedReadbackColumn.setCellFactory(e -> new VTypeCellEditor<>());
669675
readbackColumn.visibleProperty().bind(showReadbacks);
670676

677+
liveSeverityColumn.setCellFactory(a -> new AlarmSeverityCell());
678+
storedSeverityColumn.setCellFactory(a -> new AlarmSeverityCell());
679+
671680
timeColumn.visibleProperty().bind(compareViewEnabled.not());
672681
firstDividerColumn.visibleProperty().bind(compareViewEnabled);
673682
statusColumn.visibleProperty().bind(compareViewEnabled.not());
@@ -763,7 +772,7 @@ public void takeSnapshot() {
763772
* Restores snapshot meta-data properties to indicate that the UI
764773
* is not showing persisted {@link Snapshot} data.
765774
*/
766-
private void resetMetaData(){
775+
private void resetMetaData() {
767776
tabTitleProperty.setValue(Messages.unnamedSnapshot);
768777
snapshotNameProperty.setValue(null);
769778
snapshotCommentProperty.setValue(null);
@@ -1141,7 +1150,7 @@ private void showTakeSnapshotResult(List<SnapshotItem> snapshotItems) {
11411150
break;
11421151
}
11431152
}
1144-
for(SnapshotItem snapshotItem : snapshotItems){
1153+
for (SnapshotItem snapshotItem : snapshotItems) {
11451154
if (snapshotItem.getConfigPv().getReadbackPvName() != null && snapshotItem.getReadbackValue() != null &&
11461155
snapshotItem.getReadbackValue().equals(VDisconnectedData.INSTANCE)) {
11471156
disconnectedReadbackPvEncountered.set(true);
@@ -1155,7 +1164,7 @@ private void showTakeSnapshotResult(List<SnapshotItem> snapshotItems) {
11551164
if (!disconnectedPvEncountered.get()) {
11561165
actionResultColumn.setGraphic(new ImageView(ImageCache.getImage(SnapshotController.class, "/icons/ok.png")));
11571166
}
1158-
if(!disconnectedReadbackPvEncountered.get()){
1167+
if (!disconnectedReadbackPvEncountered.get()) {
11591168
actionResultReadbackColumn.setGraphic(new ImageView(ImageCache.getImage(SnapshotController.class, "/icons/ok.png")));
11601169
}
11611170
});
@@ -1329,8 +1338,7 @@ private void showRestoreResult(List<RestoreResult> restoreResultList) {
13291338
Platform.runLater(() -> {
13301339
if (!disconnectedPvEncountered.get()) {
13311340
actionResultColumn.setGraphic(new ImageView(ImageCache.getImage(SnapshotController.class, "/icons/ok.png")));
1332-
}
1333-
else{
1341+
} else {
13341342
actionResultColumn.setGraphic(new ImageView(ImageCache.getImage(SnapshotController.class, "/icons/error.png")));
13351343
}
13361344
});
@@ -1508,15 +1516,13 @@ private void showSnapshotInTable() {
15081516
tableEntry.setStoredReadbackValue(entry.getReadbackValue(), 0);
15091517
if (entry.getValue() == null || entry.getValue().equals(VDisconnectedData.INSTANCE)) {
15101518
tableEntry.setActionResult(ActionResult.FAILED);
1511-
}
1512-
else {
1519+
} else {
15131520
tableEntry.setActionResult(ActionResult.OK);
15141521
}
1515-
if (entry.getConfigPv().getReadbackPvName() != null){
1516-
if(entry.getReadbackValue() == null || entry.getReadbackValue().equals(VDisconnectedData.INSTANCE)) {
1522+
if (entry.getConfigPv().getReadbackPvName() != null) {
1523+
if (entry.getReadbackValue() == null || entry.getReadbackValue().equals(VDisconnectedData.INSTANCE)) {
15171524
tableEntry.setActionResultReadback(ActionResult.FAILED);
1518-
}
1519-
else{
1525+
} else {
15201526
tableEntry.setActionResultReadback(ActionResult.OK);
15211527
}
15221528
}
@@ -1590,22 +1596,20 @@ private void connectPVs() {
15901596
}
15911597

15921598
/**
1593-
*
15941599
* @param configurationData {@link ConfigurationData} obejct of a {@link org.phoebus.applications.saveandrestore.model.Configuration}
15951600
* @return <code>true</code> if any if the {@link ConfigPv} items in {@link ConfigurationData#getPvList()} defines a non-null read-back
15961601
* PV name, otherwise <code>false</code>.
15971602
*/
1598-
private boolean configurationHasReadbackPvs(ConfigurationData configurationData){
1603+
private boolean configurationHasReadbackPvs(ConfigurationData configurationData) {
15991604
return configurationData.getPvList().stream().anyMatch(cp -> cp.getReadbackPvName() != null);
16001605
}
16011606

16021607
/**
1603-
*
16041608
* @param snapshotData {@link SnapshotData} obejct of a {@link org.phoebus.applications.saveandrestore.model.Snapshot}
16051609
* @return <code>true</code> if any if the {@link ConfigPv} items in {@link SnapshotData#getSnapshotItems()} defines a non-null read-back
16061610
* PV name, otherwise <code>false</code>.
16071611
*/
1608-
private boolean configurationHasReadbackPvs(SnapshotData snapshotData){
1612+
private boolean configurationHasReadbackPvs(SnapshotData snapshotData) {
16091613
return snapshotData.getSnapshotItems().stream().anyMatch(si -> si.getConfigPv().getReadbackPvName() != null);
16101614
}
16111615

@@ -1660,4 +1664,32 @@ public void updateItem(org.phoebus.applications.saveandrestore.ui.snapshot.Actio
16601664
}
16611665
}
16621666
}
1667+
1668+
/**
1669+
* {@link TableCell} customized for the alarm severity column such that alarm information is
1670+
* decorated in the same manner as in other applications.
1671+
*/
1672+
private static class AlarmSeverityCell extends TableCell<TableEntry, AlarmSeverity> {
1673+
1674+
@Override
1675+
public void updateItem(AlarmSeverity alarmSeverity, boolean empty) {
1676+
if (empty) {
1677+
setText(null);
1678+
setStyle(TableCellColors.REGULAR_CELL_STYLE);
1679+
} else if (alarmSeverity == null) {
1680+
setText("---");
1681+
setStyle(TableCellColors.REGULAR_CELL_STYLE);
1682+
} else {
1683+
setText(alarmSeverity.toString());
1684+
switch (alarmSeverity) {
1685+
case NONE -> setStyle(TableCellColors.ALARM_NONE_STYLE);
1686+
case UNDEFINED -> setStyle(TableCellColors.ALARM_UNDEFINED_STYLE);
1687+
case MINOR -> setStyle(TableCellColors.ALARM_MINOR_STYLE);
1688+
case MAJOR -> setStyle(TableCellColors.ALARM_MAJOR_STYLE);
1689+
case INVALID -> setStyle(TableCellColors.ALARM_INVALID_STYLE);
1690+
}
1691+
}
1692+
1693+
}
1694+
}
16631695
}

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

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package org.phoebus.applications.saveandrestore.ui.snapshot;
66

77
import javafx.scene.paint.Color;
8-
import javafx.scene.paint.Paint;
98
import org.phoebus.ui.Preferences;
109
import org.phoebus.ui.javafx.Brightness;
1110
import org.phoebus.ui.javafx.JFXUtil;
@@ -16,34 +15,111 @@
1615
*/
1716
public class TableCellColors {
1817

19-
public static final Color DISCONNECTED_COLOR = Color.rgb(Preferences.undefined_severity_background_color[0],
18+
private static final Color DISCONNECTED_COLOR = Color.rgb(Preferences.undefined_severity_background_color[0],
2019
Preferences.undefined_severity_background_color[1],
2120
Preferences.undefined_severity_background_color[2]);
21+
private static final Color ALARM_NONE_COLOR = Color.rgb(Preferences.alarm_area_panel_ok_severity_background_color[0],
22+
Preferences.alarm_area_panel_ok_severity_background_color[1],
23+
Preferences.alarm_area_panel_ok_severity_background_color[2]);
24+
private static final Color ALARM_MINOR_COLOR = Color.rgb(Preferences.alarm_area_panel_minor_severity_background_color[0],
25+
Preferences.alarm_area_panel_minor_severity_background_color[1],
26+
Preferences.alarm_area_panel_minor_severity_background_color[2]);
27+
private static final Color ALARM_MAJOR_COLOR = Color.rgb(Preferences.alarm_area_panel_major_severity_background_color[0],
28+
Preferences.alarm_area_panel_major_severity_background_color[1],
29+
Preferences.alarm_area_panel_major_severity_background_color[2]);
30+
private static final Color ALARM_UNDEFINED_COLOR = Color.rgb(Preferences.alarm_area_panel_undefined_severity_background_color[0],
31+
Preferences.alarm_area_panel_major_severity_background_color[1],
32+
Preferences.alarm_area_panel_major_severity_background_color[2]);
33+
private static final Color ALARM_INVALID_COLOR = Color.rgb(Preferences.alarm_area_panel_invalid_severity_background_color[0],
34+
Preferences.alarm_area_panel_invalid_severity_background_color[1],
35+
Preferences.alarm_area_panel_invalid_severity_background_color[2]);
2236

23-
public static final Paint DISCONNECTED_PAINT;
2437
private static final Color DISCONNECTED_TEXT_COLOR;
25-
private static final Color DISCONNECTED_BORDER_COLOR;
38+
private static final Color ALARM_NONE_TEXT_COLOR;
39+
private static final Color ALARM_MINOR_TEXT_COLOR;
40+
private static final Color ALARM_MAJOR_TEXT_COLOR;
41+
private static final Color ALARM_UNDEFINED_TEXT_COLOR;
42+
private static final Color ALARM_INVALID_TEXT_COLOR;
2643
public static final String REGULAR_CELL_STYLE = "-fx-text-fill: black; -fx-background-color: transparent";
2744
public static final String DISCONNECTED_STYLE;
28-
public static final String DISCONNECTED_STYLE_SMALL;
45+
public static final String ALARM_NONE_STYLE;
46+
public static final String ALARM_MINOR_STYLE;
47+
public static final String ALARM_MAJOR_STYLE;
48+
public static final String ALARM_UNDEFINED_STYLE;
49+
public static final String ALARM_INVALID_STYLE;
2950

3051
static {
31-
DISCONNECTED_PAINT = Paint.valueOf(JFXUtil.webRGB(DISCONNECTED_COLOR));
3252
if (Brightness.of(DISCONNECTED_COLOR) < Brightness.BRIGHT_THRESHOLD) {
3353
DISCONNECTED_TEXT_COLOR = Color.WHITE;
34-
DISCONNECTED_BORDER_COLOR = Color.WHITE;
35-
} else {
54+
}
55+
else {
3656
DISCONNECTED_TEXT_COLOR = Color.BLACK;
37-
DISCONNECTED_BORDER_COLOR = Color.GRAY;
3857
}
3958

59+
if(Brightness.of(ALARM_NONE_COLOR) < Brightness.BRIGHT_THRESHOLD){
60+
ALARM_NONE_TEXT_COLOR = Color.WHITE;
61+
}
62+
else{
63+
ALARM_NONE_TEXT_COLOR = Color.BLACK;
64+
}
65+
66+
if(Brightness.of(ALARM_MINOR_COLOR) < Brightness.BRIGHT_THRESHOLD){
67+
ALARM_MINOR_TEXT_COLOR = Color.WHITE;
68+
}
69+
else{
70+
ALARM_MINOR_TEXT_COLOR = Color.BLACK;
71+
}
72+
73+
if(Brightness.of(ALARM_MAJOR_COLOR) < Brightness.BRIGHT_THRESHOLD){
74+
ALARM_MAJOR_TEXT_COLOR = Color.WHITE;
75+
}
76+
else{
77+
ALARM_MAJOR_TEXT_COLOR = Color.BLACK;
78+
}
4079

41-
DISCONNECTED_STYLE = "-fx-border-color: transparent; -fx-border-width: 2 0 2 0; -fx-background-insets: 2 0 2 0; -fx-text-fill: " +
80+
if(Brightness.of(ALARM_UNDEFINED_COLOR) < Brightness.BRIGHT_THRESHOLD){
81+
ALARM_UNDEFINED_TEXT_COLOR = Color.WHITE;
82+
}
83+
else{
84+
ALARM_UNDEFINED_TEXT_COLOR = Color.BLACK;
85+
}
86+
87+
if(Brightness.of(ALARM_INVALID_COLOR) < Brightness.BRIGHT_THRESHOLD){
88+
ALARM_INVALID_TEXT_COLOR = Color.WHITE;
89+
}
90+
else{
91+
ALARM_INVALID_TEXT_COLOR = Color.BLACK;
92+
}
93+
94+
95+
DISCONNECTED_STYLE = "-fx-background-insets: 2 2 2 2; -fx-text-fill: " +
4296
JFXUtil.webRGB(DISCONNECTED_TEXT_COLOR) +
4397
"; -fx-background-color: " +
4498
JFXUtil.webRGB(DISCONNECTED_COLOR);
45-
DISCONNECTED_STYLE_SMALL = "-fx-border-color: " + JFXUtil.webRGB(DISCONNECTED_BORDER_COLOR) +"; -fx-border-width: 2 2 2 2;" +
46-
" -fx-background-color: " +
47-
JFXUtil.webRGB(DISCONNECTED_COLOR);
99+
100+
ALARM_NONE_STYLE = "-fx-background-insets: 2 2 2 2; -fx-text-fill: " +
101+
JFXUtil.webRGB(ALARM_NONE_TEXT_COLOR) +
102+
"; -fx-background-color: " +
103+
JFXUtil.webRGB(ALARM_NONE_COLOR);
104+
105+
ALARM_MINOR_STYLE = "-fx-background-insets: 2 2 2 2; -fx-text-fill: " +
106+
JFXUtil.webRGB(ALARM_MINOR_TEXT_COLOR) +
107+
"; -fx-background-color: " +
108+
JFXUtil.webRGB(ALARM_MINOR_COLOR);
109+
110+
ALARM_MAJOR_STYLE = "-fx-background-insets: 2 2 2 2; -fx-text-fill: " +
111+
JFXUtil.webRGB(ALARM_MAJOR_TEXT_COLOR) +
112+
"; -fx-background-color: " +
113+
JFXUtil.webRGB(ALARM_MAJOR_COLOR);
114+
115+
ALARM_UNDEFINED_STYLE = "-fx-background-insets: 2 2 2 2; -fx-text-fill: " +
116+
JFXUtil.webRGB(ALARM_UNDEFINED_TEXT_COLOR) +
117+
"; -fx-background-color: " +
118+
JFXUtil.webRGB(ALARM_UNDEFINED_COLOR);
119+
120+
ALARM_INVALID_STYLE = "-fx-background-insets: 2 2 2 2; -fx-text-fill: " +
121+
JFXUtil.webRGB(ALARM_INVALID_TEXT_COLOR) +
122+
"; -fx-background-color: " +
123+
JFXUtil.webRGB(ALARM_INVALID_COLOR);
48124
}
49125
}

0 commit comments

Comments
 (0)