Search in sources :

Example 51 with InputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree in project tdi-studio-se by Talend.

the class XmlMapService method externalEmfDataClone.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.core.service.IXmlMapService#externalEmfDataClone(org.talend.designer.core.model.utils.emf.talendfile
     * .AbstractExternalData)
     */
@Override
public AbstractExternalData externalEmfDataClone(AbstractExternalData externalEmfData) {
    if (!(externalEmfData instanceof XmlMapData)) {
        return externalEmfData;
    }
    Map<EObject, EObject> nodeMaps = new HashMap<EObject, EObject>();
    XmlMapData newXmlMapData = XmlmapFactory.eINSTANCE.createXmlMapData();
    XmlMapData xmlMapData = (XmlMapData) externalEmfData;
    EList<InputXmlTree> oriInputs = xmlMapData.getInputTrees();
    EList<OutputXmlTree> oriOutputs = xmlMapData.getOutputTrees();
    EList<VarTable> oriVars = xmlMapData.getVarTables();
    EList<IConnection> oriConns = xmlMapData.getConnections();
    for (IConnection oriConn : oriConns) {
        if (oriConn instanceof INodeConnection) {
            AbstractNode sourceNode = ((INodeConnection) oriConn).getSource();
            AbstractNode targetNode = ((INodeConnection) oriConn).getTarget();
            EObject source = null;
            if (nodeMaps.get(sourceNode) != null) {
                source = nodeMaps.get(sourceNode);
            } else {
                source = cloneTreeNode(sourceNode);
                nodeMaps.put(sourceNode, source);
            }
            EObject target = null;
            if (nodeMaps.get(targetNode) != null) {
                target = nodeMaps.get(targetNode);
            } else {
                target = cloneTreeNode(targetNode);
                nodeMaps.put(targetNode, target);
            }
            if (oriConn instanceof Connection) {
                new XmlMapConnectionBuilder().createConnection((AbstractNode) source, (AbstractNode) target, newXmlMapData);
            } else if (oriConn instanceof LookupConnection) {
                new XmlMapConnectionBuilder().createLookupConnection((TreeNode) source, (TreeNode) target, newXmlMapData);
            }
        } else if (oriConn instanceof FilterConnection) {
            AbstractNode sourceNode = ((FilterConnection) oriConn).getSource();
            AbstractInOutTree targetNode = ((FilterConnection) oriConn).getTarget();
            EObject source = null;
            if (nodeMaps.get(sourceNode) != null) {
                source = nodeMaps.get(sourceNode);
            } else {
                source = cloneTreeNode(sourceNode);
                nodeMaps.put(sourceNode, source);
            }
            EObject target = null;
            if (nodeMaps.get(targetNode) != null) {
                target = nodeMaps.get(targetNode);
            } else {
                target = cloneTreeNode(targetNode);
                nodeMaps.put(targetNode, target);
            }
            new XmlMapConnectionBuilder().createFilterConnection((AbstractNode) source, (AbstractInOutTree) target, newXmlMapData);
        }
    }
    for (InputXmlTree inputXml : oriInputs) {
        InputXmlTree newInputXml = null;
        if (nodeMaps.get(inputXml) == null) {
            newInputXml = (InputXmlTree) cloneTreeNode(inputXml);
        } else {
            newInputXml = (InputXmlTree) nodeMaps.get(inputXml);
        }
        if (inputXml.getNodes() != null) {
            for (TreeNode treeNode : inputXml.getNodes()) {
                EObject obj = nodeMaps.get(treeNode);
                if ((obj != null) && !newInputXml.getNodes().contains(obj)) {
                    newInputXml.getNodes().add((TreeNode) obj);
                }
            }
        }
        if (!newXmlMapData.getInputTrees().contains(newInputXml)) {
            newXmlMapData.getInputTrees().add(newInputXml);
        }
        nodeMaps.put(inputXml, newInputXml);
    }
    for (OutputXmlTree outputXml : oriOutputs) {
        OutputXmlTree newOutputXml = null;
        if (nodeMaps.get(outputXml) == null) {
            newOutputXml = (OutputXmlTree) cloneTreeNode(outputXml);
        } else {
            newOutputXml = (OutputXmlTree) nodeMaps.get(outputXml);
        }
        if (outputXml.getNodes() != null) {
            for (OutputTreeNode treeNode : outputXml.getNodes()) {
                EObject obj = nodeMaps.get(treeNode);
                if ((obj != null) && !newOutputXml.getNodes().contains(obj)) {
                    newOutputXml.getNodes().add((OutputTreeNode) obj);
                }
            }
        }
        // }
        if (!newXmlMapData.getOutputTrees().contains(newOutputXml)) {
            newXmlMapData.getOutputTrees().add(newOutputXml);
        }
        nodeMaps.put(outputXml, newOutputXml);
    }
    for (VarTable varXml : oriVars) {
        VarTable newVarXml = null;
        if (nodeMaps.get(varXml) == null) {
            newVarXml = XmlmapFactory.eINSTANCE.createVarTable();
            newVarXml.setMinimized(varXml.isMinimized());
            newVarXml.setName(varXml.getName());
            if (varXml.getNodes() != null) {
                for (VarNode treeNode : varXml.getNodes()) {
                    EObject obj = nodeMaps.get(treeNode);
                    if (obj != null) {
                        newVarXml.getNodes().add((VarNode) obj);
                    }
                }
            }
            if (!newXmlMapData.getVarTables().contains(newVarXml)) {
                newXmlMapData.getVarTables().add(newVarXml);
            }
            nodeMaps.put(varXml, newVarXml);
        }
    }
    return newXmlMapData;
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) HashMap(java.util.HashMap) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) IConnection(org.talend.designer.xmlmap.model.emf.xmlmap.IConnection) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) IConnection(org.talend.designer.xmlmap.model.emf.xmlmap.IConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EObject(org.eclipse.emf.ecore.EObject) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 52 with InputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree in project tdi-studio-se by Talend.

the class DropContextAnalyzer method checkDropInputValid.

private boolean checkDropInputValid(Object target) {
    if (objects.getType() == TransferdType.INPUT) {
        for (Object obj : objects.getToTransfer()) {
            TreeNodeEditPart part = (TreeNodeEditPart) obj;
            AbstractInOutTree srouceTree = XmlMapUtil.getAbstractInOutTree((TreeNode) part.getModel());
            AbstractInOutTree targetTree = null;
            if (target instanceof InputXmlTree) {
                targetTree = (InputXmlTree) target;
            } else {
                targetTree = XmlMapUtil.getAbstractInOutTree((TreeNode) target);
            }
            if (srouceTree == targetTree) {
                return false;
            }
            if (srouceTree.eContainer() instanceof XmlMapData) {
                XmlMapData mapdata = ((XmlMapData) srouceTree.eContainer());
                int indexSource = mapdata.getInputTrees().indexOf(srouceTree);
                int indexTarget = mapdata.getInputTrees().indexOf(targetTree);
                if (indexTarget < indexSource) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)52 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)34 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)28 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)26 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)18 ArrayList (java.util.ArrayList)17 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)12 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)12 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)9 List (java.util.List)5 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)5 IConnection (org.talend.designer.xmlmap.model.emf.xmlmap.IConnection)5 InputXmlTreeEditPart (org.talend.designer.xmlmap.parts.InputXmlTreeEditPart)5 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)4 HashMap (java.util.HashMap)3 Point (org.eclipse.draw2d.geometry.Point)3 EList (org.eclipse.emf.common.util.EList)3 ExpressionFigure (org.talend.designer.gefabstractmap.figures.ExpressionFigure)3 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)3 Iterator (java.util.Iterator)2