Search in sources :

Example 41 with AbstractWidgetModel

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

the class WidgetDeleteCommand 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 42 with AbstractWidgetModel

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

the class ContainerTreeEditpart method activate.

@Override
public void activate() {
    super.activate();
    childrenPropertyChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getOldValue() instanceof Integer) {
                addChild(createChild(evt.getNewValue()), ((Integer) evt.getOldValue()).intValue());
            } else if (evt.getOldValue() instanceof AbstractWidgetModel) {
                EditPart child = (EditPart) getViewer().getEditPartRegistry().get(evt.getOldValue());
                if (child != null)
                    removeChild(child);
            } else
                refreshChildren();
            refreshVisuals();
        }
    };
    getWidgetModel().getChildrenProperty().addPropertyChangeListener(childrenPropertyChangeListener);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertyChangeListener(java.beans.PropertyChangeListener) RootEditPart(org.eclipse.gef.RootEditPart) EditPart(org.eclipse.gef.EditPart)

Example 43 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)

Example 44 with AbstractWidgetModel

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

the class XMLUtil method XMLElementToWidgetSub.

private static AbstractWidgetModel XMLElementToWidgetSub(Element element, DisplayModel displayModel, List<IPath> trace, MacrosInput macrosInput_) throws Exception {
    if (element == null) {
        return null;
    }
    AbstractWidgetModel result = null;
    if (WIDGET_TAGS.contains(element.getName())) {
        result = fillWidgets(element, displayModel);
        if (result instanceof AbstractContainerModel) {
            fillLinkingContainersSub((AbstractContainerModel) result, trace, macrosInput_);
        }
        fillConnections(element, displayModel);
        return result;
    } else {
        var errorMessage = "Unknown Tag: " + element.getName();
        OPIBuilderPlugin.getLogger().log(Level.SEVERE, errorMessage);
        return null;
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel)

Example 45 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)) {
        var typeId = element.getAttributeValue(XMLATTR_TYPEID);
        var desc = WidgetsService.getInstance().getWidgetDescriptor(typeId);
        if (desc != null) {
            rootWidgetModel = desc.getWidgetModel();
        }
        if (rootWidgetModel == null) {
            var errorMessage = NLS.bind("Unknown widget: {0}", typeId);
            ErrorHandlerUtil.handleError(errorMessage, new Exception("Widget does not exist."));
            return null;
        }
    } else if (element.getName().equals(XMLTAG_CONNECTION)) {
        rootWidgetModel = new ConnectionModel(displayModel);
    } else {
        var errorMessage = "Unknown Tag: " + element.getName();
        OPIBuilderPlugin.getLogger().log(Level.SEVERE, errorMessage);
        return null;
    }
    setPropertiesFromXML(element, rootWidgetModel);
    if (rootWidgetModel instanceof AbstractContainerModel) {
        var container = (AbstractContainerModel) rootWidgetModel;
        var children = element.getChildren();
        var iterator = children.iterator();
        while (iterator.hasNext()) {
            var 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) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException)

Aggregations

AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)50 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)15 ArrayList (java.util.ArrayList)11 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)10 Point (org.eclipse.draw2d.geometry.Point)7 Rectangle (org.eclipse.draw2d.geometry.Rectangle)7 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)7 EditPart (org.eclipse.gef.EditPart)6 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)5 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)5 IFigure (org.eclipse.draw2d.IFigure)5 PropertyChangeListener (java.beans.PropertyChangeListener)4 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)3 ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)3 EditPolicy (org.eclipse.gef.EditPolicy)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 List (java.util.List)2 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)2