use of org.csstudio.opibuilder.model.AbstractLinkingContainerModel in project yamcs-studio by yamcs.
the class XMLUtil method widgetToXMLElement.
/**
* Flatten a widget to XML element.
*
* @param widgetModel
* model of the widget
* @return the XML element
*/
public static Element widgetToXMLElement(AbstractWidgetModel widgetModel) {
Element result = new Element((widgetModel instanceof DisplayModel) ? XMLTAG_DISPLAY : (widgetModel instanceof ConnectionModel) ? XMLTAG_CONNECTION : XMLTAG_WIDGET);
result.setAttribute(XMLATTR_TYPEID, widgetModel.getTypeID());
result.setAttribute(XMLATTR_VERSION, widgetModel.getVersion().toString());
List<String> propIds = new ArrayList<>(widgetModel.getAllPropertyIDs());
Collections.sort(propIds);
for (String propId : propIds) {
if (widgetModel.getProperty(propId).isSavable()) {
Element propElement = new Element(propId);
widgetModel.getProperty(propId).writeToXML(propElement);
result.addContent(propElement);
}
}
if (widgetModel instanceof AbstractContainerModel && !(widgetModel instanceof AbstractLinkingContainerModel)) {
AbstractContainerModel containerModel = (AbstractContainerModel) widgetModel;
for (AbstractWidgetModel child : containerModel.getChildren()) {
result.addContent(widgetToXMLElement(child));
}
}
// convert connections on this displayModel to xml element
if (widgetModel instanceof DisplayModel && ((DisplayModel) widgetModel).getConnectionList() != null) {
for (ConnectionModel connectionModel : ((DisplayModel) widgetModel).getConnectionList()) {
if (!connectionModel.isLoadedFromLinkedOpi()) {
Element connElement = widgetToXMLElement(connectionModel);
result.addContent(connElement);
}
}
}
return result;
}
use of org.csstudio.opibuilder.model.AbstractLinkingContainerModel 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.csstudio.opibuilder.model.AbstractLinkingContainerModel in project yamcs-studio by yamcs.
the class XMLUtil method fillLinkingContainersSub.
private static void fillLinkingContainersSub(AbstractContainerModel container, List<IPath> trace, final MacrosInput macrosInput_) throws Exception {
if (container instanceof AbstractLinkingContainerModel) {
AbstractLinkingContainerModel linkingContainer = (AbstractLinkingContainerModel) container;
List<IPath> tempTrace = new ArrayList<>();
tempTrace.addAll(trace);
fillLinkingContainerSub(linkingContainer, tempTrace, macrosInput_);
}
for (AbstractWidgetModel w : container.getAllDescendants()) {
if (w instanceof AbstractLinkingContainerModel) {
AbstractLinkingContainerModel linkingContainer = (AbstractLinkingContainerModel) w;
List<IPath> tempTrace = new ArrayList<>();
tempTrace.addAll(trace);
fillLinkingContainerSub(linkingContainer, tempTrace, macrosInput_);
}
}
}
Aggregations