use of org.csstudio.opibuilder.script.RulesInput in project yamcs-studio by yamcs.
the class RulesProperty method readValueFromXML.
@Override
public RulesInput readValueFromXML(Element propElement) throws Exception {
var result = new RulesInput();
for (var oe : propElement.getChildren(XML_ELEMENT_RULE)) {
var se = (Element) oe;
var ruleData = new RuleData(widgetModel);
ruleData.setName(se.getAttributeValue(XML_ATTRIBUTE_NAME));
ruleData.setPropId(se.getAttributeValue(XML_ATTRIBUTE_PROPID));
ruleData.setOutputExpValue(Boolean.parseBoolean(se.getAttributeValue(XML_ATTRIBUTE_OUTPUTEXPRESSION)));
for (var eo : se.getChildren(XML_ELEMENT_EXPRESSION)) {
var ee = (Element) eo;
var booleanExpression = ee.getAttributeValue(XML_ATTRIBUTE_BOOLEXP);
Object value = "null";
var valueElement = ee.getChild(XML_ELEMENT_VALUE);
if (ruleData.isOutputExpValue()) {
value = valueElement.getText();
} else {
value = ruleData.getProperty().readValueFromXML(valueElement);
}
var exp = new Expression(booleanExpression, value);
ruleData.addExpression(exp);
}
for (var pvo : se.getChildren(XML_ELEMENT_PV)) {
var pve = (Element) pvo;
var trig = true;
if (pve.getAttribute(XML_ATTRIBUTE_TRIGGER) != null) {
trig = Boolean.parseBoolean(pve.getAttributeValue(XML_ATTRIBUTE_TRIGGER));
}
ruleData.addPV(new PVTuple(pve.getText(), trig));
}
result.getRuleDataList().add(ruleData);
}
return result;
}
use of org.csstudio.opibuilder.script.RulesInput in project yamcs-studio by yamcs.
the class AbstractWidgetModel method processVersionDifference.
/**
* Make necessary adjustment for widget compatibility between different versions.
*/
public void processVersionDifference(Version boyVersionOnFile) {
// update pv name
if (UpgradeUtil.VERSION_WITH_PVMANAGER.compareTo(boyVersionOnFile) > 0) {
if (propertyMap.containsKey(PROP_SCRIPTS)) {
ScriptsInput scriptsInput = getScriptsInput();
for (ScriptData sd : scriptsInput.getScriptList()) {
for (PVTuple tuple : sd.getPVList()) {
tuple.pvName = UpgradeUtil.convertUtilityPVNameToPM(tuple.pvName);
}
}
setPropertyValue(PROP_SCRIPTS, scriptsInput);
}
if (propertyMap.containsKey(PROP_RULES)) {
RulesInput rulesInput = getRulesInput();
for (RuleData rd : rulesInput.getRuleDataList()) {
for (PVTuple tuple : rd.getPVList()) {
tuple.pvName = UpgradeUtil.convertUtilityPVNameToPM(tuple.pvName);
}
}
setPropertyValue(PROP_RULES, rulesInput);
}
}
}
use of org.csstudio.opibuilder.script.RulesInput in project yamcs-studio by yamcs.
the class RulesProperty method writeToXML.
@Override
public void writeToXML(Element propElement) {
for (RuleData ruleData : ((RulesInput) getPropertyValue()).getRuleDataList()) {
Element ruleElement = new Element(XML_ELEMENT_RULE);
ruleElement.setAttribute(XML_ATTRIBUTE_NAME, ruleData.getName());
ruleElement.setAttribute(XML_ATTRIBUTE_PROPID, ruleData.getPropId());
ruleElement.setAttribute(XML_ATTRIBUTE_OUTPUTEXPRESSION, Boolean.toString(ruleData.isOutputExpValue()));
for (Expression exp : ruleData.getExpressionList()) {
Element expElement = new Element(XML_ELEMENT_EXPRESSION);
expElement.setAttribute(XML_ATTRIBUTE_BOOLEXP, exp.getBooleanExpression());
Element valueElement = new Element(XML_ELEMENT_VALUE);
if (ruleData.isOutputExpValue())
valueElement.setText(exp.getValue().toString());
else {
Object savedValue = ruleData.getProperty().getPropertyValue();
ruleData.getProperty().setPropertyValue_IgnoreOldValue(exp.getValue());
ruleData.getProperty().writeToXML(valueElement);
ruleData.getProperty().setPropertyValue_IgnoreOldValue(savedValue);
}
expElement.addContent(valueElement);
ruleElement.addContent(expElement);
}
for (PVTuple pv : ruleData.getPVList()) {
Element pvElement = new Element(XML_ELEMENT_PV);
pvElement.setText(pv.pvName);
pvElement.setAttribute(XML_ATTRIBUTE_TRIGGER, Boolean.toString(pv.trigger));
ruleElement.addContent(pvElement);
}
propElement.addContent(ruleElement);
}
}
Aggregations