Search in sources :

Example 1 with NameSpaceNode

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

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

the class CreateElementAction method selectionChanged.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
     */
@Override
public void selectionChanged(IStructuredSelection selection) {
    FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
    if (node == null) {
        this.setEnabled(false);
        return;
    }
    if (node instanceof Attribute) {
        this.setEnabled(false);
        return;
    }
    if (node instanceof NameSpaceNode) {
        this.setEnabled(false);
        return;
    }
    // let user can add more children to a root.
    // Element e = (Element) node;
    // if (e.getParent() == null) {
    // if (e.getElementChildren().size() >= 1) {
    // this.setEnabled(false);
    // return;
    // }
    // }
    this.setEnabled(true);
}
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)

Example 3 with NameSpaceNode

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

Example 4 with NameSpaceNode

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

the class SetGroupAction method selectionChanged.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
     */
@Override
public void selectionChanged(IStructuredSelection selection) {
    FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
    if (node == null) {
        this.setEnabled(false);
        return;
    }
    if (((node instanceof Attribute) || node.hasLink()) && this.value) {
        this.setEnabled(TreeUtil.checkTreeGoupNode(node));
        return;
    }
    if (node instanceof NameSpaceNode) {
        this.setEnabled(false);
        return;
    }
    this.setEnabled(TreeUtil.checkTreeGoupNode(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)

Example 5 with NameSpaceNode

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

the class RemoveGroupAction method selectionChanged.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
     */
@Override
public void selectionChanged(IStructuredSelection selection) {
    FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
    if (node == null) {
        this.setEnabled(false);
        return;
    }
    if (node instanceof Attribute) {
        this.setEnabled(false);
        return;
    }
    if (node instanceof NameSpaceNode) {
        this.setEnabled(false);
        return;
    }
    this.setEnabled(node.isGroup());
}
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)

Aggregations

FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)28 NameSpaceNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode)28 Attribute (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute)26 Element (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)17 Iterator (java.util.Iterator)8 ArrayList (java.util.ArrayList)7 TreePath (org.eclipse.jface.viewers.TreePath)4 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)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 NameSpaceDialog (org.talend.metadata.managment.ui.wizard.metadata.xml.dialog.NameSpaceDialog)2 EList (org.eclipse.emf.common.util.EList)1 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 ATreeNode (org.talend.datatools.xml.utils.ATreeNode)1 NodeType (org.talend.designer.xmlmap.model.emf.xmlmap.NodeType)1 JSONFileNode (org.talend.repository.model.json.JSONFileNode)1