Search in sources :

Example 6 with AbstractWidgetModel

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

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

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

the class ChangeOrderAction method fillWidgetMap.

/**
 * @param widgetMap
 */
private void fillWidgetMap(Map<AbstractContainerModel, List<IndexedWidget>> widgetMap) {
    for (Object selection : getSelectedObjects()) {
        if (selection instanceof AbstractBaseEditPart) {
            AbstractBaseEditPart widgetEditpart = (AbstractBaseEditPart) selection;
            AbstractWidgetModel widgetModel = (AbstractWidgetModel) widgetEditpart.getModel();
            if (widgetEditpart.getParent() != null && widgetModel.getParent() != null) {
                AbstractContainerModel containerModel = (AbstractContainerModel) widgetEditpart.getParent().getModel();
                if (!widgetMap.containsKey(containerModel)) {
                    widgetMap.put(containerModel, new LinkedList<IndexedWidget>());
                }
                widgetMap.get(containerModel).add(new IndexedWidget(containerModel.getIndexOf(widgetModel), widgetModel));
            }
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart)

Example 9 with AbstractWidgetModel

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

the class DistributeWidgetsAction method getSortedModelArray.

private AbstractWidgetModel[] getSortedModelArray(final boolean byHorizontal) {
    AbstractWidgetModel[] modelArray = new AbstractWidgetModel[getSelectedWidgetModels().size()];
    int i = 0;
    for (AbstractWidgetModel model : getSelectedWidgetModels()) {
        modelArray[i++] = model;
    }
    Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {

        @Override
        public int compare(AbstractWidgetModel o1, AbstractWidgetModel o2) {
            int o1loc, o2loc;
            if (byHorizontal) {
                o1loc = o1.getLocation().x;
                o2loc = o2.getLocation().x;
            } else {
                o1loc = o1.getLocation().y;
                o2loc = o2.getLocation().y;
            }
            if (o1loc < o2loc)
                return -1;
            else if (o1loc > o2loc)
                return 1;
            else
                return 0;
        }
    });
    return modelArray;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel)

Example 10 with AbstractWidgetModel

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

the class OPIWidgetsTransfer method nativeToJava.

@Override
public Object nativeToJava(TransferData transferData) {
    if (!isSupportedType(transferData))
        return null;
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    if (bytes == null)
        return null;
    try {
        DisplayModel displayModel = // $NON-NLS-1$
        (DisplayModel) XMLUtil.fillWidgetsFromXMLString(new String(bytes, "UTF-8"), null);
        List<AbstractWidgetModel> widgets = displayModel.getChildren();
        return widgets;
    } catch (Exception e) {
        OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to transfer XML to widget", e);
    }
    return null;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel)

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