use of org.csstudio.opibuilder.script.RuleData in project yamcs-studio by yamcs.
the class RulesInputDialog method invokeRuleDataDialog.
/**
*/
private void invokeRuleDataDialog() {
RuleData selection = (RuleData) ((IStructuredSelection) rulesViewer.getSelection()).getFirstElement();
if (selection == null)
return;
RuleDataEditDialog dialog = new RuleDataEditDialog(rulesViewer.getControl().getShell(), selection);
if (dialog.open() == OK) {
RuleData result = dialog.getOutput();
int index = ruleDataList.indexOf(selection);
ruleDataList.remove(index);
ruleDataList.add(index, result);
rulesViewer.refresh();
}
}
use of org.csstudio.opibuilder.script.RuleData 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.RuleData in project yamcs-studio by yamcs.
the class AbstractBaseEditPart method activate.
@Override
public void activate() {
if (!isActive()) {
super.activate();
initFigure(getFigure());
// add listener to all properties.
for (String id : getWidgetModel().getAllPropertyIDs()) {
AbstractWidgetProperty property = getWidgetModel().getProperty(id);
if (property != null) {
WidgetPropertyChangeListener listener = new WidgetPropertyChangeListener(this, property);
property.addPropertyChangeListener(listener);
propertyListenerMap.put(id, listener);
property.setExecutionMode(executionMode);
property.setWidgetModel(getWidgetModel());
}
}
registerBasePropertyChangeHandlers();
registerPropertyChangeHandlers();
if (executionMode == ExecutionMode.RUN_MODE) {
// hook open display action
Set<String> allPropIds = getWidgetModel().getAllPropertyIDs();
if (allPropIds.contains(AbstractWidgetModel.PROP_ACTIONS) && allPropIds.contains(AbstractWidgetModel.PROP_ENABLED)) {
hookMouseClickAction();
}
// script and rules execution
ScriptsInput scriptsInput = getWidgetModel().getScriptsInput();
scriptDataList = new ArrayList<>(scriptsInput.getScriptList());
for (RuleData rd : getWidgetModel().getRulesInput().getRuleDataList()) {
scriptDataList.add(rd.convertToScriptData());
}
for (final ScriptData scriptData : scriptDataList) {
final IPV[] pvArray = new IPV[scriptData.getPVList().size()];
int i = 0;
for (PVTuple pvTuple : scriptData.getPVList()) {
String pvName = pvTuple.pvName;
if (pvMap.containsKey(pvName)) {
pvArray[i] = pvMap.get(pvName);
} else {
try {
IPV pv = BOYPVFactory.createPV(pvName, false, 2);
pvMap.put(pvName, pv);
addToConnectionHandler(pvName, pv);
pvArray[i] = pv;
} catch (Exception e) {
String message = NLS.bind("Unable to connect to PV: {0}! \n" + "This may cause error when executing the script.", pvName);
OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
ConsoleService.getInstance().writeError(message);
pvArray[i] = null;
}
}
i++;
}
ScriptService.getInstance().registerScript(scriptData, AbstractBaseEditPart.this, pvArray);
UIBundlingThread.getInstance().addRunnable(new Runnable() {
@Override
public void run() {
if (!isActive()) {
// already deactivated
return;
}
hasStartedPVs = true;
for (IPV pv : pvArray) if (pv != null && !pv.isStarted())
try {
pv.start();
} catch (Exception e) {
OPIBuilderPlugin.getLogger().log(Level.WARNING, "Unable to start PV " + pv.getName(), // $NON-NLS-1$
e);
}
}
});
}
}
doActivate();
}
// Rap specified code
displayDisposeListener = new Runnable() {
@Override
public void run() {
deactivate();
}
};
}
use of org.csstudio.opibuilder.script.RuleData 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.RuleData 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