Search in sources :

Example 1 with PropertiesCopyData

use of org.csstudio.opibuilder.datadefinition.PropertiesCopyData in project yamcs-studio by yamcs.

the class PastePropertiesAction method createPasteCommand.

public Command createPasteCommand() {
    PropertiesCopyData propData = getPropetiesCopyDataFromClipboard();
    CompoundCommand cmd = new CompoundCommand("Paste Properties");
    for (AbstractWidgetModel targetWidget : getSelectedWidgetModels()) {
        for (String prop_id : propData.getPropIDList()) {
            if (targetWidget.getAllPropertyIDs().contains(prop_id)) {
                cmd.add(new SetWidgetPropertyCommand(targetWidget, prop_id, propData.getWidgetModel().getPropertyValue(prop_id)));
            }
        }
    }
    return cmd;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) PropertiesCopyData(org.csstudio.opibuilder.datadefinition.PropertiesCopyData) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with PropertiesCopyData

use of org.csstudio.opibuilder.datadefinition.PropertiesCopyData in project yamcs-studio by yamcs.

the class PropertiesCopyDataTransfer method nativeToJava.

@Override
protected Object nativeToJava(TransferData transferData) {
    if (!isSupportedType(transferData))
        return null;
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    if (bytes == null)
        return null;
    try {
        SAXBuilder saxBuilder = new SAXBuilder();
        // $NON-NLS-1$
        Document doc = saxBuilder.build(new ByteArrayInputStream(bytes));
        Element root = doc.getRootElement();
        List<String> propIDList = new ArrayList<String>();
        AbstractWidgetModel widgetModel = null;
        for (Object o : root.getChildren()) {
            if (o instanceof Element) {
                Element e = (Element) o;
                if (e.getName().equals(CopyPropertiesAction.PROPID_ELEMENT))
                    for (Object po : e.getChildren()) {
                        Element pe = (Element) po;
                        propIDList.add(pe.getName());
                    }
                else
                    widgetModel = XMLUtil.XMLElementToWidget(e);
            }
        }
        return new PropertiesCopyData(widgetModel, propIDList);
    } catch (Exception e) {
        // $NON-NLS-1$
        OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to transfer XML to widget", e);
    }
    return null;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertiesCopyData(org.csstudio.opibuilder.datadefinition.PropertiesCopyData) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Document(org.jdom.Document) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

PropertiesCopyData (org.csstudio.opibuilder.datadefinition.PropertiesCopyData)2 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 Document (org.jdom.Document)1 Element (org.jdom.Element)1 SAXBuilder (org.jdom.input.SAXBuilder)1