Search in sources :

Example 81 with AbstractWidgetModel

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;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) LineAwareElement(org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement) Element(org.jdom.Element) Iterator(java.util.Iterator) WidgetDescriptor(org.csstudio.opibuilder.util.WidgetDescriptor) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) ArrayList(java.util.ArrayList) List(java.util.List) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException)

Example 82 with AbstractWidgetModel

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_);
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) AbstractLinkingContainerModel(org.csstudio.opibuilder.model.AbstractLinkingContainerModel)

Aggregations

AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)82 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)27 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)22 Rectangle (org.eclipse.draw2d.geometry.Rectangle)18 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)17 ArrayList (java.util.ArrayList)15 Point (org.eclipse.draw2d.geometry.Point)14 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)12 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)10 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)9 IFigure (org.eclipse.draw2d.IFigure)9 PropertyChangeEvent (java.beans.PropertyChangeEvent)8 PropertyChangeListener (java.beans.PropertyChangeListener)8 Dimension (org.eclipse.draw2d.geometry.Dimension)8 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)7 EditPart (org.eclipse.gef.EditPart)7 PointList (org.eclipse.draw2d.geometry.PointList)6 List (java.util.List)5 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)5 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)5