Search in sources :

Example 1 with Element

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

the class ImportTreeFromXMLAction method treeNodeAdapt.

private List<FOXTreeNode> treeNodeAdapt(String file) {
    List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
    try {
        ATreeNode treeNode = SchemaPopulationUtil.getSchemaTree(file, true, 0);
        String schemaName = getSelectedSchema();
        String rootName = "";
        if (treeNode.getValue() instanceof String) {
            rootName += "/" + treeNode.getValue();
        }
        FOXTreeNode root = cloneATreeNode(treeNode, schemaName, rootName);
        Element rootElement = (Element) root;
        if (rootElement.getElementChildren() != null && rootElement.getElementChildren().size() > 0) {
            for (FOXTreeNode foxTreeNode : rootElement.getElementChildren()) {
                foxTreeNode.setParent(null);
                list.add(foxTreeNode);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return list;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ATreeNode(org.talend.datatools.xml.utils.ATreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) ArrayList(java.util.ArrayList)

Example 2 with Element

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

the class ImportTreeFromXMLAction method cloneATreeNode.

private FOXTreeNode cloneATreeNode(ATreeNode treeNode, String schemaName, String currentPath) throws Exception {
    FOXTreeNode node = null;
    if (treeNode.getType() == ATreeNode.ATTRIBUTE_TYPE) {
        node = new Attribute();
    } else {
        node = new Element();
    }
    // zli fixed for bug 7414
    if (treeNode.getType() == ATreeNode.NAMESPACE_TYPE) {
        node = new NameSpaceNode();
        //$NON-NLS-1$
        node.setLabel("");
        node.setDefaultValue((String) treeNode.getValue());
    } else {
        node.setLabel((String) treeNode.getValue());
    }
    Object[] children = treeNode.getChildren();
    if (children != null) {
        for (Object element : children) {
            if (element instanceof ATreeNode) {
                ATreeNode child = (ATreeNode) element;
                String newPath = currentPath + "/";
                if (child.getValue() instanceof String) {
                    String elementName = (String) child.getValue();
                    if (currentPath.contains("/" + elementName + "/")) {
                        ExceptionHandler.process(new Exception("XSD ERROR: loop found. Item: " + elementName + " is already in the currentPath (" + currentPath + ")."));
                        continue;
                    }
                    newPath += elementName;
                } else {
                    newPath += "unknownElement";
                }
                FOXTreeNode foxChild = cloneATreeNode(child, schemaName, newPath);
                foxChild.setRow(schemaName);
                node.addChild(foxChild);
            }
        }
    }
    return node;
}
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) ATreeNode(org.talend.datatools.xml.utils.ATreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 3 with Element

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

the class UIManager method validateRootElement.

public boolean validateRootElement() {
    List<FOXTreeNode> treeData = foxManager.getTreeData();
    for (int i = 0; i < treeData.size() - 1; i++) {
        Object obj1 = treeData.get(i);
        Object obj2 = treeData.get(i + 1);
        if (obj1 instanceof Element && obj2 instanceof Element) {
            Element elem1 = (Element) obj1;
            Element elem2 = (Element) obj2;
            if (!elem1.getLabel().equals(elem2.getLabel())) {
                return false;
            }
        }
    }
    return true;
}
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 4 with Element

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

the class CreateElementAction method createChildNode.

/**
     * Create the child node of the input node
     * 
     * @param node
     */
private boolean createChildNode(FOXTreeNode node) {
    if (node.getColumn() != null) {
        if (!//$NON-NLS-1$
        MessageDialog.openConfirm(//$NON-NLS-1$
        xmlViewer.getControl().getShell(), //$NON-NLS-1$
        Messages.getString("CreateElementAction.0"), //$NON-NLS-1$
        Messages.getString("CreateElementAction.1") + node.getLabel() + "\"?")) {
            //$NON-NLS-1$
            return false;
        }
        node.setColumn(null);
    }
    //$NON-NLS-1$
    String label = "";
    while (!StringUtil.validateLabelForXML(label)) {
        InputDialog dialog = new InputDialog(null, //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("CreateElementAction.4"), //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("CreateElementAction.5"), "", //$NON-NLS-1$
        null);
        int status = dialog.open();
        if (status == InputDialog.OK) {
            label = dialog.getValue().trim();
        }
        if (status == InputDialog.CANCEL) {
            return false;
        }
    }
    FOXTreeNode child = new Element(label);
    // add by wzhang. set the row name
    child.setRow(node.getRow());
    node.addChild(child);
    this.xmlViewer.refresh();
    this.xmlViewer.expandToLevel(node, 1);
    return true;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) InputDialog(org.eclipse.jface.dialogs.InputDialog) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 5 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 initModel.

public void initModel() {
    int i = 0;
    List<? extends IConnection> incomingConnections = NodeUtil.getIncomingConnections(foxComponent, IConnectionCategory.FLOW);
    for (IConnection connection : incomingConnections) {
        IMetadataTable metadataTable = connection.getMetadataTable();
        metadataTable.setLabel(connection.getUniqueName());
        treeData = new ArrayList<FOXTreeNode>();
        if (// the first schema as current
        i == 0)
            currentSchema = metadataTable.getLabel();
        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;
        //$NON-NLS-1$
        String schemaId = metadataTable.getLabel() + ":";
        // build root tree
        List<Map<String, String>> rootTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.ROOT);
        if (rootTable != null) {
            for (Map<String, String> rootMap : rootTable) {
                String newPath = rootMap.get(FileOutputXMLComponent.PATH);
                String columnName = rootMap.get(FileOutputXMLComponent.COLUMN);
                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();
                }
                //$NON-NLS-1$
                String flag = columnName + ":";
                if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
                    //$NON-NLS-1$
                    continue;
                }
                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 = 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);
                }
                temp.setRow(metadataTable.getLabel());
                if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
                    //$NON-NLS-1$
                    columnName = columnName.replace(schemaId, "");
                    temp.setColumn(metadataTable.getColumn(columnName));
                    temp.setTable(metadataTable);
                }
            }
        }
        // build group tree
        current = mainNode;
        currentPath = mainPath;
        boolean isFirst = true;
        List<Map<String, String>> groupTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.GROUP);
        if (groupTable != null) {
            for (Map<String, String> groupMap : groupTable) {
                String newPath = groupMap.get(FileOutputXMLComponent.PATH);
                String columnName = groupMap.get(FileOutputXMLComponent.COLUMN);
                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();
                }
                //$NON-NLS-1$
                String flag = columnName + ":";
                if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
                    //$NON-NLS-1$
                    continue;
                }
                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);
                }
                temp.setRow(metadataTable.getLabel());
                if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
                    //$NON-NLS-1$
                    columnName = columnName.replace(schemaId, "");
                    temp.setColumn(metadataTable.getColumn(columnName));
                    temp.setTable(metadataTable);
                }
            }
        }
        // build loop tree
        current = mainNode;
        currentPath = mainPath;
        isFirst = true;
        List<Map<String, String>> loopTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.LOOP);
        if (loopTable != null) {
            for (Map<String, String> loopMap : loopTable) {
                String newPath = loopMap.get(FileOutputXMLComponent.PATH);
                String columnName = loopMap.get(FileOutputXMLComponent.COLUMN);
                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();
                }
                //$NON-NLS-1$
                String flag = columnName + ":";
                if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
                    //$NON-NLS-1$
                    continue;
                }
                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 (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);
                }
                temp.setRow(metadataTable.getLabel());
                if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
                    //$NON-NLS-1$
                    columnName = columnName.replace(schemaId, "");
                    temp.setColumn(metadataTable.getColumn(columnName));
                    temp.setTable(metadataTable);
                }
            }
            if (rootNode == null) {
                //$NON-NLS-1$
                rootNode = new Element("rootTag");
            }
            rootNode.setParent(null);
            if (haveOrder) {
                orderNode(rootNode);
            }
            treeData.add(rootNode);
            rootNode.setRow(metadataTable.getLabel());
            contents.put(metadataTable.getLabel(), treeData);
            i++;
        }
    }
}
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) ArrayList(java.util.ArrayList) List(java.util.List) 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