Search in sources :

Example 31 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 prepareEmfTree.

private void prepareEmfTree(List<FOXTreeNode> list, TreeNode parent, boolean ignoreMapped) {
    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 = 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);
            }
        }
        createTreeNode.setXpath(XmlMapUtil.getXPath(xPath, label, createTreeNode.getNodeType()));
        // tempXpath is current xpath remove schema node xpath like: row1:newColumn1
        String tempXpath = createTreeNode.getXpath().substring(schemaNode.getXpath().length() + 1);
        if (createTreeNode.isChoice() || createTreeNode.isSubstitution()) {
            if (!isMappedChoiceSubs(foxNode, xPath)) {
                continue;
            }
        } else if (!ignoreMapped && !isMappedChild(tempXpath)) {
            continue;
        }
        // get talend type from metadata table
        String dataType = null;
        if (targetAbsolutePath != null) {
            dataType = targetAbsolutePath.get(tempXpath);
        }
        if (dataType == null) {
            dataType = foxNode.getDataType();
        }
        if (dataType != null && !"".equals(dataType)) {
            if (dataType.equals("id_Date")) {
                String datePattern = targetDatePattern.get(tempXpath);
                if (datePattern == null || "".equals(datePattern)) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    datePattern = "\"dd-MM-yyyy\"";
                }
                createTreeNode.setPattern(datePattern);
            }
            createTreeNode.setType(dataType);
        } else {
            createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
        }
        if (tempXpath.equals(absoluteXPathQuery)) {
            createTreeNode.setLoop(true);
            createTreeNode.setOptional(foxNode.isOptional());
            loopNode = createTreeNode;
        }
        parent.getChildren().add(createTreeNode);
        if (createTreeNode.isLoop()) {
            XmlMapUtil.upsetMainNode(createTreeNode);
        }
        if (foxNode.getChildren() != null && !foxNode.getChildren().isEmpty()) {
            prepareEmfTree(foxNode.getChildren(), createTreeNode, ignoreMapped);
        }
    }
}
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) 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)

Example 32 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 prepareEmfTreeFromXml.

private void prepareEmfTreeFromXml(XmlFileConnection connection) throws Exception {
    if (!connection.isInputModel()) {
        prepareEmfTreeFromConnection(connection);
    // String file = connection.getXmlFilePath();
    // List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
    // // fix for TDI-20671 , root element is loop in output
    // String rootXpath = null;
    // if (!connection.getRoot().isEmpty()) {
    // rootXpath = connection.getRoot().get(0).getXMLPath();
    // } else if (!connection.getLoop().isEmpty()) {
    // rootXpath = connection.getLoop().get(0).getXMLPath();
    // }
    // File xmlFile = new File(file);
    // if (xmlFile.exists() && !file.endsWith(".zip")) {
    // list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), rootXpath, true);
    // } else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
    // String xsdFile = initFileContent(connection);
    // if (xsdFile != null && new File(xsdFile).exists()) {
    // String targetNameSpace = connection.getTargetNameSpace();
    // list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, rootXpath, targetNameSpace, true);
    // } else {
    // // for manually created output
    // prepareEmfTreeFromConnection(connection);
    // return;
    //
    // }
    // } else {
    // // for manually created output
    // prepareEmfTreeFromConnection(connection);
    // return;
    // }
    // schemaNode.getChildren().clear();
    // root = connection.getRoot();
    // loop = connection.getLoop();
    // group = connection.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);
    // }
    // }
    } else {
        List<SchemaTarget> schemaTargets = null;
        if (!connection.getSchema().isEmpty() && connection.getSchema().get(0) instanceof XmlXPathLoopDescriptorImpl) {
            absoluteXPathQuery = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getAbsoluteXPathQuery();
            schemaTargets = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getSchemaTargets();
            metadataTable = ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0];
        }
        // fix for TDI-8707 : only import mapped elements from connection to xml map
        if (schemaTargets == null || schemaTargets.isEmpty()) {
            return;
        }
        this.schemaTargets = schemaTargets;
        String file = connection.getXmlFilePath();
        List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
        File xmlFile = new File(file);
        if (xmlFile.exists()) {
            list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), absoluteXPathQuery, true);
        } else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
            String xsdFile = initFileContent(connection);
            if (xsdFile != null && new File(xsdFile).exists()) {
                list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, absoluteXPathQuery, true);
            }
        } else {
            throw new FileNotFoundException();
        }
        schemaNode.getChildren().clear();
        prepareEmfTree(list, schemaNode);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) XmlXPathLoopDescriptorImpl(org.talend.core.model.metadata.builder.connection.impl.XmlXPathLoopDescriptorImpl) SchemaTarget(org.talend.core.model.metadata.builder.connection.SchemaTarget) File(java.io.File)

Example 33 with FOXTreeNode

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

the class JSONFileSchema2TreeLinker method createLinks.

public void createLinks() {
    removeAllLinks();
    getBackgroundRefresher().refreshBackground();
    ProgressDialog progressDialog = new ProgressDialog(getSource().getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) {
            TreeItem root = jsonViewer.getTree().getItem(0);
            // if (getManager().getFoxComponent().istFileOutputMSXML()) {
            // List<FOXTreeNode> treeData = getManager().getTreeData(getManager().getCurrentSchema());
            // if (treeData != null && treeData.size() > 0) {
            // FOXTreeNode rootTreeData = treeData.get(0);
            // for (TreeItem item : xmlViewer.getTree().getItems()) {
            // if (rootTreeData == item.getData()) {
            // root = item;
            // break;
            // }
            // }
            // }
            // }
            List<TreeItem> allItems = TreeUtils.collectAllItems(root);
            monitorWrap = new EventLoopProgressMonitor(monitor);
            String taskName = "Loop links creation ...";
            int totalWork = allItems.size();
            //$NON-NLS-1$
            monitorWrap.beginTask(taskName, totalWork);
            for (int i = 0; i < totalWork; i++) {
                if (monitorWrap.isCanceled()) {
                    return;
                }
                TreeItem treeItem = allItems.get(i);
                FOXTreeNode node = (FOXTreeNode) treeItem.getData();
                if (node.getColumn() == null) {
                    //$NON-NLS-1$
                    continue;
                }
                createLoopLinks(node.getColumn().getLabel(), treeItem, monitorWrap, i == totalWork - 1);
                monitorWrap.worked(1);
            }
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeItem(org.eclipse.swt.widgets.TreeItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 34 with FOXTreeNode

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

the class JSONFileTreeViewerProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    FOXTreeNode treeNode = (FOXTreeNode) parentElement;
    List<FOXTreeNode> children = treeNode.getChildren();
    return children.toArray();
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)

Example 35 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.fileoutputJSON.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();
        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;
                }
            }
        }
    }
    if (parent == null) {
        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)

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