Search in sources :

Example 26 with Element

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method isMappedChoiceSubsOutput.

private boolean isMappedChoiceSubsOutput(FOXTreeNode node, String pXpath) {
    List<FOXTreeNode> children = node.getChildren();
    List<FOXTreeNode> subsChoice = new ArrayList<FOXTreeNode>();
    XMLFileNode found = null;
    for (FOXTreeNode child : children) {
        if (child.isSubstitution() || child.isChoice()) {
            subsChoice.add(child);
        } else {
            String childXpath = "";
            if (child instanceof Element) {
                childXpath = XmlMapUtil.getXPath(pXpath, child.getLabel(), NodeType.ELEMENT);
            } else if (child instanceof Attribute) {
                childXpath = XmlMapUtil.getXPath(pXpath, child.getLabel(), NodeType.ATTRIBUT);
            } else if (child instanceof NameSpaceNode) {
                childXpath = XmlMapUtil.getXPath(pXpath, child.getLabel(), NodeType.NAME_SPACE);
            }
            found = findXmlFileNode(childXpath, root);
            if (found == null) {
                found = findXmlFileNode(childXpath, group);
            }
            if (found == null) {
                found = findXmlFileNode(childXpath, loop);
            }
            if (found != null) {
                break;
            }
        }
    }
    if (found != null) {
        return true;
    }
    if (!subsChoice.isEmpty()) {
        for (FOXTreeNode foxNode : subsChoice) {
            boolean isChildMapped = isMappedChoiceSubsOutput(foxNode, pXpath);
            if (isChildMapped) {
                return true;
            }
        }
    }
    return found != null;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) ArrayList(java.util.ArrayList)

Example 27 with Element

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.

the class FOXManager method addElement.

