Search in sources :

Example 31 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ConnectionDeleteCommand method undo.

@Override
public void undo() {
    Process process = (Process) connectionList.get(0).getSource().getProcess();
    for (Connection connection : connectionList) {
        collpseJoblet(connection);
        ConnectionDeletedInfo deletedInfo = connectionDeletedInfosMap.get(connection);
        if (deletedInfo != null) {
            INode source = connection.getSource();
            if (source != null && deletedInfo.metadataTable != null) {
                List<IMetadataTable> metaList = source.getMetadataList();
                if (!metaList.contains(deletedInfo.metadataTable)) {
                    metaList.add(deletedInfo.metadataTableIndex, deletedInfo.metadataTable);
                }
            }
        }
        connection.reconnect();
        INode target = connection.getTarget();
        if (target.getExternalNode() instanceof AbstractNode) {
            ((AbstractNode) target.getExternalNode()).addInput(connection);
        }
        INodeConnector nodeConnectorSource, nodeConnectorTarget;
        nodeConnectorSource = connection.getSourceNodeConnector();
        if (nodeConnectorSource != null) {
            nodeConnectorSource.setCurLinkNbOutput(nodeConnectorSource.getCurLinkNbOutput() + 1);
        }
        nodeConnectorTarget = connection.getTargetNodeConnector();
        if (nodeConnectorTarget != null) {
            nodeConnectorTarget.setCurLinkNbInput(nodeConnectorTarget.getCurLinkNbInput() + 1);
        }
    }
    process.checkStartNodes();
    process.checkProcess();
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INode(org.talend.core.model.process.INode) AbstractNode(org.talend.core.model.process.AbstractNode) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 32 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ExternalNodeChangeCommand method undo.

@Override
public void undo() {
    for (Connection connection : (List<Connection>) node.getIncomingConnections()) {
        if (connection.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connection.getLineStyle().equals(EConnectionType.FLOW_REF) || connection.getLineStyle().equals(EConnectionType.TABLE) || connection.getLineStyle().equals(EConnectionType.TABLE_REF)) {
            IODataComponent currentIO = inAndOut.getDataComponent(connection);
            if (currentIO.hasChanged()) {
                // IMetadataTable metadata = inAndOut.getTable(connection);
                INode sourceNode = currentIO.getSource();
                sourceNode.metadataOutputChanged(currentIO, currentIO.getName());
                // IMetadataTable oldMetadata = connection.getMetadataTable().clone();
                // currentIO.setTable(oldMetadata);
                // connection.getMetadataTable().setListColumns(metadata.getListColumns());
                IMetadataTable oldMetadata = currentIO.getConnMetadataTable();
                // currentIO.setTable(oldMetadata);
                connection.getMetadataTable().setListColumns(oldMetadata.getListColumns());
                if (metadataInputWasRepository.get(connection) != null) {
                    connection.getSource().setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.REPOSITORY);
                }
            }
        }
    }
    metadataInputWasRepository.clear();
    node.setExternalData(oldExternalData);
    node.setMetadataList(oldMetaDataList);
    for (Connection connection : connectionsToDelete.keySet()) {
        connection.reconnect();
        Node prevNode = (Node) connection.getSource();
        INodeConnector nodeConnectorSource, nodeConnectorTarget;
        nodeConnectorSource = prevNode.getConnectorFromType(connection.getLineStyle());
        nodeConnectorSource.setCurLinkNbOutput(nodeConnectorSource.getCurLinkNbOutput() + 1);
        Node nextNode = (Node) connection.getTarget();
        nodeConnectorTarget = nextNode.getConnectorFromType(connection.getLineStyle());
        nodeConnectorTarget.setCurLinkNbInput(nodeConnectorTarget.getCurLinkNbInput() + 1);
        if (connectionsToDelete.get(connection) != null) {
            inAndOut.getOuputs().add(connectionsToDelete.get(connection));
        }
    }
    for (ChangeMetadataCommand cmd : metadataOutputChanges) {
        cmd.undo();
    }
    ((Process) node.getProcess()).checkProcess();
    if (!isMetaLanguage) {
        refreshCodeView();
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) List(java.util.List) Process(org.talend.designer.core.ui.editor.process.Process) IODataComponent(org.talend.core.model.components.IODataComponent) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 33 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ExternalNodeChangeCommand method propagateInput.

private void propagateInput() {
    for (Connection connection : (List<Connection>) node.getIncomingConnections()) {
        if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            IODataComponent currentIO = inAndOut.getDataComponent(connection);
            currentIO.setColumnOption(IMetadataColumn.OPTIONS_NONE);
            if (currentIO.hasChanged()) {
                IMetadataTable metadata = inAndOut.getTable(connection);
                INode sourceNode = currentIO.getSource();
                sourceNode.metadataOutputChanged(currentIO, currentIO.getName());
                // It's better to clone, because will change that, if apply, bug 13325
                // IMetadataTable oldMetadata = connection.getMetadataTable().clone();
                IMetadataTable newMetadata = metadata.clone();
                currentIO.setTable(newMetadata);
                String schemaType = (String) connection.getSource().getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
                if (schemaType != null) {
                    // if there is a SCHEMA_TYPE, then switch it to BUILT_IN if REPOSITORY is set.
                    if (schemaType.equals(EmfComponent.REPOSITORY)) {
                        connection.getSource().setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                        metadataInputWasRepository.put(connection, Boolean.TRUE);
                    }
                }
                // for bug 9849
                List<IMetadataColumn> listColumns = connection.getMetadataTable().getListColumns();
                // before is empty
                boolean empty = listColumns.isEmpty();
                List<IMetadataColumn> newListColumns = newMetadata.getListColumns();
                List<ColumnNameChanged> columnNameChangeds = new ArrayList<ColumnNameChanged>();
                int size = listColumns.size();
                int newSize = newListColumns.size();
                if (newSize < size) {
                    size = newSize;
                }
                for (int i = 0; i < size; i++) {
                    IMetadataColumn metadataColumn = listColumns.get(i);
                    IMetadataColumn newMetadataColumn = newListColumns.get(i);
                    if (metadataColumn != null && newMetadataColumn != null) {
                        String oldId = metadataColumn.getId();
                        String oldLabel = metadataColumn.getLabel();
                        String newLabel = newMetadataColumn.getLabel();
                        String newId = newMetadataColumn.getId();
                        if (oldId != null && oldLabel != null && newId != null && oldId.equals(newId) && !oldLabel.equals(newLabel)) {
                            columnNameChangeds.add(new ColumnNameChanged(oldLabel, newLabel));
                        }
                    }
                }
                connection.getMetadataTable().setListColumns(newListColumns);
                // some pig component have FLOW_MAIN && PIGCOMBINE two connector type
                if (connection.getConnectorName() != null && connection.getConnectorName().equals("PIGCOMBINE")) {
                    IMetadataTable table = sourceNode.getMetadataFromConnector(EConnectionType.FLOW_MAIN.getName());
                    if (table != null) {
                        table.setListColumns(newListColumns);
                    }
                }
                ColumnListController.updateColumnList(sourceNode, columnNameChangeds, false);
                if (empty) {
                    // trace init
                    connection.initTraceParamters();
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ArrayList(java.util.ArrayList) List(java.util.List) IODataComponent(org.talend.core.model.components.IODataComponent)

Example 34 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ExternalNodeChangeCommand method init.

private void init() {
    connectionsToDelete = new HashMap<Connection, IODataComponent>();
    for (IODataComponent dataComponent : inAndOut.getOuputs()) {
        IConnection connection = dataComponent.getConnection();
        boolean metadataExists = false;
        for (IMetadataTable metadata : newMetaDataList) {
            if (connection.getMetadataTable().getTableName().equals(metadata.getTableName())) {
                metadataExists = true;
            }
        }
        if (!metadataExists && (connection instanceof Connection)) {
            connectionsToDelete.put((Connection) connection, dataComponent);
        }
    }
    for (Connection connection : (List<Connection>) node.getIncomingConnections()) {
        String schemaType = (String) connection.getSource().getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
        if (schemaType != null) {
            if (schemaType.equals(EmfComponent.REPOSITORY)) {
                String metaRepositoryName = (String) connection.getSource().getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
                IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(metaRepositoryName);
                if (repositoryMetadata == null) {
                    connection.getSource().setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                } else {
                    repositoryMetadata = repositoryMetadata.clone();
                    repositoryMetadata.setTableName(connection.getSource().getUniqueName());
                    ((org.talend.core.model.metadata.MetadataTable) repositoryMetadata).setRepository(true);
                    if (!repositoryMetadata.sameMetadataAs(connection.getMetadataTable(), IMetadataColumn.OPTIONS_IGNORE_USED)) {
                        connection.getSource().setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                    }
                }
            }
        }
    }
    //$NON-NLS-1$
    setLabel(Messages.getString("ExternalNodeChangeCommand.modifaicationFrom") + node.getUniqueName());
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IConnection(org.talend.core.model.process.IConnection) ArrayList(java.util.ArrayList) List(java.util.List) IODataComponent(org.talend.core.model.components.IODataComponent)

Example 35 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ExternalNodeChangeCommand method execute.

@Override
public void execute() {
    propagateInput();
    // bug 0020749
    if (!oldMetaDataList.isEmpty() && !newMetaDataList.isEmpty() && !oldMetaDataList.get(0).sameMetadataAs(newMetaDataList.get(0))) {
        node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
    }
    metadataOutputChanges.clear();
    List<IConnection> initTraceList = new ArrayList<IConnection>();
    for (IConnection connection : node.getOutgoingConnections()) {
        if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            IODataComponent dataComponent = inAndOut.getDataComponent(connection);
            boolean sameMetadataAs = connection.getMetadataTable().sameMetadataAs(dataComponent.getTable());
            IMetadataTable tempTable = null;
            boolean isSchemaAutoPropagated = true;
            if (connection.getTarget().getComponent() instanceof EmfComponent) {
                EmfComponent component = (EmfComponent) connection.getTarget().getComponent();
                isSchemaAutoPropagated = component.isSchemaAutoPropagated();
            }
            if (sameMetadataAs || !isSchemaAutoPropagated) {
                for (IMetadataTable itable : newMetaDataList) {
                    if (connection.getMetadataTable().getTableName().equals(itable.getTableName())) {
                        sameMetadataAs = connection.getMetadataTable().sameMetadataAs(itable);
                        tempTable = itable;
                        break;
                    }
                }
            } else {
                IMetadataTable table = connection.getMetadataTable();
                if (table == null || table.getListColumns().isEmpty()) {
                    initTraceList.add(connection);
                }
                INode connTar = connection.getTarget();
                boolean isAllowedPropagated = connTar.getComponent().isAllowedPropagated();
                boolean openDialog = false;
                Map<String, Boolean> jobletMap = new HashMap<String, Boolean>();
                if (isForTemlate()) {
                    openDialog = true;
                } else if (!isAllowedPropagated) {
                    openDialog = false;
                } else {
                    openDialog = getPropagate(connection, jobletMap);
                }
                if (openDialog) {
                    IElementParameter schemaParam = null;
                    if (connection != null) {
                        IMetadataTable connTable = connection.getMetadataTable();
                        IMetadataTable dataTable = dataComponent.getTable();
                        if (tempTable != null) {
                            dataTable = tempTable;
                        }
                        for (IElementParameter param : ((Node) connection.getTarget()).getElementParameters()) {
                            if (EParameterFieldType.SCHEMA_TYPE.equals(param.getFieldType()) || EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                                INodeConnector connector = connection.getTarget().getConnectorFromName(connection.getConnectorName());
                                if (connector != null && param.getContext().equals(connector.getBaseSchema())) {
                                    schemaParam = param;
                                    break;
                                }
                            }
                        }
                        if (schemaParam != null) {
                            ChangeMetadataCommand cmd = new ChangeMetadataCommand(connection.getTarget(), schemaParam, connTable, dataTable);
                            cmd.execute(true);
                            metadataOutputChanges.add(cmd);
                        }
                        for (IElementParameter param : ((Node) connection.getSource()).getElementParameters()) {
                            if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) && param.getContext().equals(connection.getSource().getConnectorFromName(connection.getConnectorName()).getBaseSchema())) {
                                schemaParam = param;
                                break;
                            }
                        }
                        if (schemaParam != null) {
                            ChangeMetadataCommand cmd = new ChangeMetadataCommand(connection.getSource(), schemaParam, connTable, dataTable);
                            cmd.execute(true);
                            metadataOutputChanges.add(cmd);
                        }
                        if (((Node) connTar).isJoblet()) {
                            IElementParameter param = connTar.getElementParameter(connection.getTarget().getUniqueName());
                            if (param != null) {
                                IMetadataTable originaleOutputTable = connTar.getMetadataFromConnector(param.getContext());
                                if (originaleOutputTable != null) {
                                    MetadataToolHelper.copyTable(dataTable, originaleOutputTable);
                                }
                            }
                        } else if (((Node) connTar).getJobletNode() != null) {
                            IElementParameter param = ((Node) connTar).getJobletNode().getElementParameter(connection.getTarget().getUniqueName());
                            if (param != null) {
                                IMetadataTable originaleOutputTable = ((Node) connTar).getJobletNode().getMetadataFromConnector(param.getContext());
                                if (originaleOutputTable != null) {
                                    MetadataToolHelper.copyTable(dataTable, originaleOutputTable);
                                }
                            }
                        }
                    }
                    if (((Node) connTar).isJoblet()) {
                        changeCollapsedState(true, jobletMap, connTar);
                    }
                } else {
                    // no matter propagate or not the metadata change will be propagate to xmlmap emf data
                    final Node target = (Node) connection.getTarget();
                    if (target != null && target.getExternalNode() != null) {
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IXmlMapService.class)) {
                            final IXmlMapService service = (IXmlMapService) GlobalServiceRegister.getDefault().getService(IXmlMapService.class);
                            if (service.isXmlMapComponent(target.getExternalNode())) {
                                IODataComponent output = new IODataComponent(connection, dataComponent.getTable());
                                target.metadataInputChanged(output, connection.getUniqueName());
                            }
                        }
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkMapService.class)) {
                            final ISparkMapService service = (ISparkMapService) GlobalServiceRegister.getDefault().getService(ISparkMapService.class);
                            if (service.isSparkMapComponent(target.getExternalNode())) {
                                IODataComponent output = new IODataComponent(connection, dataComponent.getTable());
                                target.metadataInputChanged(output, connection.getUniqueName());
                            }
                        }
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDQComponentService.class)) {
                            final IDQComponentService service = (IDQComponentService) GlobalServiceRegister.getDefault().getService(IDQComponentService.class);
                            service.externalComponentChange(connection, dataComponent.getTable());
                        }
                    }
                }
            }
            if (connection instanceof Connection) {
                ((Connection) connection).updateName();
            }
        }
    }
    node.setExternalData(newExternalData);
    /*
         * It's better to clone, because will change that, if apply, bug 13325
         */
    // node.setExternalData(newExternalData.clone()); //should test later.
    List<IMetadataTable> cloneNewMetadata = new ArrayList<IMetadataTable>();
    if (newMetaDataList != null) {
        for (IMetadataTable t : newMetaDataList) {
            cloneNewMetadata.add(t.clone(true));
        }
    }
    node.setMetadataList(cloneNewMetadata);
    // init trace
    for (IConnection conn : initTraceList) {
        if (conn instanceof Connection) {
            ((Connection) conn).initTraceParamters();
        }
    }
    for (Connection connection : connectionsToDelete.keySet()) {
        connection.disconnect();
        INode prevNode = connection.getSource();
        INodeConnector nodeConnectorSource, nodeConnectorTarget;
        nodeConnectorSource = prevNode.getConnectorFromType(connection.getLineStyle());
        nodeConnectorSource.setCurLinkNbOutput(nodeConnectorSource.getCurLinkNbOutput() - 1);
        INode nextNode = connection.getTarget();
        nodeConnectorTarget = nextNode.getConnectorFromType(connection.getLineStyle());
        nodeConnectorTarget.setCurLinkNbInput(nodeConnectorTarget.getCurLinkNbInput() - 1);
        inAndOut.getOuputs().remove(connectionsToDelete.get(connection));
        ((Process) node.getProcess()).checkStartNodes();
    }
    ((Process) node.getProcess()).checkProcess();
    if (!isMetaLanguage) {
        refreshCodeView();
        ComponentSettings.switchToCurComponentSettingsView();
    }
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Process(org.talend.designer.core.ui.editor.process.Process) IXmlMapService(org.talend.core.service.IXmlMapService) ISparkMapService(org.talend.core.service.ISparkMapService) INodeConnector(org.talend.core.model.process.INodeConnector) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IDQComponentService(org.talend.core.service.IDQComponentService) IElementParameter(org.talend.core.model.process.IElementParameter) EmfComponent(org.talend.designer.core.model.components.EmfComponent) IODataComponent(org.talend.core.model.components.IODataComponent)

Aggregations

Connection (org.talend.designer.core.ui.editor.connections.Connection)84 IConnection (org.talend.core.model.process.IConnection)52 ArrayList (java.util.ArrayList)47 List (java.util.List)46 Node (org.talend.designer.core.ui.editor.nodes.Node)44 INode (org.talend.core.model.process.INode)35 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)28 Process (org.talend.designer.core.ui.editor.process.Process)24 IElementParameter (org.talend.core.model.process.IElementParameter)20 INodeConnector (org.talend.core.model.process.INodeConnector)18 HashMap (java.util.HashMap)12 IComponent (org.talend.core.model.components.IComponent)12 ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)12 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)11 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)11 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)10 Property (org.talend.core.model.properties.Property)10 Test (org.junit.Test)9 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)9 Map (java.util.Map)8