Search in sources :

Example 26 with FOXTreeNode

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

the class MoveDownTreeNodeButton method updateStatus.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.fileoutputxml.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
     */
@Override
protected void updateStatus(TreeSelection selection) {
    if (selection.isEmpty()) {
        getButton().setEnabled(false);
        return;
    }
    final TreePath[] paths = selection.getPaths();
    boolean sameSegment = true;
    for (int i = 0; i < paths.length - 1; i++) {
        if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
            sameSegment = false;
        }
    }
    if (sameSegment) {
        getButton().setEnabled(true);
    } else {
        getButton().setEnabled(false);
        return;
    }
    // if same segment ,they have the same parent and parent must be an element
    FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
    if (foxNode.getParent() instanceof Element) {
        final Element parent = (Element) foxNode.getParent();
        if (parent == null) {
            getButton().setEnabled(false);
            return;
        }
        final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
        final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
        final List<FOXTreeNode> elementChildren = parent.getElementChildren();
        final Iterator iterator = selection.iterator();
        while (iterator.hasNext()) {
            final Object next = iterator.next();
            if (next instanceof Attribute) {
                if (attrChildren.contains(next) && attrChildren.indexOf(next) == attrChildren.size() - 1) {
                    getButton().setEnabled(false);
                    return;
                }
            } else if (next instanceof NameSpaceNode) {
                if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == nameSpaceChildren.size() - 1) {
                    getButton().setEnabled(false);
                    return;
                }
            } else if (next instanceof Element) {
                if (elementChildren.contains(next) && elementChildren.indexOf(next) == elementChildren.size() - 1) {
                    getButton().setEnabled(false);
                    return;
                }
            }
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreePath(org.eclipse.jface.viewers.TreePath) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) Iterator(java.util.Iterator)

Example 27 with FOXTreeNode

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

the class MoveUpTreeNodeButton method updateStatus.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.fileoutputxml.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
     */
@Override
protected void updateStatus(TreeSelection selection) {
    if (selection.isEmpty()) {
        getButton().setEnabled(false);
        return;
    }
    final TreePath[] paths = selection.getPaths();
    boolean sameSegment = true;
    for (int i = 0; i < paths.length - 1; i++) {
        if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
            sameSegment = false;
        }
    }
    if (sameSegment) {
        getButton().setEnabled(true);
    } else {
        getButton().setEnabled(false);
        return;
    }
    // if same segment ,they have the same parent and parent must be an element
    final Element parent = (Element) ((FOXTreeNode) selection.getFirstElement()).getParent();
    if (parent == null) {
        getButton().setEnabled(false);
        return;
    }
    final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
    final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
    final List<FOXTreeNode> elementChildren = parent.getElementChildren();
    final Iterator iterator = selection.iterator();
    while (iterator.hasNext()) {
        final Object next = iterator.next();
        if (next instanceof Attribute) {
            if (attrChildren.contains(next) && attrChildren.indexOf(next) == 0) {
                getButton().setEnabled(false);
                return;
            }
        } else if (next instanceof NameSpaceNode) {
            if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == 0) {
                getButton().setEnabled(false);
                return;
            }
        } else if (next instanceof Element) {
            if (elementChildren.contains(next) && elementChildren.indexOf(next) == 0) {
                getButton().setEnabled(false);
                return;
            }
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreePath(org.eclipse.jface.viewers.TreePath) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) Iterator(java.util.Iterator)

Example 28 with FOXTreeNode

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

the class Schema2XMLLinker method getAbsoluteXPath.

public String getAbsoluteXPath(FOXTreeNode foxTreeNode) {
    FOXTreeNode item = foxTreeNode;
    String path = "";
    while (item != null) {
        path = "/" + item.getLabelForViewer() + path;
        item = item.getParent();
    }
    return path;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)

Example 29 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 isMappedChoiceSubs.

private boolean isMappedChoiceSubs(FOXTreeNode choiceSubs, String parentXpath) {
    // if any child of the choice or subs is mapped to target schema , it should be created in xmlmap
    for (FOXTreeNode child : choiceSubs.getChildren()) {
        NodeType nodeType = null;
        if (child instanceof Element) {
            nodeType = NodeType.ELEMENT;
        } else if (child instanceof Attribute) {
            nodeType = NodeType.ATTRIBUT;
        } else if (child instanceof NameSpaceNode) {
            nodeType = NodeType.NAME_SPACE;
        }
        String tempPath = XmlMapUtil.getXPath(parentXpath, child.getLabel(), nodeType);
        tempPath = tempPath.substring(schemaNode.getXpath().length() + 1);
        if (isMappedChild(tempPath)) {
            return true;
        }
    }
    return false;
}
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) NodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 30 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 prepareModelFromOutput.

private void prepareModelFromOutput(List<FOXTreeNode> foxTreeNodes, TreeNode parent) {
    TreeNode realParent = XmlMapUtil.getRealParentNode(parent);
    for (FOXTreeNode foxNode : foxTreeNodes) {
        TreeNode createTreeNode = createModel();
        createTreeNode.setOptional(foxNode.isOptional());
        String label = foxNode.getLabel();
        createTreeNode.setName(label);
        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);
            }
        }
        String xPath = XmlMapUtil.getXPath(realParent.getXpath(), label, createTreeNode.getNodeType());
        createTreeNode.setXpath(xPath);
        if (createTreeNode.isSubstitution() || createTreeNode.isChoice()) {
            if (isMappedChoiceSubsOutput(foxNode, realParent.getXpath())) {
                parent.getChildren().add(createTreeNode);
            }
        } else {
            String subXpath = xPath.substring(schemaNode.getXpath().length() + 1, xPath.length());
            XMLFileNode found = findXmlFileNode(subXpath, root);
            if (found == null) {
                found = findXmlFileNode(subXpath, group);
                if (found != null) {
                    groupElements.add(createTreeNode);
                }
            }
            if (found == null) {
                found = findXmlFileNode(subXpath, loop);
                if (found != null) {
                    if (loopNode == null) {
                        loopNode = createTreeNode;
                        loopNode.setLoop(true);
                        loopNode.setOptional(foxNode.isOptional());
                    }
                }
            }
            if (found == null) {
                continue;
            } else {
                String dataType = found.getType();
                if (dataType == null || dataType.equals("")) {
                    dataType = foxNode.getDataType();
                }
                if (dataType != null && !"".equals(dataType)) {
                    if (dataType.equals("id_Date")) {
                        //$NON-NLS-1$
                        createTreeNode.setPattern("\"dd-MM-yyyy\"");
                    }
                    createTreeNode.setType(dataType);
                } else {
                    createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                }
                addChildInOrder(parent, createTreeNode, found.getOrder());
            }
        }
        prepareModelFromOutput(foxNode.getChildren(), createTreeNode);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) 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