Search in sources :

Example 61 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 addElement.

protected FOXTreeNode addElement(FOXTreeNode current, String currentPath, String newPath, String defaultValue) {
    //$NON-NLS-1$
    String name = newPath.substring(newPath.lastIndexOf("/") + 1);
    //$NON-NLS-1$
    String parentPath = newPath.substring(0, newPath.lastIndexOf("/"));
    FOXTreeNode temp = new Element(name, defaultValue);
    if (current == null) {
        // root node
        return temp;
    }
    if (currentPath.equals(parentPath)) {
        current.addChild(temp);
    } else {
        //$NON-NLS-1$
        String[] nods = currentPath.split("/");
        //$NON-NLS-1$
        String[] newNods = parentPath.split("/");
        int parentLevel = 0;
        int checkLength = nods.length < newNods.length ? nods.length : newNods.length;
        for (int i = 1; i < checkLength; i++) {
            if (nods[i].equals(newNods[i])) {
                parentLevel = i;
            }
        }
        FOXTreeNode parent = current;
        for (int i = 0; i < nods.length - (parentLevel + 1); i++) {
            FOXTreeNode tmpParent = parent.getParent();
            if (tmpParent == null) {
                break;
            }
            parent = tmpParent;
        }
        if (parent != null)
            parent.addChild(temp);
    }
    return temp;
}
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 62 with FOXTreeNode

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

the class AbstractJSONFileStepForm method tableLoader.

protected void tableLoader(Element element, String parentPath, List<JSONFileNode> table, String defaultValue) {
    JSONFileNode JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
    String currentPath = parentPath + "/" + element.getLabel();
    JSONFileNode.setJSONPath(currentPath);
    JSONFileNode.setRelatedColumn(element.getColumnLabel());
    JSONFileNode.setAttribute(element.isMain() ? "main" : "branch");
    JSONFileNode.setDefaultValue(defaultValue);
    JSONFileNode.setType(element.getDataType());
    JSONFileNode.setOrder(getNodeOrder(element));
    table.add(JSONFileNode);
    for (FOXTreeNode att : element.getAttributeChildren()) {
        JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
        JSONFileNode.setJSONPath(att.getLabel());
        JSONFileNode.setRelatedColumn(att.getColumnLabel());
        JSONFileNode.setAttribute("attri");
        JSONFileNode.setDefaultValue(att.getDefaultValue());
        JSONFileNode.setType(att.getDataType());
        JSONFileNode.setOrder(getNodeOrder(att));
        table.add(JSONFileNode);
    }
    for (FOXTreeNode att : element.getNameSpaceChildren()) {
        JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
        JSONFileNode.setJSONPath(att.getLabel());
        JSONFileNode.setRelatedColumn(att.getColumnLabel());
        JSONFileNode.setAttribute("ns");
        JSONFileNode.setDefaultValue(att.getDefaultValue());
        JSONFileNode.setType(att.getDataType());
        JSONFileNode.setOrder(getNodeOrder(att));
        table.add(JSONFileNode);
    }
    List<FOXTreeNode> children = element.getElementChildren();
    for (FOXTreeNode child : children) {
        if (!child.isGroup() && !child.isLoop()) {
            tableLoader((Element) child, currentPath, table, child.getDefaultValue());
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) JSONFileNode(org.talend.repository.model.json.JSONFileNode)

Example 63 with FOXTreeNode

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

the class AbstractJSONFileStepForm method initMetadataTable.

protected void initMetadataTable(List<FOXTreeNode> list, EList columnList) {
    int maxColumnsNumber = CoreUIPlugin.getDefault().getPreferenceStore().getInt(ITalendCorePrefConstants.MAXIMUM_AMOUNT_OF_COLUMNS_FOR_XML);
    for (FOXTreeNode node : list) {
        if (columnList.size() > maxColumnsNumber) {
            return;
        }
        MetadataEmfTableEditor editor = new MetadataEmfTableEditor();
        if (node instanceof Element) {
            String label = node.getLabel();
            if (!node.hasChildren() && label != null && !label.equals("")) {
                String columnName = label;
                if (columnName.contains(":")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    columnName = columnName.split(":")[1];
                }
                columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
                String dataType = node.getDataType();
                MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
                metadataColumn.setOriginalField(label);
                metadataColumn.setTalendType(dataType);
                columnList.add(metadataColumn);
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
            }
        }
        if (node instanceof Attribute) {
            String label = node.getLabel();
            if (label != null && !label.equals("")) {
                String columnName = label;
                if (columnName.contains(":")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    columnName = columnName.split(":")[1];
                }
                columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
                String dataType = node.getDataType();
                MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
                metadataColumn.setOriginalField(label);
                metadataColumn.setTalendType(dataType);
                columnList.add(metadataColumn);
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
            }
        }
        if (node.hasChildren()) {
            List<FOXTreeNode> children = node.getChildren();
            initMetadataTable(children, columnList);
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 64 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 updateJSONTreeViewer.

private void updateJSONTreeViewer() {
    LinksManager<Item, Object, Tree, Object> linkManager = linker.getLinkManager();
    List<LinkDescriptor<Item, Object, Tree, Object>> links = linkManager.getLinks();
    for (int i = 0; i < links.size(); i++) {
        LinkDescriptor<Item, Object, Tree, Object> linkDescriptor = links.get(i);
        IExtremityLink<Item, Object> ex1 = linkDescriptor.getExtremity1();
        IExtremityLink<Tree, Object> ex2 = linkDescriptor.getExtremity2();
        MetadataColumn metaColumn = (MetadataColumn) ex1.getDataItem();
        FOXTreeNode node = (FOXTreeNode) ex2.getDataItem();
        if (ex1.getGraphicalObject() != null) {
            Item item = ex1.getGraphicalObject();
            if (!item.isDisposed() && metaColumn.equals(item.getData())) {
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metaColumn));
            } else {
                node.setColumn(null);
            }
        }
        node.setDataType(metaColumn.getTalendType());
    }
    JSONViewer.refresh();
    updateConnection();
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Item(org.eclipse.swt.widgets.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Tree(org.eclipse.swt.widgets.Tree) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor)

Example 65 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)

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