Search in sources :

Example 16 with IODataComponent

use of org.talend.core.model.components.IODataComponent in project tdi-studio-se by Talend.

the class WebServiceComponent method getIODataComponents.

@Override
public IODataComponentContainer getIODataComponents() {
    IODataComponentContainer inAndOut = new IODataComponentContainer();
    List<IODataComponent> outputs = inAndOut.getOuputs();
    for (IConnection currentConnection : getOutgoingConnections()) {
        if (currentConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            IODataComponent component = new IODataComponent(currentConnection, getMetadataList().get(1));
            outputs.add(component);
        }
    }
    List<IODataComponent> inputs = inAndOut.getInputs();
    for (IConnection currentConnection : getIncomingConnections()) {
        if (currentConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            IODataComponent component = new IODataComponent(currentConnection, inputMetadata);
            inputs.add(component);
        }
    }
    return inAndOut;
}
Also used : IConnection(org.talend.core.model.process.IConnection) IODataComponent(org.talend.core.model.components.IODataComponent) IODataComponentContainer(org.talend.core.model.components.IODataComponentContainer)

Example 17 with IODataComponent

use of org.talend.core.model.components.IODataComponent in project tdi-studio-se by Talend.

the class spssComponent method getIODataComponents.

@Override
public IODataComponentContainer getIODataComponents() {
    IODataComponentContainer inAndOut = new IODataComponentContainer();
    List<IODataComponent> outputs = inAndOut.getOuputs();
    if (null != getOutgoingConnections()) {
        for (IConnection currentConnection : getOutgoingConnections()) {
            IODataComponent component = new IODataComponent(currentConnection, getMetadataList().get(0));
            outputs.add(component);
        }
    }
    List<IODataComponent> inputs = inAndOut.getInputs();
    if (null != getIncomingConnections()) {
        for (IConnection currentConnection : getIncomingConnections()) {
            IODataComponent component = new IODataComponent(currentConnection, getMetadataList().get(0));
            inputs.add(component);
        }
    }
    return inAndOut;
}
Also used : IConnection(org.talend.core.model.process.IConnection) IODataComponent(org.talend.core.model.components.IODataComponent) IODataComponentContainer(org.talend.core.model.components.IODataComponentContainer)

Example 18 with IODataComponent

use of org.talend.core.model.components.IODataComponent in project tdi-studio-se by Talend.

the class MapperManager method selectInputXmlTree.

