|
| 1 | +/* |
| 2 | + * Copyright (C) 2024 European Spallation Source ERIC. |
| 3 | + */ |
| 4 | + |
| 5 | +package org.phoebus.applications.saveandrestore.ui.configuration; |
| 6 | + |
| 7 | +import javafx.beans.property.BooleanProperty; |
| 8 | +import javafx.beans.property.ObjectProperty; |
| 9 | +import javafx.beans.property.SimpleBooleanProperty; |
| 10 | +import javafx.beans.property.SimpleObjectProperty; |
| 11 | +import javafx.beans.property.SimpleStringProperty; |
| 12 | +import javafx.beans.property.StringProperty; |
| 13 | +import org.phoebus.applications.saveandrestore.model.Comparison; |
| 14 | +import org.phoebus.applications.saveandrestore.model.ConfigPv; |
| 15 | +import org.phoebus.applications.saveandrestore.model.ComparisonMode; |
| 16 | + |
| 17 | +import java.util.Objects; |
| 18 | + |
| 19 | +/** |
| 20 | + * Wrapper around a {@link ConfigPv} instance for the purpose of facilitating |
| 21 | + * configuration and data binding in (for instance) a {@link javafx.scene.control.TableView}. |
| 22 | + */ |
| 23 | +public class ConfigPvEntry implements Comparable<ConfigPvEntry> { |
| 24 | + |
| 25 | + private final StringProperty pvNameProperty; |
| 26 | + private final StringProperty readBackPvNameProperty; |
| 27 | + private final BooleanProperty readOnlyProperty; |
| 28 | + private final ObjectProperty<ComparisonMode> comparisonModeProperty; |
| 29 | + private final ObjectProperty<Double> toleranceProperty; |
| 30 | + |
| 31 | + public ConfigPvEntry(ConfigPv configPv) { |
| 32 | + this.pvNameProperty = new SimpleStringProperty(this, "pvNameProperty", configPv.getPvName()); |
| 33 | + this.readBackPvNameProperty = new SimpleStringProperty(configPv.getReadbackPvName()); |
| 34 | + this.readOnlyProperty = new SimpleBooleanProperty(configPv.isReadOnly()); |
| 35 | + this.comparisonModeProperty = new SimpleObjectProperty<>(configPv.getComparison() == null ? null : configPv.getComparison().getComparisonMode()); |
| 36 | + this.toleranceProperty = new SimpleObjectProperty<>(configPv.getComparison() == null ? null : configPv.getComparison().getTolerance()); |
| 37 | + } |
| 38 | + |
| 39 | + public StringProperty getPvNameProperty() { |
| 40 | + return pvNameProperty; |
| 41 | + } |
| 42 | + |
| 43 | + public StringProperty getReadBackPvNameProperty() { |
| 44 | + return readBackPvNameProperty; |
| 45 | + } |
| 46 | + |
| 47 | + public BooleanProperty getReadOnlyProperty() { |
| 48 | + return readOnlyProperty; |
| 49 | + } |
| 50 | + |
| 51 | + public ObjectProperty<ComparisonMode> getComparisonModeProperty() { |
| 52 | + return comparisonModeProperty; |
| 53 | + } |
| 54 | + |
| 55 | + public ObjectProperty<Double> getToleranceProperty() { |
| 56 | + return toleranceProperty; |
| 57 | + } |
| 58 | + |
| 59 | + public void setPvNameProperty(String pvNameProperty) { |
| 60 | + this.pvNameProperty.set(pvNameProperty); |
| 61 | + } |
| 62 | + |
| 63 | + public void setReadBackPvNameProperty(String readBackPvNameProperty) { |
| 64 | + this.readBackPvNameProperty.set(readBackPvNameProperty); |
| 65 | + } |
| 66 | + |
| 67 | + public void setComparisonModeProperty(ComparisonMode comparisonModeProperty) { |
| 68 | + this.comparisonModeProperty.set(comparisonModeProperty); |
| 69 | + } |
| 70 | + |
| 71 | + public void setToleranceProperty(Double toleranceProperty) { |
| 72 | + this.toleranceProperty.set(toleranceProperty ); |
| 73 | + } |
| 74 | + |
| 75 | + public ConfigPv toConfigPv() { |
| 76 | + ConfigPv configPv = ConfigPv.builder() |
| 77 | + .pvName(pvNameProperty.get()) |
| 78 | + .readbackPvName(readBackPvNameProperty.get()) |
| 79 | + .readOnly(readOnlyProperty.get()) |
| 80 | + .build(); |
| 81 | + if(comparisonModeProperty.isNotNull().get() && toleranceProperty.isNotNull().get()){ |
| 82 | + configPv.setComparison(new Comparison(comparisonModeProperty.get(), toleranceProperty.get())); |
| 83 | + } |
| 84 | + return configPv; |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public boolean equals(Object other) { |
| 89 | + if (other instanceof ConfigPvEntry otherConfigPv) { |
| 90 | + return Objects.equals(pvNameProperty, otherConfigPv.getPvNameProperty()) && |
| 91 | + Objects.equals(readBackPvNameProperty, otherConfigPv.getReadBackPvNameProperty()) && |
| 92 | + Objects.equals(readOnlyProperty.get(), otherConfigPv.getReadOnlyProperty().get()); |
| 93 | + } |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public int hashCode() { |
| 99 | + return Objects.hash(pvNameProperty, readBackPvNameProperty, readOnlyProperty); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public int compareTo(ConfigPvEntry other) { |
| 104 | + return pvNameProperty.get().compareTo(other.getPvNameProperty().get()); |
| 105 | + } |
| 106 | +} |
0 commit comments