Search in sources :

Example 21 with Element

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

the class JSONFileOutputStep2Form method updateConnection.

public void updateConnection() {
    ConnectionHelper.getTables(getConnection());
    EList root = getConnection().getRoot();
    EList loop = getConnection().getLoop();
    EList group = getConnection().getGroup();
    root.clear();
    loop.clear();
    group.clear();
    List<FOXTreeNode> node = (List<FOXTreeNode>) JSONViewer.getInput();
    FOXTreeNode foxTreeNode = node.get(0);
    if (foxTreeNode != null) {
        initNodeOrder(foxTreeNode);
        if (!foxTreeNode.isLoop()) {
            tableLoader((Element) foxTreeNode, "", root, foxTreeNode.getDefaultValue());
        }
        Element loopNode = (Element) TreeUtil.getLoopNode(foxTreeNode);
        if (loopNode != null) {
            String path = TreeUtil.getPath(loopNode);
            tableLoader(loopNode, path.substring(0, path.lastIndexOf("/")), loop, loopNode.getDefaultValue());
        }
        Element groupNode = (Element) TreeUtil.getGroupNode(foxTreeNode);
        if (groupNode != null) {
            String path = TreeUtil.getPath(groupNode);
            tableLoader(groupNode, path.substring(0, path.lastIndexOf("/")), group, groupNode.getDefaultValue());
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) EList(org.eclipse.emf.common.util.EList) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList)

Example 22 with Element

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

the class JSONFileOutputStep2Form 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 23 with Element

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

the class AbstractJSONFileStepForm method initMetadataTable.

protected void initMetadataTable(List<FOXTreeNode> list, EList columnList) {
    int maxColumnsNumber = CoreUIPlugin.getDefault().getPreferenceStore().getInt(ITalendCorePrefConstants.MAXIMUM_AMOUNT_OF_COLUMNS_FOR_XML);
    for (FOXTreeNode node : list) {
        if (columnList.size() > maxColumnsNumber) {
            return;
        }
        MetadataEmfTableEditor editor = new MetadataEmfTableEditor();
        if (node instanceof Element) {
            String label = node.getLabel();
            if (!node.hasChildren() && label != null && !label.equals("")) {
                String columnName = label;
                if (columnName.contains(":")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    columnName = columnName.split(":")[1];
                }
                columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
                String dataType = node.getDataType();
                MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
                metadataColumn.setOriginalField(label);
                metadataColumn.setTalendType(dataType);
                columnList.add(metadataColumn);
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
            }
        }
        if (node instanceof Attribute) {
            String label = node.getLabel();
            if (label != null && !label.equals("")) {
                String columnName = label;
                if (columnName.contains(":")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    columnName = columnName.split(":")[1];
                }
                columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
                String dataType = node.getDataType();
                MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
                metadataColumn.setOriginalField(label);
                metadataColumn.setTalendType(dataType);
                columnList.add(metadataColumn);
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
            }
        }
        if (node.hasChildren()) {
            List<FOXTreeNode> children = node.getChildren();
            initMetadataTable(children, columnList);
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 24 with Element

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

the class JSONFileOutputStep2Form method initJSONTreeData.

private void initJSONTreeData() {
    treeData.clear();
    // metadataColumnList.clear();
    EList root = getConnection().getRoot();
    EList loop = getConnection().getLoop();
    EList group = getConnection().getGroup();
    // initialMetadataColumn();
    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
    for (int i = 0; i < root.size(); i++) {
        JSONFileNode node = (JSONFileNode) root.get(i);
        String newPath = node.getJSONPath();
        defaultValue = node.getDefaultValue();
        String type = node.getType();
        String orderValue = String.valueOf(node.getOrder());
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = node.getOrder();
        }
        if (node.getAttribute().equals("attri")) {
            temp = new Attribute(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setAttribute(true);
            temp.setDataType(type);
            current.addChild(temp);
        } else if (node.getAttribute().equals("ns")) {
            temp = new NameSpaceNode(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setNameSpace(true);
            temp.setDataType(type);
            current.addChild(temp);
        } else {
            temp = this.addElement(current, currentPath, newPath, defaultValue);
            temp.setDataType(type);
            if (rootNode == null) {
                rootNode = temp;
            }
            if (node.getAttribute().equals("main")) {
                temp.setMain(true);
                mainNode = temp;
                mainPath = newPath;
            }
            current = temp;
            currentPath = newPath;
        }
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        String columnName = node.getRelatedColumn();
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(getColumn(columnName));
        }
    }
    // build group tree
    current = mainNode;
    currentPath = mainPath;
    boolean isFirst = true;
    for (int i = 0; i < group.size(); i++) {
        JSONFileNode node = (JSONFileNode) group.get(i);
        String newPath = node.getJSONPath();
        defaultValue = node.getDefaultValue();
        String type = node.getType();
        String orderValue = String.valueOf(node.getOrder());
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = node.getOrder();
        }
        if (node.getAttribute().equals("attri")) {
            temp = new Attribute(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setAttribute(true);
            temp.setDataType(type);
            current.addChild(temp);
        } else if (node.getAttribute().equals("ns")) {
            temp = new NameSpaceNode(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setNameSpace(true);
            temp.setDataType(type);
            current.addChild(temp);
        } else {
            temp = this.addElement(current, currentPath, newPath, defaultValue);
            temp.setDataType(type);
            if (node.getAttribute().equals("main")) {
                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 = node.getRelatedColumn();
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(getColumn(columnName));
        }
    }
    // build loop tree
    current = mainNode;
    currentPath = mainPath;
    isFirst = true;
    for (int i = 0; i < loop.size(); i++) {
        JSONFileNode node = (JSONFileNode) loop.get(i);
        String newPath = node.getJSONPath();
        defaultValue = node.getDefaultValue();
        String type = node.getType();
        String orderValue = String.valueOf(node.getOrder());
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = node.getOrder();
        }
        if (node.getAttribute().equals("attri")) {
            temp = new Attribute(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setAttribute(true);
            temp.setDataType(type);
            temp.setDataType(type);
            current.addChild(temp);
        } else if (node.getAttribute().equals("ns")) {
            temp = new NameSpaceNode(newPath);
            temp.setDefaultValue(defaultValue);
            temp.setNameSpace(true);
            temp.setDataType(type);
            current.addChild(temp);
        } else {
            temp = this.addElement(current, currentPath, newPath, defaultValue);
            temp.setDataType(type);
            // fix for TDI-18802 , if root node is loop
            if (rootNode == null) {
                rootNode = temp;
            }
            if (node.getAttribute().equals("main")) {
                temp.setMain(true);
                mainNode = temp;
                mainPath = newPath;
            }
            if (isFirst) {
                temp.setLoop(true);
                isFirst = false;
            }
            current = temp;
            currentPath = newPath;
        }
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        String columnName = node.getRelatedColumn();
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(getColumn(columnName));
        }
    }
    if (rootNode == null) {
        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) EList(org.eclipse.emf.common.util.EList) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) JSONFileNode(org.talend.repository.model.json.JSONFileNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 25 with Element

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

the class ImportTreeFromXml method prepareEmfTreeNode.

private void prepareEmfTreeNode(List<FOXTreeNode> list, TreeNode parent) {
    if (list == null || list.isEmpty()) {
        return;
    }
    String xPath = parent.getXpath();
    TreeNode realParentNode = parent;
    if (parent.isSubstitution() || parent.isChoice()) {
        realParentNode = XmlMapUtil.getRealParentNode(parent);
        if (realParentNode != null) {
            xPath = realParentNode.getXpath();
        }
    }
    for (FOXTreeNode foxNode : list) {
        TreeNode createTreeNode = null;
        if (input) {
            createTreeNode = XmlmapFactory.eINSTANCE.createTreeNode();
        } else {
            createTreeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
        }
        String label = foxNode.getLabel();
        createTreeNode.setName(label);
        createTreeNode.setOptional(foxNode.isOptional());
        if (foxNode instanceof Element) {
            createTreeNode.setNodeType(NodeType.ELEMENT);
            if (foxNode.isChoice()) {
                createTreeNode.setChoice(foxNode.isChoice());
            } else if (foxNode.isSubstitution()) {
                createTreeNode.setSubstitution(foxNode.isSubstitution());
            }
        } else if (foxNode instanceof Attribute) {
            createTreeNode.setNodeType(NodeType.ATTRIBUT);
        } else if (foxNode instanceof NameSpaceNode) {
            createTreeNode.setNodeType(NodeType.NAME_SPACE);
            createTreeNode.setDefaultValue(foxNode.getDefaultValue());
            if (createTreeNode.getName() == null || createTreeNode.getName().equals("")) {
                createTreeNode.setName(XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX);
            }
        }
        createTreeNode.setXpath(XmlMapUtil.getXPath(xPath, label, createTreeNode.getNodeType()));
        if (foxNode.getDataType() != null && !"".equals(foxNode.getDataType())) {
            if (foxNode.getDataType().equals("id_Date")) {
                //$NON-NLS-1$
                createTreeNode.setPattern("\"dd-MM-yyyy\"");
            }
            createTreeNode.setType(foxNode.getDataType());
        } else {
            createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
        }
        parent.getChildren().add(createTreeNode);
        if (foxNode.getChildren() != null && !foxNode.getChildren().isEmpty()) {
            prepareEmfTreeNode(foxNode.getChildren(), createTreeNode);
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

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