use of org.yamcs.studio.data.IPVListener in project yamcs-studio by yamcs.
the class AbstractScriptStore method init.
private void init() throws Exception {
if (!(scriptData instanceof RuleScriptData) && !scriptData.isEmbedded()) {
absoluteScriptPath = scriptData.getPath();
if (!absoluteScriptPath.isAbsolute()) {
// The following looked like this:
// absoluteScriptPath = ResourceUtil.buildAbsolutePath(
// editpart.getWidgetModel(), absoluteScriptPath);
// .. but that doesn't work when the editpart is already a LinkingContainer.
// It would fetch the parent's DisplayModel, i.e. look for scripts where the container is used,
// instead of where it's defined.
//
// After updating buildAbsolutePath() to handle (editpart instanceof LinkingContainer) as below,
// the resolution of related displays failed again as in #977 because buildAbsolutePath() is
// called in many placed while reading the *.opi file, and it would now build a different widget tree.
//
// The following just fixes the relative script lookup from linking containers for #998,
// without disturbing any other code.
//
// TODO Understand & redo the whole widget model and its quirks for linking containers,
// so all the recently added (.. instanceof ..Linking..) can be removed.
var model = editPart.getWidgetModel();
DisplayModel root;
if (model instanceof AbstractLinkingContainerModel) {
root = ((AbstractLinkingContainerModel) model).getDisplayModel();
} else {
root = model.getRootDisplayModel();
}
absoluteScriptPath = root.getOpiFilePath().removeLastSegments(1).append(absoluteScriptPath);
// ---
if (!ResourceUtil.isExsitingFile(absoluteScriptPath, true)) {
throw new FileNotFoundException(scriptData.getPath().toString());
}
}
}
initScriptEngine();
errorInScript = false;
errorSource = (scriptData instanceof RuleScriptData ? ((RuleScriptData) scriptData).getRuleData().getName() : scriptData.getPath().toString()) + " on " + editPart.getWidgetModel().getName();
if (scriptData instanceof RuleScriptData) {
compileString(((RuleScriptData) scriptData).getScriptString());
} else if (scriptData.isEmbedded()) {
compileString(scriptData.getScriptText());
} else {
var inputStream = ResourceUtil.pathToInputStream(absoluteScriptPath);
compileInputStream(inputStream);
inputStream.close();
}
pvListenerMap = new HashMap<>();
var suppressPVListener = new IPVListener() {
@Override
public synchronized void valueChanged(IPV pv) {
if (triggerSuppressed && checkPVsConnected(scriptData, pvArray)) {
executeScriptInUIThread(pv);
triggerSuppressed = false;
}
}
};
var triggerPVListener = new IPVListener() {
@Override
public synchronized void valueChanged(IPV pv) {
// execute script only if all input pvs are connected
if (pvArray.length > 1) {
if (!checkPVsConnected(scriptData, pvArray)) {
triggerSuppressed = true;
return;
}
}
executeScriptInUIThread(pv);
}
};
// register pv listener
for (var i = 0; i < pvArray.length; i++) {
var pv = pvArray[i];
if (pv == null) {
continue;
}
if (!scriptData.getPVList().get(i).trigger) {
// execute the script if it was suppressed.
pv.addListener(suppressPVListener);
pvListenerMap.put(pv, suppressPVListener);
continue;
}
pv.addListener(triggerPVListener);
pvListenerMap.put(pv, triggerPVListener);
}
}
use of org.yamcs.studio.data.IPVListener in project yamcs-studio by yamcs.
the class ArrayEditPart method registerLoadPVDataTypeListener.
private void registerLoadPVDataTypeListener() {
if (getExecutionMode() == ExecutionMode.RUN_MODE) {
var model = getWidgetModel();
var pv = getPV();
if (pv != null) {
if (pvDataTypeListener == null) {
pvDataTypeListener = new IPVListener() {
@Override
public void valueChanged(IPV pv) {
var value = pv.getValue();
if (value != null) {
model.setArrayLength(VTypeHelper.getSize(value));
var dataType = VTypeHelper.getBasicDataType(value);
model.setPropertyValue(PROP_DATA_TYPE, mapBasicDataTypeToArrayType(dataType));
}
}
};
}
pv.addListener(pvDataTypeListener);
}
}
}
Aggregations