Search in sources :

Example 1 with ConnectionModel

use of org.csstudio.opibuilder.model.ConnectionModel 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;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) LineAwareElement(org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) AbstractLinkingContainerModel(org.csstudio.opibuilder.model.AbstractLinkingContainerModel)

Example 2 with ConnectionModel

use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.

the class XMLUtil method fillConnections.

@SuppressWarnings("rawtypes")
private static void fillConnections(Element element, DisplayModel displayModel) throws Exception {
    if (element.getName().equals(XMLTAG_CONNECTION)) {
        ConnectionModel result = new ConnectionModel(displayModel);
        setPropertiesFromXML(element, result);
    } else if (element.getName().equals(XMLTAG_DISPLAY)) {
        List children = element.getChildren();
        Iterator iterator = children.iterator();
        while (iterator.hasNext()) {
            Element subElement = (Element) iterator.next();
            if (subElement.getName().equals(XMLTAG_CONNECTION)) {
                fillConnections(subElement, displayModel);
            }
        }
    }
}
Also used : LineAwareElement(org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement) Element(org.jdom.Element) Iterator(java.util.Iterator) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ConnectionModel

use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.

the class ReplaceWidgetCommand method getAllConnections.

private List<ConnectionModel> getAllConnections(AbstractWidgetModel widget, boolean source) {
    List<ConnectionModel> result = new ArrayList<ConnectionModel>();
    result.addAll(source ? widget.getSourceConnections() : widget.getTargetConnections());
    if (widget instanceof AbstractContainerModel) {
        for (AbstractWidgetModel child : ((AbstractContainerModel) widget).getAllDescendants()) {
            result.addAll(source ? child.getSourceConnections() : child.getTargetConnections());
        }
    }
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ArrayList(java.util.ArrayList) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel)

Example 4 with ConnectionModel

use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.

the class ReplaceWidgetCommand method undo.

@Override
public void undo() {
    container.removeChild(targetWidget);
    container.addChild(index, srcWidget);
    for (ConnectionModel conn : sourceConnections) {
        if (conn.getSource() == targetWidget)
            conn.setSource(srcWidget);
    }
    for (ConnectionModel conn : targetConnections) {
        if (conn.getTarget() == targetWidget)
            conn.setTarget(srcWidget);
    }
    removeConnections(sourceConnections);
    removeConnections(targetConnections);
    addConnections(sourceConnections);
    addConnections(targetConnections);
}
Also used : ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel)

Example 5 with ConnectionModel

use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.

the class AbstractPolyEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    super.registerPropertyChangeHandlers();
    // points
    IWidgetPropertyChangeHandler pointsHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            Polyline polyline = (Polyline) refreshableFigure;
            PointList points = (PointList) newValue;
            if (points.size() != polyline.getPoints().size()) {
                anchorMap = null;
                // delete connections on deleted points
                if (points.size() < polyline.getPoints().size()) {
                    for (ConnectionModel conn : getWidgetModel().getSourceConnections()) {
                        if (Integer.parseInt(conn.getSourceTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                    for (ConnectionModel conn : getWidgetModel().getTargetConnections()) {
                        if (Integer.parseInt(conn.getTargetTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                }
            }
            // deselect the widget (this refreshes the polypoint drag
            // handles)
            int selectionState = getSelected();
            setSelected(EditPart.SELECTED_NONE);
            polyline.setPoints(points);
            doRefreshVisuals(polyline);
            // restore the selection state
            setSelected(selectionState);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_POINTS, pointsHandler);
    IWidgetPropertyChangeHandler rotationHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            getWidgetModel().setPoints(PointsUtil.rotatePoints(getWidgetModel().getOriginalPoints().getCopy(), (Double) newValue), false);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_ROTATION, rotationHandler);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) Polyline(org.eclipse.draw2d.Polyline) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)14 ArrayList (java.util.ArrayList)5 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)5 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)5 PointList (org.eclipse.draw2d.geometry.PointList)5 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 LineAwareElement (org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement)3 Element (org.jdom.Element)3 ConnectionReconnectCommand (org.csstudio.opibuilder.commands.ConnectionReconnectCommand)2 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)1 ChangeGuideCommand (org.csstudio.opibuilder.commands.ChangeGuideCommand)1 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)1 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)1 WidgetSetConstraintCommand (org.csstudio.opibuilder.commands.WidgetSetConstraintCommand)1