Search in sources :

Example 91 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 checkFieldsValue.

@Override
protected boolean checkFieldsValue() {
    int num = 0, rootNum = 0;
    StringBuffer msgError = new StringBuffer();
    List<FOXTreeNode> onLoopNodes = new ArrayList<FOXTreeNode>();
    for (FOXTreeNode node : treeData) {
        FOXTreeNode rootFOXTreeNode = TreeUtil.getRootFOXTreeNode(node);
        if (rootFOXTreeNode != null) {
            if (existedLoopNode(rootFOXTreeNode)) {
                num++;
            } else {
                onLoopNodes.add(rootFOXTreeNode);
            }
            rootNum++;
        }
    }
    if (num != rootNum) {
        msgError.append("Require set as loop\n");
    }
    if (linker.isNoLinker()) {
        msgError.append("No source and target linked");
    }
    if ("".equals(msgError.toString())) {
        updateStatus(IStatus.OK, null);
        return true;
    }
    updateStatus(IStatus.ERROR, msgError.toString());
    return false;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ArrayList(java.util.ArrayList)

Example 92 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 93 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)

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