Search in sources :

Example 31 with AbstractContainerModel

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

the class FixedPointsConnectionRouter method getScrollPaneImpl.

private ScrollPane getScrollPaneImpl() {
    if (connectionModel != null) {
        if (connectionModel.getScrollPane() != null) {
            return connectionModel.getScrollPane();
        } else {
            // are both connected widgets defined - this should be always true
            if ((connectionModel.getSource() == null) || (connectionModel.getTarget() == null))
                return null;
            AbstractContainerModel sourceModel = connectionModel.getSource().getParent();
            AbstractContainerModel targetModel = connectionModel.getTarget().getParent();
            // if one of them is null, then at least one end if the connection is in the top-most container. No translation.
            if ((sourceModel == null) || (targetModel == null))
                return null;
            // otherwise, see if any of them is scrollable
            AbstractScrollableEditpart sourceEditpart = getScrollable(sourceModel.getEditPart());
            AbstractScrollableEditpart targetEditpart = getScrollable(targetModel.getEditPart());
            // if one of them is not linking container, then return null
            if ((sourceEditpart == null) || (targetEditpart == null))
                return null;
            // now we have two options:
            // - one linking container is inside the other
            // - they are not one inside the other, but they have common parent
            // option one?
            ScrollPane scrollPane = getScrollPaneForContained(sourceEditpart, targetEditpart);
            if (scrollPane != null)
                return scrollPane;
            // option two
            return getCommonScrollableParent(sourceEditpart, targetEditpart);
        }
    }
    return null;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) ScrollPane(org.eclipse.draw2d.ScrollPane)

Example 32 with AbstractContainerModel

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

the class WidgetXYLayoutEditPolicy method createAddCommand.

@SuppressWarnings("deprecation")
@Override
protected Command createAddCommand(EditPart child, Object constraint) {
    if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
        return super.createAddCommand(child, constraint);
    AbstractContainerModel container = (AbstractContainerModel) getHost().getModel();
    AbstractWidgetModel widget = (AbstractWidgetModel) child.getModel();
    CompoundCommand result = new CompoundCommand("Adding widgets to container");
    result.add(new AddWidgetCommand(container, widget, (Rectangle) constraint));
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 33 with AbstractContainerModel

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

the class XMLUtil method XMLElementToWidgetSub.

private static AbstractWidgetModel XMLElementToWidgetSub(Element element, DisplayModel displayModel, List<IPath> trace, final 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 {
        String errorMessage = "Unknown Tag: " + element.getName();
        ConsoleService.getInstance().writeError(errorMessage);
        return null;
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel)

Example 34 with AbstractContainerModel

use of org.csstudio.opibuilder.model.AbstractContainerModel 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)

Aggregations

AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)34 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)27 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)11 ArrayList (java.util.ArrayList)10 Rectangle (org.eclipse.draw2d.geometry.Rectangle)10 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)9 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)7 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)6 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)5 IFigure (org.eclipse.draw2d.IFigure)5 Point (org.eclipse.draw2d.geometry.Point)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeListener (java.beans.PropertyChangeListener)4 List (java.util.List)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)4 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4 HashMap (java.util.HashMap)3 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)3