use of org.csstudio.display.builder.runtime.pv.RuntimePVListener in project org.csstudio.display.builder by kasemir.
the class XYPlotWidgetRuntime method bindMarker.
private void bindMarker(final WidgetProperty<String> name_prop, final WidgetProperty<Double> value_prop) {
final String pv_name = name_prop.getValue();
if (pv_name.isEmpty())
return;
logger.log(Level.FINER, "Connecting {0} to Marker PV {1}", new Object[] { widget, pv_name });
try {
final RuntimePV pv = PVFactory.getPV(pv_name);
addPV(pv);
marker_pvs.add(pv);
// Write value changes to the PV
final WidgetPropertyListener<Double> prop_listener = (prop, old, value) -> {
// Ignore if PV already has same value to break update loops
double pv_value = VTypeUtil.getValueNumber(pv.read()).doubleValue();
if (value == pv_value)
return;
try {
// System.out.println("Writing " + value_prop + " to PV " + pv_name);
pv.write(value);
} catch (Exception ex) {
logger.log(Level.WARNING, "Error writing marker value to PV " + pv_name, ex);
// Restore property to the unchanged value of the PV
value_prop.setValue(pv_value);
}
};
value_prop.addPropertyListener(prop_listener);
marker_prop_listeners.put(value_prop, prop_listener);
// Write PV updates to the value
final RuntimePVListener pv_listener = new RuntimePVListener() {
@Override
public void valueChanged(final RuntimePV pv, final VType value) {
final double number = VTypeUtil.getValueNumber(value).doubleValue();
if (number == value_prop.getValue())
return;
// System.out.println("Writing " + number + " from PV " + pv_name + " to " + value_prop);
value_prop.setValue(number);
}
};
pv.addListener(pv_listener);
marker_pv_listeners.put(pv, pv_listener);
} catch (Exception ex) {
logger.log(Level.WARNING, "Error connecting Marker PV " + pv_name, ex);
}
}
Aggregations