Search in sources :

Example 66 with FOXTreeNode

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

the class JSONFileOutputStep2Form method orderNode.

private void orderNode(FOXTreeNode node) {
    // reset the order.
    if (node != null) {
        List<FOXTreeNode> firstSubChildren = node.getChildren();
        FOXTreeNode foundNode = null;
        for (FOXTreeNode childen : firstSubChildren) {
            if (childen.isLoop()) {
                foundNode = childen;
                sortOrder(foundNode, node);
                break;
            } else if (childen.isGroup()) {
                foundNode = childen;
                sortOrder(foundNode, node);
                orderNode(childen);
            } else {
                orderNode(childen);
            }
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)

Example 67 with FOXTreeNode

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode 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 68 with FOXTreeNode

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode 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)

Example 69 with FOXTreeNode

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

the class ImportTreeFromXml method run.

@Override
public void run() {
    List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
    FileDialog f = new FileDialog(shell);
    String file = f.open();
    if (file != null) {
        boolean clickOk = false;
        TreeNode treeNodeRoot = null;
        String detailedMessage = "";
        try {
            clickOk = TreeUtil.getFoxTreeNodesForXmlMap(file, shell, list);
            if (!clickOk) {
                return;
            }
            treeNodeRoot = XmlMapUtil.getTreeNodeRoot(parentNode);
            XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
            parentNode.getChildren().clear();
            prepareEmfTreeNode(list, parentNode);
        } catch (Exception e) {
            ExceptionHandler.process(e);
            StringBuffer sb = new StringBuffer();
            sb.append(e.toString());
            sb.append("\n");
            if (e.getStackTrace() != null) {
                for (StackTraceElement trace : e.getStackTrace()) {
                    sb.append(trace.toString());
                    sb.append("\n");
                }
            }
            detailedMessage = sb.toString();
        }
        boolean childrenEmpty = false;
        if (parentNode.getChildren().isEmpty()) {
            childrenEmpty = true;
            TreeNode rootNode = null;
            if (input) {
                rootNode = XmlmapFactory.eINSTANCE.createTreeNode();
            } else {
                rootNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
            }
            rootNode.setName("root");
            rootNode.setNodeType(NodeType.ELEMENT);
            rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
            rootNode.setXpath(XmlMapUtil.getXPath(parentNode.getXpath(), "root", NodeType.ELEMENT));
            parentNode.getChildren().add(rootNode);
        }
        // set a default loop
        parentNode.getChildren().get(0).setLoop(true);
        parentNode.getChildren().get(0).setMain(true);
        if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
            showError(detailedMessage);
        }
        if (parentNode.eContainer() instanceof InputXmlTree) {
            XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
            connectionBuilder.setCheckRootNodePrefix(true);
            connectionBuilder.rebuildLinks(parentNode, mapperManager.getExternalData());
            mapperManager.refreshTreeSchemaEditor((InputXmlTree) parentNode.eContainer());
        // mapperManager.inputTreeSchemaBeanListModified();
        } else if (parentNode.eContainer() instanceof OutputXmlTree) {
            mapperManager.refreshTreeSchemaEditor((OutputXmlTree) parentNode.eContainer());
        // mapperManager.outputTreeSchemaBeanListModified();
        }
        if (treeNodeRoot != null && treeNodeRoot.eContainer() instanceof AbstractInOutTree) {
            mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) treeNodeRoot.eContainer());
            mapperManager.getMapperUI().updateStatusBar();
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ArrayList(java.util.ArrayList) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 70 with FOXTreeNode

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

the class ImportTreeFromRepository method prepareEmfTreeFromMdm.

private void prepareEmfTreeFromMdm(MDMConnection connection, String selectedConcept) throws Exception {
    if (connection == null || selectedConcept == null) {
        return;
    }
    EList<Concept> schemas = connection.getSchemas();
    Concept selected = null;
    for (int i = 0; i < schemas.size(); i++) {
        Concept concept = schemas.get(i);
        if (selectedConcept.equals(concept.getLabel())) {
            selected = concept;
            break;
        }
    }
    if (selected != null) {
        IMDMProviderService service = (IMDMProviderService) GlobalServiceRegister.getDefault().getService(IMDMProviderService.class);
        if (service != null) {
            boolean initConcepts = service.initConcepts(connection);
            if (initConcepts) {
                if (!MdmConceptType.OUTPUT.equals(selected.getConceptType())) {
                    String prefix = service.getXPathPrefixValue(selected);
                    prefix = TalendTextUtils.removeQuotes(prefix);
                    absoluteXPathQuery = selected.getLoopExpression();
                    EList<ConceptTarget> conceptTargets = selected.getConceptTargets();
                    if (conceptTargets == null || absoluteXPathQuery == null) {
                        return;
                    }
                    this.schemaTargets = conceptTargets;
                    // find corresponding metadata table
                    Set<MetadataTable> metadataTables = ConnectionHelper.getTables(connection);
                    for (MetadataTable table : metadataTables) {
                        if (selected.getLabel() != null && selected.getLabel().equals(table.getLabel())) {
                            metadataTable = table;
                            break;
                        }
                    }
                    List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), absoluteXPathQuery, true);
                    TreeNode pNode = schemaNode;
                    if (MdmConceptType.RECEIVE.equals(selected.getConceptType())) {
                        List<FOXTreeNode> updateNodesList = TreeUtil.parseMDMUpdateReport(shell, true);
                        schemaNode.getChildren().clear();
                        if (updateNodesList == null) {
                            if (prefix != null && !"".equals(prefix)) {
                                String[] preValues = prefix.split(XmlMapUtil.XPATH_SEPARATOR);
                                for (String value : preValues) {
                                    if (!"".equals(value)) {
                                        TreeNode createTreeNode = createModel();
                                        createTreeNode.setName(value);
                                        createTreeNode.setNodeType(NodeType.ELEMENT);
                                        createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                                        createTreeNode.setXpath(XmlMapUtil.getXPath(pNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                        pNode.getChildren().add(createTreeNode);
                                        pNode = createTreeNode;
                                    }
                                }
                                absoluteXPathQuery = prefix + absoluteXPathQuery;
                            }
                        } else {
                            //$NON-NLS-1$
                            TreeNode rootNode = createDefaultTreeNode(pNode, "exchange");
                            //$NON-NLS-1$
                            TreeNode reportNode = createDefaultTreeNode(rootNode, "report");
                            //$NON-NLS-1$
                            TreeNode itemNode = createDefaultTreeNode(rootNode, "item");
                            // parse the update content..
                            prepareEmfTree(updateNodesList, reportNode, true);
                            pNode = itemNode;
                            //$NON-NLS-1$
                            absoluteXPathQuery = "/exchange/item" + absoluteXPathQuery;
                        }
                    } else {
                        schemaNode.getChildren().clear();
                    }
                    prepareEmfTree(list, pNode);
                } else {
                    List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), selected.getRoot().get(0).getXMLPath(), true);
                    schemaNode.getChildren().clear();
                    root = selected.getRoot();
                    loop = selected.getLoop();
                    group = selected.getGroup();
                    groupElements = new ArrayList<TreeNode>();
                    prepareModelFromOutput(list, schemaNode);
                    if (loopNode != null) {
                        fillGroup(loopNode, groupElements);
                    } else {
                        if (!schemaNode.getChildren().isEmpty()) {
                            schemaNode.getChildren().get(0).setLoop(true);
                        }
                    }
                }
            }
        }
    }
}
Also used : Concept(org.talend.core.model.metadata.builder.connection.Concept) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IMDMProviderService(org.talend.core.ui.IMDMProviderService) ConceptTarget(org.talend.core.model.metadata.builder.connection.ConceptTarget) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Aggregations

FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)93 Attribute (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute)29 Element (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)29 NameSpaceNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode)28 ArrayList (java.util.ArrayList)23 Iterator (java.util.Iterator)10 HashMap (java.util.HashMap)8 TreeItem (org.eclipse.swt.widgets.TreeItem)7 Map (java.util.Map)6 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)5 List (java.util.List)4 InputDialog (org.eclipse.jface.dialogs.InputDialog)4 TreePath (org.eclipse.jface.viewers.TreePath)4 EList (org.eclipse.emf.common.util.EList)3 TableItem (org.eclipse.swt.widgets.TableItem)3 Tree (org.eclipse.swt.widgets.Tree)3 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 IConnection (org.talend.core.model.process.IConnection)3 ATreeNode (org.talend.datatools.xml.utils.ATreeNode)3