Search in sources :

Example 16 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class ShadowNode method getMetadataList.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.process.INode#getMetaDataList()
     */
@Override
public List<IMetadataTable> getMetadataList() {
    List<IMetadataTable> metadataList = super.getMetadataList();
    if (metadataList != null) {
        return metadataList;
    }
    List<IMetadataTable> metadatas = new ArrayList<IMetadataTable>();
    MetadataTable metadata = new MetadataTable();
    metadata.setTableName(this.getUniqueName());
    List<IMetadataColumn> columns = new ArrayList<IMetadataColumn>();
    for (int i = 0; i < columnNumber; i++) {
        MetadataColumn col = new MetadataColumn();
        //$NON-NLS-1$
        col.setLabel("row" + i);
        //$NON-NLS-1$
        col.setTalendType("id_String");
        //$NON-NLS-1$
        col.setType("String");
        columns.add(col);
    }
    metadata.setListColumns(columns);
    metadatas.add(metadata);
    return metadatas;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 17 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class InsertNewColumnCommand method createInputMetadataColumn.

private void createInputMetadataColumn(String sourceTreeName, String targetTreeName, TreeNode sourceNode, String targetNodeName, int index) {
    String sourceNodeName = sourceNode.getName();
    IMetadataTable metadataTarget = null;
    List<IODataComponent> inputs = manager.getMapperComponent().getIODataComponents().getInputs();
    for (IODataComponent incoming : inputs) {
        if (targetTreeName != null && targetTreeName.equals(incoming.getConnection().getName())) {
            metadataTarget = incoming.getTable();
        }
    }
    if (metadataTarget != null) {
        IMetadataColumn columnSource = null;
        if (sourceTreeName != null) {
            columnSource = getSourceColumn(sourceTreeName, sourceNodeName);
        }
        creatMeatadataColumn(columnSource, targetNodeName, sourceNode, metadataTarget, index);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IODataComponent(org.talend.core.model.components.IODataComponent) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 18 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class InsertNewColumnCommand method createOutputMetadataColumn.

private void createOutputMetadataColumn(String sourceTreeName, String targetTreeName, AbstractNode sourceNode, String targetNodeName, int index) {
    String sourceNodeName = sourceNode.getName();
    IMetadataTable metadataTarget = null;
    List<IMetadataTable> metadataTargets = manager.getMapperComponent().getMetadataList();
    if (metadataTargets != null) {
        for (IMetadataTable target : metadataTargets) {
            if (target.getTableName().equals(targetTreeName)) {
                metadataTarget = target;
            }
        }
    }
    if (metadataTarget != null) {
        IMetadataColumn columnSource = null;
        if (sourceTreeName != null) {
            columnSource = getSourceColumn(sourceTreeName, sourceNodeName);
        }
        creatMeatadataColumn(columnSource, targetNodeName, sourceNode, metadataTarget, index);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 19 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class MapDataHelper method rebuildInputTree.

public void rebuildInputTree(InputXmlTree inputTree, IMetadataTable metadataTable, XmlMapData mapData) {
    if (metadataTable != null && metadataTable.getListColumns() != null) {
        List<IMetadataColumn> listColumns = metadataTable.getListColumns();
        EList<TreeNode> nodes = inputTree.getNodes();
        for (int i = 0; i < listColumns.size(); i++) {
            IMetadataColumn column = listColumns.get(i);
            TreeNode found = null;
            int j = 0;
            for (; j < nodes.size(); j++) {
                TreeNode node = nodes.get(j);
                if (node.getName() != null && node.getName().equals(column.getLabel())) {
                    found = node;
                    break;
                }
            }
            if (found != null) {
                // set in case talend type changed in metadata
                found.setType(column.getTalendType());
                if (i != j) {
                    // do switch to keep the same sequence
                    TreeNode temp = nodes.get(j);
                    nodes.remove(j);
                    nodes.add(i, temp);
                }
            } else {
                found = XmlmapFactory.eINSTANCE.createTreeNode();
                found.setName(column.getLabel());
                found.setType(column.getTalendType());
                found.setNullable(column.isNullable());
                found.setXpath(XmlMapUtil.getXPath(inputTree.getName(), found.getName(), found.getNodeType()));
                nodes.add(i, found);
            }
            // add a default root for document
            if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
                EList<TreeNode> children = found.getChildren();
                // if type is changed from a non-document to document
                if (children.isEmpty()) {
                    XmlMapUtil.detachNodeConnections(found, mapData, true);
                    TreeNode treeRoot = XmlmapFactory.eINSTANCE.createTreeNode();
                    treeRoot.setName("root");
                    treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                    treeRoot.setNodeType(NodeType.ELEMENT);
                    treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(), treeRoot.getName(), treeRoot.getNodeType()));
                    treeRoot.setLoop(true);
                    treeRoot.setMain(true);
                    children.add(treeRoot);
                }
            } else // remove children and connections for children if not document
            {
                EList<TreeNode> children = found.getChildren();
                if (!children.isEmpty()) {
                    XmlMapUtil.detachNodeConnections(found, mapData, true);
                    List<TreeNode> copyOfChildren = new ArrayList<TreeNode>(found.getChildren());
                    found.getChildren().clear();
                    if (!inputTree.isLookup() && inputTree.isMultiLoops()) {
                        List<TreeNode> oldLoops = new ArrayList<TreeNode>();
                        XmlMapUtil.getChildLoops(oldLoops, copyOfChildren);
                        inputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(inputTree));
                        XmlMapUtil.removeloopInOutputTree(mapData, inputTree, oldLoops);
                    }
                }
            }
        }
        if (nodes.size() > listColumns.size()) {
            List unUsed = new ArrayList();
            for (int i = listColumns.size(); i < nodes.size(); i++) {
                XmlMapUtil.detachNodeConnections(nodes.get(i), mapData, true);
                unUsed.add(nodes.get(i));
            }
            nodes.removeAll(unUsed);
        }
    }
    // be deleted
    if (inputTree.isLookup()) {
        rebuildInputNodesConnections(inputTree.getNodes(), mapData);
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 20 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class Connection method initTraceFilterParameters.

/**
     * just keep this method in case we need it again in some day, or we can delete it dirrectly, since it is never
     * used.
     */
private void initTraceFilterParameters() {
    List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
    IMetadataTable metadataTable = this.getMetadataTable();
    if (metadataTable != null) {
        for (IMetadataColumn metaColumn : metadataTable.getListColumns()) {
            Map<String, Object> line = new HashMap<String, Object>();
            line.put(IConnection.TRACE_SCHEMA_COLUMN, metaColumn.getLabel());
            line.put(IConnection.TRACE_SCHEMA_COLUMN_CHECKED, true);
            line.put(IConnection.TRACE_SCHEMA_COLUMN_CONDITION, null);
            values.add(line);
        }
    }
    if (getElementParameter(EParameterName.TRACES_CONNECTION_FILTER.getName()) != null && values != null) {
        getElementParameter(EParameterName.TRACES_CONNECTION_FILTER.getName()).setValue(values);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)149 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)82 ArrayList (java.util.ArrayList)73 List (java.util.List)34 IConnection (org.talend.core.model.process.IConnection)34 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)31 HashMap (java.util.HashMap)30 IElementParameter (org.talend.core.model.process.IElementParameter)26 Map (java.util.Map)24 INode (org.talend.core.model.process.INode)24 MetadataTable (org.talend.core.model.metadata.MetadataTable)23 Node (org.talend.designer.core.ui.editor.nodes.Node)16 Point (org.eclipse.swt.graphics.Point)15 Connection (org.talend.designer.core.ui.editor.connections.Connection)10 INodeConnector (org.talend.core.model.process.INodeConnector)9 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)9 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)9 MetadataTableEditor (org.talend.core.ui.metadata.editor.MetadataTableEditor)8 IComponent (org.talend.core.model.components.IComponent)7 IODataComponent (org.talend.core.model.components.IODataComponent)7