use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class XMLUtil method fillWidgets.
/**
* Convert XML Element to a widget model.
*
* @param element
* @param displayModel
* the root display model. If root of the element is a display, use this display model as root model
* instead of creating a new one. If this is null, a new one will be created.
* @throws Exception
*/
@SuppressWarnings("rawtypes")
public static AbstractWidgetModel fillWidgets(Element element, DisplayModel displayModel) throws Exception {
if (element == null)
return null;
AbstractWidgetModel rootWidgetModel = null;
// Determine root widget model
if (element.getName().equals(XMLTAG_DISPLAY)) {
if (displayModel != null)
rootWidgetModel = displayModel;
else
rootWidgetModel = new DisplayModel(null);
} else if (element.getName().equals(XMLTAG_WIDGET)) {
String typeId = element.getAttributeValue(XMLATTR_TYPEID);
WidgetDescriptor desc = WidgetsService.getInstance().getWidgetDescriptor(typeId);
if (desc != null)
rootWidgetModel = desc.getWidgetModel();
if (rootWidgetModel == null) {
String errorMessage = NLS.bind("Fail to load the widget: {0}\n " + "The widget may not exist, as a consequence, the widget will be ignored.", typeId);
ErrorHandlerUtil.handleError(errorMessage, new Exception("Widget does not exist."));
return null;
}
} else if (element.getName().equals(XMLTAG_CONNECTION)) {
rootWidgetModel = new ConnectionModel(displayModel);
} else {
String errorMessage = "Unknown Tag: " + element.getName();
ConsoleService.getInstance().writeError(errorMessage);
return null;
}
setPropertiesFromXML(element, rootWidgetModel);
if (rootWidgetModel instanceof AbstractContainerModel) {
AbstractContainerModel container = (AbstractContainerModel) rootWidgetModel;
List children = element.getChildren();
Iterator iterator = children.iterator();
while (iterator.hasNext()) {
Element subElement = (Element) iterator.next();
if (subElement.getName().equals(XMLTAG_WIDGET))
container.addChild(fillWidgets(subElement, displayModel));
}
}
if (displayModel != null)
rootWidgetModel.processVersionDifference(displayModel.getBOYVersion());
return rootWidgetModel;
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel 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