Search in sources :

Example 61 with IMetadataTable

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

the class DeleteNodeContainerCommand method storeMetadata.

private void storeMetadata(IConnection connection, INode node, boolean remove) {
    ConnectionDeletedInfo deletedInfo = new ConnectionDeletedInfo();
    connectionDeletedInfosMap.put(connection, node, deletedInfo);
    INode source = connection.getSource();
    if (source != null && remove) {
        deletedInfo.metadataTable = connection.getMetadataTable();
        List<IMetadataTable> metaList = source.getMetadataList();
        if (metaList != null && deletedInfo.metadataTable != null) {
            deletedInfo.metadataTableIndex = metaList.indexOf(deletedInfo.metadataTable);
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INode(org.talend.core.model.process.INode)

Example 62 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable 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 63 with IMetadataTable

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

the class ConnectionReconnectCommand method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.commands.Command#execute()
     */
@Override
public void execute() {
    metadataChanges.clear();
    if (newSource != null) {
        INodeConnector connector = oldSource.getConnectorFromName(connectorName);
        connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() - 1);
        connector = newSource.getConnectorFromName(connectorName);
        connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
        if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
            newSourceSchemaType = (String) newSource.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
            boolean builtInNewSource = newSource.getConnectorFromName(connectorName).isMultiSchema();
            boolean builtInOldSource = oldSource.getConnectorFromName(connectorName).isMultiSchema();
            if ((!builtInNewSource) && (!builtInOldSource)) {
                setSchemaToNotBuiltInNode(oldSource, newSource, oldMetadataTable);
                connection.setMetaName(newSource.getUniqueName());
            } else {
                if (!builtInNewSource) {
                    int num = 0;
                    for (int i = 0; i < oldSource.getMetadataList().size(); i++) {
                        IMetadataTable meta = oldSource.getMetadataList().get(i);
                        if (meta.getTableName().equals(oldMetadataTable.getTableName())) {
                            num = i;
                        }
                    }
                    oldSource.getMetadataList().remove(num);
                    setSchemaToNotBuiltInNode(oldSource, newSource, oldMetadataTable);
                    connection.setMetaName(newSource.getUniqueName());
                }
                if (!builtInOldSource) {
                    IMetadataTable meta = oldMetadataTable.clone();
                    meta.setTableName(connection.getUniqueName());
                    newSource.getMetadataList().add(meta);
                    connection.setMetaName(meta.getTableName());
                }
                if ((builtInOldSource) && (builtInNewSource)) {
                    int num = 0;
                    for (int i = 0; i < oldSource.getMetadataList().size(); i++) {
                        IMetadataTable meta = oldSource.getMetadataList().get(i);
                        if (meta.getTableName().equals(oldMetadataTable.getTableName())) {
                            num = i;
                        }
                    }
                    oldSource.getMetadataList().remove(num);
                    newSource.getMetadataList().add(oldMetadataTable);
                }
            }
        // if (newSourceSchemaType != null) {
        // newSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), newSourceSchemaType);
        // }
        // if (oldSourceSchemaType != null) {
        // oldSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
        // }
        } else {
            connection.setMetaName(newSource.getUniqueName());
        }
        connection.reconnect(newSource, oldTarget, newLineStyle);
        connection.updateName();
        if (newSourceSchemaType != null && connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            IMetadataTable sourceMetadataTable = newSource.getMetadataFromConnector(connector.getName());
            // IMetadataTable targetMetadataTable = oldTarget.getMetadataFromConnector(connector.getName());
            if (oldMetadataTable != null && sourceMetadataTable != null) {
                boolean sameFlag = oldMetadataTable.sameMetadataAs(sourceMetadataTable, IMetadataColumn.OPTIONS_NONE);
                // For the auto propagate.
                if (!sameFlag && oldTarget.getComponent().isSchemaAutoPropagated() && (oldMetadataTable.getListColumns().isEmpty() || getPropagateDialog())) {
                    IElementParameter param = oldTarget.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                    if (param == null) {
                        param = oldTarget.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
                    }
                    if (param != null && param.getContext() != null && !param.getContext().equals(connection.getLineStyle().getName())) {
                        param = null;
                    }
                    ChangeMetadataCommand changeMetadataCmd = new ChangeMetadataCommand(oldTarget, param, null, sourceMetadataTable);
                    changeMetadataCmd.execute(true);
                    metadataChanges.add(changeMetadataCmd);
                }
            }
        }
        ((Process) newSource.getProcess()).checkStartNodes();
        ((Process) newSource.getProcess()).checkProcess();
    } else if (newTarget != null) {
        newTargetSchemaType = (String) newTarget.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
        INodeConnector connector = oldTarget.getConnectorFromType(oldLineStyle);
        connector.setCurLinkNbInput(connector.getCurLinkNbInput() - 1);
        connector = newTarget.getConnectorFromType(newLineStyle);
        connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
        connection.reconnect(oldSource, newTarget, newLineStyle);
        connection.updateName();
        if (newTargetSchemaType != null) {
            // TDI-28557:if target is repository mode,can not propagate to target and set to build-in,or target is
            // build-in mode,need user to choose by the pop up dialog
            boolean isPropagate = false;
            boolean isRepoMode = newTargetSchemaType.equals(EmfComponent.REPOSITORY);
            if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA) && !connection.getLineStyle().equals(EConnectionType.FLOW_REF)) {
                IMetadataTable targetOldMetadataTable = newTarget.getMetadataFromConnector(connector.getName());
                if (oldMetadataTable != null && targetOldMetadataTable != null) {
                    boolean sameFlag = oldMetadataTable.sameMetadataAs(targetOldMetadataTable, IMetadataColumn.OPTIONS_NONE);
                    isPropagate = (!sameFlag && newTarget.getComponent().isSchemaAutoPropagated() && !isRepoMode && (targetOldMetadataTable.getListColumns().isEmpty() || getPropagateDialog()));
                    // For the auto propagate.
                    if (isPropagate) {
                        IElementParameter param = newTarget.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                        if (param != null && param.getContext() != null && !param.getContext().equals(connection.getLineStyle().getName())) {
                            param = null;
                        }
                        ChangeMetadataCommand changeMetadataCmd = new ChangeMetadataCommand(newTarget, param, null, oldMetadataTable);
                        changeMetadataCmd.execute(true);
                        metadataChanges.add(changeMetadataCmd);
                    }
                }
            }
            if (isPropagate) {
                newTarget.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
            }
        }
        ((Process) oldSource.getProcess()).checkStartNodes();
        ((Process) oldSource.getProcess()).checkProcess();
    } else {
        //$NON-NLS-1$
        throw new IllegalStateException("Should not happen");
    }
    if (oldSource instanceof Node) {
        if (((Node) oldSource).isJoblet()) {
            ((Node) oldSource).getNodeContainer().setInputs(new HashSet<IConnection>(((Node) oldSource).getInputs()));
            ((Node) oldSource).getNodeContainer().setOutputs(new HashSet<IConnection>(((Node) oldSource).getOutputs()));
        }
    }
    if (oldTarget instanceof Node) {
        if (((Node) oldTarget).isJoblet()) {
            ((Node) oldTarget).getNodeContainer().setInputs(new HashSet<IConnection>(((Node) oldTarget).getInputs()));
            ((Node) oldTarget).getNodeContainer().setOutputs(new HashSet<IConnection>(((Node) oldTarget).getOutputs()));
        }
    }
}
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) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) IConnection(org.talend.core.model.process.IConnection) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 64 with IMetadataTable

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