protected FOXTreeNode addElement(FOXTreeNode current, String currentPath, String newPath, String defaultValue) {
    //$NON-NLS-1$
    String name = newPath.substring(newPath.lastIndexOf("/") + 1);
    //$NON-NLS-1$
    String parentPath = newPath.substring(0, newPath.lastIndexOf("/"));
    FOXTreeNode temp = new Element(name, defaultValue);
    if (current == null) {
        // root node
        return temp;
    }
    if (currentPath.equals(parentPath)) {
        current.addChild(temp);
    } else {
        //$NON-NLS-1$
        String[] nods = currentPath.split("/");
        //$NON-NLS-1$
        String[] newNods = parentPath.split("/");
        int parentLevel = 0;
        int checkLength = nods.length < newNods.length ? nods.length : newNods.length;
        for (int i = 1; i < checkLength; i++) {
            if (nods[i].equals(newNods[i])) {
                parentLevel = i;
            }
        }
        FOXTreeNode parent = current;
        for (int i = 0; i < nods.length - (parentLevel + 1); i++) {
            FOXTreeNode tmpParent = parent.getParent();
            if (tmpParent == null) {
                break;
            }
            parent = tmpParent;
        }
        if (parent != null)
            parent.addChild(temp);
    }
    return temp;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 28 with Element

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.

the class MultiFOXManager method getLoopTable.

@Override
public List<Map<String, String>> getLoopTable() {
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    for (FOXTreeNode rootNode : this.getOriginalNodes()) {
        Element loopNode = (Element) org.talend.metadata.managment.ui.wizard.metadata.xml.utils.TreeUtil.getLoopNode(rootNode);
        if (loopNode != null) {
            String path = TreeUtil.getPath(loopNode);
            //$NON-NLS-1$
            tableLoader(loopNode, path.substring(0, path.lastIndexOf("/")), result, loopNode.getDefaultValue());
        }
    }
    return result;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with Element

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.

the class FOXManager method initModel.

public void initModel() {
    IMetadataTable metadataTable = foxComponent.getMetadataTable();
    if (metadataTable == null) {
        metadataTable = new MetadataTable();
    }
    String componentName = foxComponent.getComponent().getName();
    //        if (componentName.equals("tWriteXMLField")) { //$NON-NLS-1$ //$NON-NLS-2$
    IConnection inConn = null;
    for (IConnection conn : foxComponent.getIncomingConnections()) {
        if ((conn.getLineStyle().equals(EConnectionType.FLOW_MAIN)) || (conn.getLineStyle().equals(EConnectionType.FLOW_REF))) {
            inConn = conn;
            break;
        }
    }
    if (inConn != null) {
        metadataTable = inConn.getMetadataTable();
    }
    // }
    treeData = new ArrayList<FOXTreeNode>();
    FOXTreeNode rootNode = null;
    FOXTreeNode current = null;
    FOXTreeNode temp = null;
    FOXTreeNode mainNode = null;
    String mainPath = null;
    String currentPath = null;
    String defaultValue = null;
    int nodeOrder = 0;
    boolean haveOrder = true;
    // build root tree
    List<Map<String, String>> rootTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.ROOT);
    for (Map<String, String> rootMap : rootTable) {
        String newPath = rootMap.get(FileOutputXMLComponent.PATH);
        defaultValue = rootMap.get(FileOutputXMLComponent.VALUE);
        String orderValue = rootMap.get(FileOutputXMLComponent.ORDER);
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = Integer.valueOf(rootMap.get(FileOutputXMLComponent.ORDER)).intValue();
        }
        if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
            //$NON-NLS-1$
            temp = new Attribute(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setAttribute(true);
            current.addChild(temp);
        } else if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
            //$NON-NLS-1$
            temp = new NameSpaceNode(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setNameSpace(true);
            current.addChild(temp);
        } else {
            temp = this.addElement(current, currentPath, newPath, defaultValue);
            if (rootNode == null) {
                rootNode = temp;
            }
            if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
                //$NON-NLS-1$
                temp.setMain(true);
                mainNode = temp;
                mainPath = newPath;
            }
            current = temp;
            currentPath = newPath;
        }
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        String columnName = rootMap.get(FileOutputXMLComponent.COLUMN);
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(metadataTable.getColumn(columnName));
        }
    }
    // build group tree
    current = mainNode;
    currentPath = mainPath;
    boolean isFirst = true;
    List<Map<String, String>> groupTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.GROUP);
    for (Map<String, String> groupMap : groupTable) {
        String newPath = groupMap.get(FileOutputXMLComponent.PATH);
        defaultValue = groupMap.get(FileOutputXMLComponent.VALUE);
        String orderValue = groupMap.get(FileOutputXMLComponent.ORDER);
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = Integer.valueOf(groupMap.get(FileOutputXMLComponent.ORDER)).intValue();
        }
        if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
            //$NON-NLS-1$
            temp = new Attribute(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setAttribute(true);
            current.addChild(temp);
        } else if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
            //$NON-NLS-1$
            temp = new NameSpaceNode(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setNameSpace(true);
            current.addChild(temp);
        } else {
            temp = this.addElement(current, currentPath, newPath, defaultValue);
            if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
                //$NON-NLS-1$
                temp.setMain(true);
                mainNode = temp;
                mainPath = newPath;
            }
            if (isFirst) {
                temp.setGroup(true);
                isFirst = false;
            }
            current = temp;
            currentPath = newPath;
        }
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        String columnName = groupMap.get(FileOutputXMLComponent.COLUMN);
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(metadataTable.getColumn(columnName));
        }
    }
    // build loop tree
    current = mainNode;
    currentPath = mainPath;
    isFirst = true;
    List<Map<String, String>> loopTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.LOOP);
    for (Map<String, String> loopMap : loopTable) {
        String newPath = loopMap.get(FileOutputXMLComponent.PATH);
        defaultValue = loopMap.get(FileOutputXMLComponent.VALUE);
        String orderValue = loopMap.get(FileOutputXMLComponent.ORDER);
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = Integer.valueOf(loopMap.get(FileOutputXMLComponent.ORDER)).intValue();
        }
        if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
            //$NON-NLS-1$
            temp = new Attribute(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setAttribute(true);
            current.addChild(temp);
        } else if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
            //$NON-NLS-1$
            temp = new NameSpaceNode(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setNameSpace(true);
            current.addChild(temp);
        } else {
            temp = this.addElement(current, currentPath, newPath, defaultValue);
            if (rootNode == null) {
                rootNode = temp;
            }
            if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
                //$NON-NLS-1$
                temp.setMain(true);
            }
            if (isFirst) {
                temp.setLoop(true);
                isFirst = false;
            }
            current = temp;
            currentPath = newPath;
        }
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        String columnName = loopMap.get(FileOutputXMLComponent.COLUMN);
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(metadataTable.getColumn(columnName));
        }
    }
    if (rootNode == null) {
        //$NON-NLS-1$
        rootNode = new Element("rootTag");
    }
    rootNode.setParent(null);
    if (haveOrder) {
        orderNode(rootNode);
    }
    treeData.add(rootNode);
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with Element

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.

the class FOXManager method getGroupTable.

public List<Map<String, String>> getGroupTable() {
    if (currentSchema != null) {
        treeData = contents.get(currentSchema);
    }
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    Element groupNode = (Element) TreeUtil.getGroupNode(this.treeData.get(0));
    if (groupNode != null) {
        String path = TreeUtil.getPath(groupNode);
        //$NON-NLS-1$
        tableLoader(groupNode, path.substring(0, path.lastIndexOf("/")), result, groupNode.getDefaultValue());
    }
    return result;
}
Also used : Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Element (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)32 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)29 Attribute (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute)18 NameSpaceNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode)17 ArrayList (java.util.ArrayList)15 Iterator (java.util.Iterator)10 HashMap (java.util.HashMap)6 Map (java.util.Map)6 TreePath (org.eclipse.jface.viewers.TreePath)4 List (java.util.List)3 EList (org.eclipse.emf.common.util.EList)3 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 XMLFileNode (org.talend.core.model.metadata.builder.connection.XMLFileNode)2 IConnection (org.talend.core.model.process.IConnection)2 ATreeNode (org.talend.datatools.xml.utils.ATreeNode)2 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)1