public void selectInputXmlTree(InputXmlTree inputTree) {
    if (inputTree != selectedInputTree) {
        selectedInputTree = inputTree;
        MetadataTableEditorView inputMetaEditorView = mapperUI.getTabFolderEditors().getInputMetaEditorView();
        List<IODataComponent> inputs = getMapperComponent().getIODataComponents().getInputs();
        IMetadataTable table = null;
        for (int i = 0; i < inputs.size(); i++) {
            IODataComponent ioDataComponent = inputs.get(i);
            if (inputTree.getName() != null && inputTree.getName().equals(ioDataComponent.getConnection().getName())) {
                table = ioDataComponent.getTable();
                break;
            }
        }
        if (table != null) {
            MetadataTableEditor editor = new MetadataTableEditor(table, selectedInputTree.getName());
            editor.setModifiedBeanListenable(inputMetaEditorView.getTableViewerCreator());
            IModifiedBeanListener<IMetadataColumn> columnListener = new IModifiedBeanListener<IMetadataColumn>() {

                @Override
                public void handleEvent(ModifiedBeanEvent<IMetadataColumn> event) {
                    fireCurrentDirectEditApply();
                    if (AbstractMetadataTableEditorView.ID_COLUMN_NAME.equals(event.column.getId())) {
                        if (event.index < selectedInputTree.getNodes().size()) {
                            TreeNode treeNode = selectedInputTree.getNodes().get(event.index);
                            if (treeNode != null) {
                                treeNode.setName((String) event.newValue);
                                processColumnNameChanged(treeNode);
                            }
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_TYPE.equals(event.column.getId())) {
                        if (event.index < selectedInputTree.getNodes().size()) {
                            TreeNode treeNode = selectedInputTree.getNodes().get(event.index);
                            if (treeNode != null) {
                                if (treeNode.getType() != null && treeNode.getType().equals(XmlMapUtil.DOCUMENT)) {
                                    List<TreeNode> oldLoops = new ArrayList<TreeNode>();
                                    if (selectedInputTree == mainInputTree && mainInputTree.isMultiLoops()) {
                                        oldLoops = XmlMapUtil.getMultiLoopsForXmlTree(selectedInputTree);
                                    }
                                    XmlMapUtil.detachNodeConnections(treeNode, getExternalData(), true);
                                    treeNode.getChildren().clear();
                                    if (selectedInputTree == mainInputTree && mainInputTree.isMultiLoops()) {
                                        selectedInputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(selectedInputTree));
                                        List<TreeNode> newLoops = XmlMapUtil.getMultiLoopsForXmlTree(selectedInputTree);
                                        oldLoops.removeAll(newLoops);
                                        if (!oldLoops.isEmpty()) {
                                            XmlMapUtil.removeloopInOutputTree(MapperManager.this, oldLoops);
                                        }
                                    }
                                }
                                treeNode.setType((String) event.newValue);
                                if (XmlMapUtil.DOCUMENT.equals(event.newValue)) {
                                    XmlMapUtil.detachNodeConnections(treeNode, getExternalData(), true);
                                    TreeNode createTreeNode = XmlmapFactory.eINSTANCE.createTreeNode();
                                    createTreeNode.setName("root");
                                    createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                                    createTreeNode.setNodeType(NodeType.ELEMENT);
                                    createTreeNode.setXpath(XmlMapUtil.getXPath(treeNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                    createTreeNode.setLoop(true);
                                    createTreeNode.setMain(true);
                                    treeNode.getChildren().add(createTreeNode);
                                }
                                problemsAnalyser.checkProblems(selectedInputTree);
                                mapperUI.updateStatusBar();
                                inputTreeSchemaBeanListModified();
                            }
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_KEY.equals(event.column.getId())) {
                        if (event.index < selectedInputTree.getNodes().size()) {
                            TreeNode treeNode = selectedInputTree.getNodes().get(event.index);
                            treeNode.setKey((Boolean) event.newValue);
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_PATTERN.equals(event.column.getId())) {
                        if (event.index < selectedInputTree.getNodes().size()) {
                            TreeNode treeNode = selectedInputTree.getNodes().get(event.index);
                            treeNode.setPattern((String) event.newValue);
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_NULLABLE.equals(event.column.getId())) {
                        if (event.index < selectedInputTree.getNodes().size()) {
                            TreeNode treeNode = selectedInputTree.getNodes().get(event.index);
                            treeNode.setNullable((Boolean) event.newValue);
                        }
                    }
                }
            };
            editor.addModifiedBeanListener(columnListener);
            editor.addAfterOperationListListener(new IListenableListListener() {

                @Override
                public void handleEvent(ListenableListEvent event) {
                    if (event.type == TYPE.ADDED) {
                        EList<TreeNode> nodes = selectedInputTree.getNodes();
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.addedObjects;
                        if (event.index != null) {
                            int index = event.index;
                            for (IMetadataColumn column : metadataColumns) {
                                TreeNode createTreeNode = XmlmapFactory.eINSTANCE.createTreeNode();
                                createTreeNode.setName(column.getLabel());
                                createTreeNode.setType(column.getTalendType());
                                createTreeNode.setNullable(column.isNullable());
                                createTreeNode.setPattern(column.getPattern());
                                createTreeNode.setXpath(XmlMapUtil.getXPath(selectedInputTree.getName(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                selectedInputTree.getNodes().add(index, createTreeNode);
                                index = index + 1;
                            }
                        }
                    } else if (event.type == TYPE.REMOVED) {
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.removedObjects;
                        List treeNodeToRemove = new ArrayList();
                        for (IMetadataColumn column : metadataColumns) {
                            for (TreeNode node : selectedInputTree.getNodes()) {
                                if (node.getName() != null && node.getName().equals(column.getLabel())) {
                                    XmlMapUtil.detachNodeConnections(node, getExternalData(), true);
                                    treeNodeToRemove.add(node);
                                }
                            }
                        }
                        selectedInputTree.getNodes().removeAll(treeNodeToRemove);
                        if (selectedInputTree == mainInputTree && mainInputTree.isMultiLoops()) {
                            selectedInputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(selectedInputTree));
                            List<TreeNode> oldLoops = new ArrayList<TreeNode>();
                            XmlMapUtil.getChildLoops(oldLoops, treeNodeToRemove);
                            if (!oldLoops.isEmpty()) {
                                XmlMapUtil.removeloopInOutputTree(MapperManager.this, oldLoops);
                            }
                        }
                        problemsAnalyser.checkProblems(selectedInputTree);
                        mapperUI.updateStatusBar();
                        inputTreeSchemaBeanListModified();
                    } else if (event.type == TYPE.SWAPED) {
                        List<Integer> listIndexTarget = event.indicesTarget;
                        List<Integer> listIndexOrignal = event.indicesOrigin;
                        for (int i = 0; i < listIndexOrignal.size(); i++) {
                            int orignal = listIndexOrignal.get(i);
                            int target = listIndexTarget.get(i);
                            if (orignal < selectedInputTree.getNodes().size()) {
                                TreeNode tempTreeNode = selectedInputTree.getNodes().get(orignal);
                                selectedInputTree.getNodes().remove(orignal);
                                selectedInputTree.getNodes().add(target, tempTreeNode);
                            }
                        }
                    } else if (event.type == TYPE.REPLACED) {
                        // fix for TDI-24071
                        List added = (List) event.addedObjects;
                        List removed = (List) event.removedObjects;
                        boolean needCheckOutput = false;
                        List<TreeNode> oldLoops = new ArrayList<TreeNode>();
                        if (selectedInputTree == mainInputTree && mainInputTree.isMultiLoops()) {
                            needCheckOutput = true;
                        }
                        List<IMetadataColumn> removedColumn = new ArrayList<IMetadataColumn>();
                        List<IMetadataColumn> addedColumn = new ArrayList<IMetadataColumn>();
                        if (!added.isEmpty()) {
                            addedColumn.addAll((List<IMetadataColumn>) added.get(0));
                        }
                        if (!removed.isEmpty()) {
                            removedColumn.addAll((List<IMetadataColumn>) removed.get(0));
                        }
                        Map<IMetadataColumn, TreeNode> nodeMap = new HashMap<IMetadataColumn, TreeNode>();
                        for (int i = 0; i < removedColumn.size(); i++) {
                            IMetadataColumn column = removedColumn.get(i);
                            TreeNode node = selectedInputTree.getNodes().get(i);
                            boolean found = false;
                            for (IMetadataColumn columnAdded : addedColumn) {
                                if (column.sameMetacolumnAs(columnAdded)) {
                                    nodeMap.put(columnAdded, node);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                XmlMapUtil.detachNodeConnections(node, getExternalData(), true);
                                // get old loops if doc column need to be delete
                                if (needCheckOutput) {
                                    XmlMapUtil.getChildLoops(oldLoops, node.getChildren());
                                }
                            }
                        }
                        // remove all
                        selectedInputTree.getNodes().clear();
                        // add all
                        for (IMetadataColumn column : addedColumn) {
                            TreeNode treeNode = nodeMap.get(column);
                            if (treeNode == null) {
                                treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
                                treeNode.setName(column.getLabel());
                                treeNode.setType(column.getTalendType());
                                treeNode.setNullable(column.isNullable());
                                treeNode.setPattern(column.getPattern());
                                treeNode.setXpath(XmlMapUtil.getXPath(selectedInputTree.getName(), treeNode.getName(), treeNode.getNodeType()));
                                if (XmlMapUtil.DOCUMENT.equals(column.getTalendType())) {
                                    TreeNode createTreeNode = XmlmapFactory.eINSTANCE.createTreeNode();
                                    createTreeNode.setName("root");
                                    createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                                    createTreeNode.setNodeType(NodeType.ELEMENT);
                                    createTreeNode.setXpath(XmlMapUtil.getXPath(treeNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                    createTreeNode.setLoop(true);
                                    createTreeNode.setMain(true);
                                    treeNode.getChildren().add(createTreeNode);
                                }
                            }
                            selectedInputTree.getNodes().add(treeNode);
                        }
                        // for multi loops ,incase the doc node with multi loop is deleted
                        selectedInputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(selectedInputTree));
                        if (!oldLoops.isEmpty()) {
                            XmlMapUtil.removeloopInOutputTree(MapperManager.this, oldLoops);
                        }
                        mapperUI.updateStatusBar();
                    }
                }
            });
            inputMetaEditorView.setMetadataTableEditor(editor);
        }
        refreshTreeSchemaEditor(inputTree);
    }
}
Also used : ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IModifiedBeanListener(org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ModifiedBeanEvent(org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent) EList(org.eclipse.emf.common.util.EList) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IODataComponent(org.talend.core.model.components.IODataComponent) MetadataTableEditorView(org.talend.core.ui.metadata.editor.MetadataTableEditorView) AbstractMetadataTableEditorView(org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView)

Example 19 with IODataComponent

use of org.talend.core.model.components.IODataComponent in project tdi-studio-se by Talend.

the class MapperUI method prepareClosing.

public void prepareClosing(int response) {
    List<IMetadataTable> newMetadatas = new ArrayList<IMetadataTable>();
    EList<OutputXmlTree> outputTrees = null;
    if (response == SWT.OK || response == SWT.APPLICATION_MODAL) {
        // fix for bug TDI-18185
        mapperManager.fireCurrentDirectEditApply();
        // if press ok or apply , use copyOfMapData to check the metadata list
        outputTrees = copyOfMapData.getOutputTrees();
    } else {
        // if press cancel , use the original mapData
        outputTrees = ((XmlMapData) mapperComponent.getExternalEmfData()).getOutputTrees();
    }
    List<IMetadataTable> copyOfMetadata = new ArrayList<IMetadataTable>(mapperComponent.getMetadataList());
    for (OutputXmlTree outputTree : outputTrees) {
        IMetadataTable found = null;
        for (IMetadataTable table : mapperComponent.getMetadataList()) {
            if (outputTree.getName().equals(table.getTableName())) {
                found = table;
            }
        }
        if (found != null) {
            newMetadatas.add(found);
        } else {
            // create a new metadata if needed
            MetadataTable metadataTable = new MetadataTable();
            metadataTable.setTableName(outputTree.getName());
            mapperComponent.getProcess().addUniqueConnectionName(outputTree.getName());
            List<IMetadataColumn> listColumns = new ArrayList<IMetadataColumn>();
            for (OutputTreeNode treeNode : outputTree.getNodes()) {
                MetadataColumn column = new MetadataColumn();
                column.setLabel(treeNode.getName());
                column.setKey(treeNode.isKey());
                column.setTalendType(treeNode.getType());
                column.setNullable(treeNode.isNullable());
                column.setPattern(treeNode.getPattern());
                listColumns.add(column);
            }
            metadataTable.setListColumns(listColumns);
            newMetadatas.add(metadataTable);
        }
    }
    mapperComponent.setMetadataList(newMetadatas);
    copyOfMetadata.removeAll(newMetadatas);
    List<IODataComponent> outputs = mapperComponent.getIODataComponents().getOuputs();
    List<String> connectionNames = new ArrayList<String>();
    for (IODataComponent output : outputs) {
        connectionNames.add(output.getUniqueName());
    }
    for (IMetadataTable leftTree : copyOfMetadata) {
        if (!connectionNames.contains(leftTree.getTableName())) {
            mapperComponent.getProcess().removeUniqueConnectionName(leftTree.getTableName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IODataComponent(org.talend.core.model.components.IODataComponent)

Example 20 with IODataComponent

use of org.talend.core.model.components.IODataComponent in project tdi-studio-se by Talend.

the class InsertNewColumnCommand method getSourceColumn.

private IMetadataColumn getSourceColumn(String sourceTreeName, String sourceNodeName) {
    List<IODataComponent> inputs = manager.getMapperComponent().getIODataComponents().getInputs();
    IMetadataColumn columnSource = null;
    for (IODataComponent incoming : inputs) {
        if (sourceTreeName != null && sourceTreeName.equals(incoming.getConnection().getName())) {
            IMetadataTable metadataSource = incoming.getTable();
            for (IMetadataColumn column : metadataSource.getListColumns()) {
                if (column.getLabel().equals(sourceNodeName)) {
                    columnSource = column;
                    break;
                }
            }
            break;
        }
    }
    return columnSource;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IODataComponent(org.talend.core.model.components.IODataComponent) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Aggregations

IODataComponent (org.talend.core.model.components.IODataComponent)20 IConnection (org.talend.core.model.process.IConnection)11 ArrayList (java.util.ArrayList)10 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)10 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)7 List (java.util.List)6 IODataComponentContainer (org.talend.core.model.components.IODataComponentContainer)6 INode (org.talend.core.model.process.INode)5 Connection (org.talend.designer.core.ui.editor.connections.Connection)5 Node (org.talend.designer.core.ui.editor.nodes.Node)4 IExternalNode (org.talend.core.model.process.IExternalNode)3 INodeConnector (org.talend.core.model.process.INodeConnector)3 HashMap (java.util.HashMap)2 ColumnNameChanged (org.talend.core.model.metadata.ColumnNameChanged)2 Process (org.talend.designer.core.ui.editor.process.Process)2 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)2 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 EList (org.eclipse.emf.common.util.EList)1