the class ConnectionReconnectCommand method undo.

@Override
public void undo() {
    if (newSource != null) {
        INodeConnector connector = oldSource.getConnectorFromName(connectorName);
        connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
        connector = newSource.getConnectorFromName(connectorName);
        connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() - 1);
        if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
            boolean builtInNewSource = newSource.getConnectorFromName(connectorName).isMultiSchema();
            boolean builtInOldSource = oldSource.getConnectorFromName(connectorName).isMultiSchema();
            if ((!builtInNewSource) && (!builtInOldSource)) {
                setSchemaToNotBuiltInNode(newSource, oldSource, oldMetadataTable);
                connection.setMetaName(oldSource.getUniqueName());
            } else {
                if (!builtInNewSource) {
                    oldSource.getMetadataList().add(oldMetadataTable);
                    connection.setMetaName(oldMetadataTable.getTableName());
                }
                if (!builtInOldSource) {
                    int num = 0;
                    for (int i = 0; i < newSource.getMetadataList().size(); i++) {
                        IMetadataTable meta = newSource.getMetadataList().get(i);
                        if (meta.getTableName().equals(connection.getUniqueName())) {
                            num = i;
                        }
                    }
                    newSource.getMetadataList().remove(num);
                    setSchemaToNotBuiltInNode(newSource, oldSource, oldMetadataTable);
                    connection.setMetaName(oldSource.getUniqueName());
                }
                if ((builtInOldSource) && (builtInNewSource)) {
                    int num = 0;
                    for (int i = 0; i < newSource.getMetadataList().size(); i++) {
                        IMetadataTable meta = newSource.getMetadataList().get(i);
                        if (meta.getTableName().equals(oldMetadataTable.getTableName())) {
                            num = i;
                        }
                    }
                    newSource.getMetadataList().remove(num);
                    oldSource.getMetadataList().add(oldMetadataTable);
                }
            }
            if (newSourceSchemaType != null) {
                for (ChangeMetadataCommand cmd : metadataChanges) {
                    cmd.undo();
                }
                newSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), newSourceSchemaType);
            }
            if (oldSourceSchemaType != null) {
                oldSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), oldSourceSchemaType);
            }
        } else {
            connection.setMetaName(oldSource.getUniqueName());
        }
    } else if (newTarget != null) {
        INodeConnector connector = oldTarget.getConnectorFromType(oldLineStyle);
        connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
        connector = newTarget.getConnectorFromType(newLineStyle);
        connector.setCurLinkNbInput(connector.getCurLinkNbInput() - 1);
        if (newTargetSchemaType != null) {
            for (ChangeMetadataCommand cmd : metadataChanges) {
                cmd.undo();
            }
            newTarget.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), newTargetSchemaType);
        }
    }
    connection.reconnect(oldSource, oldTarget, oldLineStyle);
    connection.updateName();
    ((Process) oldSource.getProcess()).checkStartNodes();
    ((Process) oldSource.getProcess()).checkProcess();
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 65 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable 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)

Aggregations

IMetadataTable (org.talend.core.model.metadata.IMetadataTable)212 ArrayList (java.util.ArrayList)102 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)81 IElementParameter (org.talend.core.model.process.IElementParameter)67 IConnection (org.talend.core.model.process.IConnection)66 List (java.util.List)56 INode (org.talend.core.model.process.INode)54 Node (org.talend.designer.core.ui.editor.nodes.Node)50 HashMap (java.util.HashMap)48 Map (java.util.Map)39 MetadataTable (org.talend.core.model.metadata.MetadataTable)34 INodeConnector (org.talend.core.model.process.INodeConnector)32 Connection (org.talend.designer.core.ui.editor.connections.Connection)28 Process (org.talend.designer.core.ui.editor.process.Process)25 IComponent (org.talend.core.model.components.IComponent)22 ConnectionItem (org.talend.core.model.properties.ConnectionItem)20 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)18 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)17 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Point (org.eclipse.swt.graphics.Point)15