use of org.csstudio.opibuilder.script.ScriptsInput in project yamcs-studio by yamcs.
the class ScriptProperty method readValueFromXML.
@Override
public ScriptsInput readValueFromXML(Element propElement) {
ScriptsInput result = new ScriptsInput();
for (Object oe : propElement.getChildren(XML_ELEMENT_PATH)) {
Element se = (Element) oe;
ScriptData sd = new ScriptData();
if (se.getAttributeValue(XML_ATTRIBUTE_PATHSTRING).equals(EMBEDDEDJS)) {
sd.setEmbedded(true);
sd.setScriptType(ScriptType.JAVASCRIPT);
sd.setScriptText(se.getChildText(XML_ELEMENT_SCRIPT_TEXT));
sd.setScriptName(se.getChildText(XML_ELEMENT_SCRIPT_NAME));
} else if (se.getAttributeValue(XML_ATTRIBUTE_PATHSTRING).equals(EMBEDDEDPY)) {
sd.setEmbedded(true);
sd.setScriptType(ScriptType.PYTHON);
sd.setScriptText(se.getChildText(XML_ELEMENT_SCRIPT_TEXT));
sd.setScriptName(se.getChildText(XML_ELEMENT_SCRIPT_NAME));
} else
sd = new ScriptData(new Path(se.getAttributeValue(XML_ATTRIBUTE_PATHSTRING)));
if (se.getAttributeValue(XML_ATTRIBUTE_CHECKCONNECT) != null)
sd.setCheckConnectivity(Boolean.parseBoolean(se.getAttributeValue(XML_ATTRIBUTE_CHECKCONNECT)));
if (se.getAttributeValue(XML_ATTRIBUTE_SKIP_FIRST_EXECUTION) != null)
sd.setSkipPVsFirstConnection(Boolean.parseBoolean(se.getAttributeValue(XML_ATTRIBUTE_SKIP_FIRST_EXECUTION)));
if (se.getAttributeValue(XML_ATTRIBUTE_STOP_EXECUTE_ON_ERROR) != null)
sd.setStopExecuteOnError(Boolean.parseBoolean(se.getAttributeValue(XML_ATTRIBUTE_STOP_EXECUTE_ON_ERROR)));
for (Object o : se.getChildren(XML_ELEMENT_PV)) {
Element pve = (Element) o;
boolean trig = true;
if (pve.getAttribute(XML_ATTRIBUTE_TRIGGER) != null)
trig = Boolean.parseBoolean(pve.getAttributeValue(XML_ATTRIBUTE_TRIGGER));
sd.addPV(new PVTuple(pve.getText(), trig));
}
result.getScriptList().add(sd);
}
return result;
}
use of org.csstudio.opibuilder.script.ScriptsInput 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.ScriptsInput 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.ScriptsInput in project yamcs-studio by yamcs.
the class ScriptProperty method writeToXML.
@Override
public void writeToXML(Element propElement) {
for (ScriptData scriptData : ((ScriptsInput) getPropertyValue()).getScriptList()) {
Element pathElement = new Element(XML_ELEMENT_PATH);
String pathString = null;
if (scriptData.isEmbedded()) {
if (scriptData.getScriptType() == ScriptType.JAVASCRIPT)
pathString = EMBEDDEDJS;
else if (scriptData.getScriptType() == ScriptType.PYTHON)
pathString = EMBEDDEDPY;
Element scriptNameElement = new Element(XML_ELEMENT_SCRIPT_NAME);
scriptNameElement.setText(scriptData.getScriptName());
pathElement.addContent(scriptNameElement);
Element scriptTextElement = new Element(XML_ELEMENT_SCRIPT_TEXT);
scriptTextElement.setContent(new CDATA(scriptData.getScriptText()));
pathElement.addContent(scriptTextElement);
} else
pathString = scriptData.getPath().toPortableString();
pathElement.setAttribute(XML_ATTRIBUTE_PATHSTRING, pathString);
pathElement.setAttribute(XML_ATTRIBUTE_CHECKCONNECT, Boolean.toString(scriptData.isCheckConnectivity()));
pathElement.setAttribute(XML_ATTRIBUTE_SKIP_FIRST_EXECUTION, Boolean.toString(scriptData.isSkipPVsFirstConnection()));
pathElement.setAttribute(XML_ATTRIBUTE_STOP_EXECUTE_ON_ERROR, Boolean.toString(scriptData.isStopExecuteOnError()));
for (PVTuple pv : scriptData.getPVList()) {
Element pvElement = new Element(XML_ELEMENT_PV);
pvElement.setText(pv.pvName);
pvElement.setAttribute(XML_ATTRIBUTE_TRIGGER, Boolean.toString(pv.trigger));
pathElement.addContent(pvElement);
}
propElement.addContent(pathElement);
}
}
use of org.csstudio.opibuilder.script.ScriptsInput in project yamcs-studio by yamcs.
the class ScriptProperty method getPropertyValue.
@Override
public Object getPropertyValue() {
if (executionMode == ExecutionMode.RUN_MODE && widgetModel != null) {
ScriptsInput value = (ScriptsInput) super.getPropertyValue();
for (ScriptData sd : value.getScriptList()) {
for (Object pv : sd.getPVList().toArray()) {
PVTuple pvTuple = (PVTuple) pv;
String newPV = OPIBuilderMacroUtil.replaceMacros(widgetModel, pvTuple.pvName);
if (!newPV.equals(pvTuple.pvName)) {
int i = sd.getPVList().indexOf(pv);
sd.getPVList().remove(pv);
sd.getPVList().add(i, new PVTuple(newPV, pvTuple.trigger));
}
}
}
return value;
} else
return super.getPropertyValue();
}
Aggregations