Search in sources :

Example 36 with TreeNode

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

the class XmlMapUtil method isExpressionEditable.

public static boolean isExpressionEditable(TreeNode treeNode) {
    List children = treeNode.getChildren();
    if (treeNode.isChoice() || treeNode.isSubstitution()) {
        return false;
    }
    boolean haschild = false;
    boolean isNameSpace = false;
    if (children.size() > 0) {
        for (int i = 0; i < children.size(); i++) {
            TreeNode child = (TreeNode) children.get(i);
            // attribute and namespace are not treat as subnode , so the expression of treeNode should be editable.
            if (NodeType.ATTRIBUT != child.getNodeType() && NodeType.NAME_SPACE != child.getNodeType()) {
                haschild = true;
                break;
            }
        }
    } else if (NodeType.NAME_SPACE.equals(treeNode.getNodeType())) {
        isNameSpace = true;
    }
    return !haschild && !isNameSpace;
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List)

Example 37 with TreeNode

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

the class XmlMapUtil method getParentLoopNodeEditPart.

public static OutputTreeNodeEditPart getParentLoopNodeEditPart(OutputTreeNodeEditPart nodePart) {
    if (nodePart != null && nodePart instanceof OutputTreeNodeEditPart) {
        OutputTreeNodeEditPart nodePartTemp = nodePart;
        TreeNode model = (TreeNode) nodePartTemp.getModel();
        if (model.isLoop()) {
            return nodePartTemp;
        } else {
            if (nodePartTemp.getParent() != null && nodePartTemp.getParent() instanceof OutputTreeNodeEditPart) {
                return getParentLoopNodeEditPart((OutputTreeNodeEditPart) nodePartTemp.getParent());
            }
        }
    }
    return null;
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Example 38 with TreeNode

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

the class MapDataHelper method rebuildInputTree.

public void rebuildInputTree(InputXmlTree inputTree, IMetadataTable metadataTable, XmlMapData mapData) {
    if (metadataTable != null && metadataTable.getListColumns() != null) {
        List<IMetadataColumn> listColumns = metadataTable.getListColumns();
        EList<TreeNode> nodes = inputTree.getNodes();
        for (int i = 0; i < listColumns.size(); i++) {
            IMetadataColumn column = listColumns.get(i);
            TreeNode found = null;
            int j = 0;
            for (; j < nodes.size(); j++) {
                TreeNode node = nodes.get(j);
                if (node.getName() != null && node.getName().equals(column.getLabel())) {
                    found = node;
                    break;
                }
            }
            if (found != null) {
                // set in case talend type changed in metadata
                found.setType(column.getTalendType());
                if (i != j) {
                    // do switch to keep the same sequence
                    TreeNode temp = nodes.get(j);
                    nodes.remove(j);
                    nodes.add(i, temp);
                }
            } else {
                found = XmlmapFactory.eINSTANCE.createTreeNode();
                found.setName(column.getLabel());
                found.setType(column.getTalendType());
                found.setNullable(column.isNullable());
                found.setXpath(XmlMapUtil.getXPath(inputTree.getName(), found.getName(), found.getNodeType()));
                nodes.add(i, found);
            }
            // add a default root for document
            if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
                EList<TreeNode> children = found.getChildren();
                // if type is changed from a non-document to document
                if (children.isEmpty()) {
                    XmlMapUtil.detachNodeConnections(found, mapData, true);
                    TreeNode treeRoot = XmlmapFactory.eINSTANCE.createTreeNode();
                    treeRoot.setName("root");
                    treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                    treeRoot.setNodeType(NodeType.ELEMENT);
                    treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(), treeRoot.getName(), treeRoot.getNodeType()));
                    treeRoot.setLoop(true);
                    treeRoot.setMain(true);
                    children.add(treeRoot);
                }
            } else // remove children and connections for children if not document
            {
                EList<TreeNode> children = found.getChildren();
                if (!children.isEmpty()) {
                    XmlMapUtil.detachNodeConnections(found, mapData, true);
                    List<TreeNode> copyOfChildren = new ArrayList<TreeNode>(found.getChildren());
                    found.getChildren().clear();
                    if (!inputTree.isLookup() && inputTree.isMultiLoops()) {
                        List<TreeNode> oldLoops = new ArrayList<TreeNode>();
                        XmlMapUtil.getChildLoops(oldLoops, copyOfChildren);
                        inputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(inputTree));
                        XmlMapUtil.removeloopInOutputTree(mapData, inputTree, oldLoops);
                    }
                }
            }
        }
        if (nodes.size() > listColumns.size()) {
            List unUsed = new ArrayList();
            for (int i = listColumns.size(); i < nodes.size(); i++) {
                XmlMapUtil.detachNodeConnections(nodes.get(i), mapData, true);
                unUsed.add(nodes.get(i));
            }
            nodes.removeAll(unUsed);
        }
    }
    // be deleted
    if (inputTree.isLookup()) {
        rebuildInputNodesConnections(inputTree.getNodes(), mapData);
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 39 with TreeNode

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

the class XMLMapperHelper method hasDocumentInMainInput.

private static boolean hasDocumentInMainInput(final INode xmlMapperNode) {
    boolean hasDocumentInMainInput = false;
    List<? extends IConnection> inConnections = (List<? extends IConnection>) xmlMapperNode.getIncomingConnections();
    XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
    if (xmlMapData != null && inConnections != null && inConnections.size() > 0) {
        List<InputXmlTree> inputTables = xmlMapData.getInputTrees();
        HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
        for (IConnection connection : inConnections) {
            hNameToConnection.put(connection.getName(), connection);
        }
        for (InputXmlTree inputTable : inputTables) {
            String tableName = inputTable.getName();
            IConnection connection = hNameToConnection.get(tableName);
            if (connection == null) {
                continue;
            }
            if (!(inputTable.isLookup())) {
                for (TreeNode node : inputTable.getNodes()) {
                    if ("id_Document".equals(node.getType())) {
                        hasDocumentInMainInput = true;
                        break;
                    }
                }
            }
        }
    }
    return hasDocumentInMainInput;
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) HashMap(java.util.HashMap) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) IConnection(org.talend.core.model.process.IConnection) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 40 with TreeNode

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

the class XmlMapUtil method detachConnectionsSouce.

public static void detachConnectionsSouce(AbstractNode treeNode, XmlMapData mapData, boolean detachChildren) {
    for (Connection connection : treeNode.getIncomingConnections()) {
        AbstractNode source = connection.getSource();
        if (source.getOutgoingConnections().contains(connection)) {
            source.getOutgoingConnections().remove(connection);
            mapData.getConnections().remove(connection);
        }
    }
    treeNode.getIncomingConnections().clear();
    if (treeNode instanceof OutputTreeNode) {
        OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
        if (!XmlMapUtil.isExpressionEditable(outputTreeNode) && outputTreeNode.isAggregate()) {
            outputTreeNode.setAggregate(false);
        }
        if (detachChildren && !outputTreeNode.getChildren().isEmpty()) {
            for (int i = 0; i < outputTreeNode.getChildren().size(); i++) {
                TreeNode child = outputTreeNode.getChildren().get(i);
                detachConnectionsSouce(child, mapData);
            }
        }
    }
    treeNode.setExpression("");
}
Also used : AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) 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) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Aggregations

TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)119 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)88 ArrayList (java.util.ArrayList)39 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)34 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)26 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)25 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)22 List (java.util.List)21 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)19 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)17 EList (org.eclipse.emf.common.util.EList)15 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)14 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)13 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)12 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)12 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)11 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)10 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)9 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)9 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)8