Search in sources :

Example 1 with DisplayModel

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

the class WidgetTreeEditpart method getImage.

@Override
protected Image getImage() {
    if (getWidgetModel() instanceof DisplayModel)
        return super.getImage();
    String typeID = getWidgetModel().getTypeID();
    WidgetDescriptor widgetDescriptor = WidgetsService.getInstance().getWidgetDescriptor(typeID);
    Image image = CustomMediaFactory.getInstance().getImageFromPlugin(widgetDescriptor.getPluginId(), widgetDescriptor.getIconPath());
    return image;
}
Also used : DisplayModel(org.csstudio.opibuilder.model.DisplayModel) WidgetDescriptor(org.csstudio.opibuilder.util.WidgetDescriptor) Image(org.eclipse.swt.graphics.Image)

Example 2 with DisplayModel

use of org.csstudio.opibuilder.model.DisplayModel 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 3 with DisplayModel

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

the class CopyWidgetsAction method run.

@Override
public void run() {
    DisplayModel tempModel = new DisplayModel();
    List<AbstractWidgetModel> widgetModels = getSelectedWidgetModels();
    for (AbstractWidgetModel widget : widgetModels) {
        tempModel.addChild(widget, false);
    }
    String xml = XMLUtil.widgetToXMLString(tempModel, false);
    ((OPIEditor) getWorkbenchPart()).getClipboard().setContents(new Object[] { xml }, new Transfer[] { OPIWidgetsTransfer.getInstance() });
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            IAction pasteAction = ((ActionRegistry) ((OPIEditor) getWorkbenchPart()).getAdapter(ActionRegistry.class)).getAction(ActionFactory.PASTE.getId());
            if (pasteAction != null) {
                ((PasteWidgetsAction) pasteAction).refreshEnable();
            }
        }
    });
}
Also used : OPIEditor(org.csstudio.opibuilder.editor.OPIEditor) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IAction(org.eclipse.jface.action.IAction) DisplayModel(org.csstudio.opibuilder.model.DisplayModel)

Example 4 with DisplayModel

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

the class PasteWidgetsAction method getAbsolutePosition.

/**
 * @param widgetModel
 * @return the absolute position of a widget relative to display.
 */
private Point getAbsolutePosition(AbstractWidgetModel widgetModel) {
    if (widgetModel instanceof DisplayModel)
        return new Point(0, 0);
    Point result = widgetModel.getLocation();
    AbstractContainerModel parent = widgetModel.getParent();
    while (!(parent instanceof DisplayModel)) {
        result.translate(parent.getLocation());
        parent = parent.getParent();
    }
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Point(org.eclipse.draw2d.geometry.Point)

Example 5 with DisplayModel

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

the class NewOPIFileWizardPage method getInitialContents.

@Override
protected InputStream getInitialContents() {
    DisplayModel displayModel = new DisplayModel();
    SchemaService.getInstance().applySchema(displayModel);
    String s = XMLUtil.widgetToXMLString(displayModel, true);
    InputStream result = new ByteArrayInputStream(s.getBytes());
    return result;
}
Also used : DisplayModel(org.csstudio.opibuilder.model.DisplayModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

DisplayModel (org.csstudio.opibuilder.model.DisplayModel)19 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)7 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 AbstractLinkingContainerModel (org.csstudio.opibuilder.model.AbstractLinkingContainerModel)2 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)2 LineAwareElement (org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 Element (org.jdom.Element)2 JDOMException (org.jdom.JDOMException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1