Search in sources :

Example 1 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class DummyComponent method createConnectors.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.components.IComponent#createConnectors(org.talend.core.model.process.INode)
     */
@Override
public List<? extends INodeConnector> createConnectors(INode node) {
    List<INodeConnector> listConnector = new ArrayList<INodeConnector>();
    INodeConnector nodeConnector;
    for (int i = 0; i < EConnectionType.values().length; i++) {
        EConnectionType currentType = EConnectionType.values()[i];
        if ((currentType == EConnectionType.FLOW_REF) || (currentType == EConnectionType.FLOW_MERGE)) {
            continue;
        }
        boolean exists = false;
        for (INodeConnector curNodeConn : listConnector) {
            if (curNodeConn.getDefaultConnectionType().equals(currentType)) {
                exists = true;
            }
        }
        if (!exists) {
            // will add by default all connectors not defined in
            // the xml files
            nodeConnector = new NodeConnector(node);
            nodeConnector.setDefaultConnectionType(currentType);
            nodeConnector.setName(currentType.getName());
            nodeConnector.setBaseSchema(currentType.getName());
            nodeConnector.addConnectionProperty(currentType, currentType.getRGB(), currentType.getDefaultLineStyle());
            nodeConnector.setLinkName(currentType.getDefaultLinkName());
            nodeConnector.setMenuName(currentType.getDefaultMenuName());
            nodeConnector.setMaxLinkInput(0);
            nodeConnector.setMinLinkInput(0);
            nodeConnector.setMaxLinkOutput(0);
            nodeConnector.setMinLinkOutput(0);
            if (currentType == EConnectionType.FLOW_MAIN) {
                nodeConnector.addConnectionProperty(EConnectionType.FLOW_REF, EConnectionType.FLOW_REF.getRGB(), EConnectionType.FLOW_REF.getDefaultLineStyle());
                nodeConnector.addConnectionProperty(EConnectionType.FLOW_MERGE, EConnectionType.FLOW_MERGE.getRGB(), EConnectionType.FLOW_MERGE.getDefaultLineStyle());
            }
            listConnector.add(nodeConnector);
        }
    }
    return listConnector;
}
Also used : INodeConnector(org.talend.core.model.process.INodeConnector) ArrayList(java.util.ArrayList) EConnectionType(org.talend.core.model.process.EConnectionType) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 2 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class JobletUtil method createTriggerConnector.

private void createTriggerConnector(List<INodeConnector> listConnector, INode jobletNode) {
    IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
    if (service != null) {
        List<INode> triggerNodes = service.getTriggerNodes(jobletNode.getJobletNode());
        for (INode node : triggerNodes) {
            // INode node = jobletNode;
            EConnectionType triggerConnType = service.getTriggerNodeConnType(node);
            if (triggerConnType == null) {
                continue;
            }
            boolean isInput = service.isTriggerInputNode(node);
            INodeConnector nodeConnector = null;
            String name = node.getUniqueName();
            nodeConnector = new NodeConnector(jobletNode);
            nodeConnector.setName(name);
            nodeConnector.setBaseSchema(triggerConnType.getName());
            nodeConnector.setBuiltIn(true);
            nodeConnector.setMaxLinkOutput(isInput ? 0 : 1);
            nodeConnector.setMinLinkOutput(0);
            nodeConnector.setMaxLinkInput(isInput ? 1 : 0);
            nodeConnector.setMinLinkInput(0);
            String displayName = conDisplayName(node.getLabel(), name);
            //$NON-NLS-1$ //$NON-NLS-2$
            nodeConnector.setLinkName(triggerConnType.getDefaultLinkName() + " (" + displayName + ")");
            //$NON-NLS-1$ //$NON-NLS-2$
            nodeConnector.setMenuName(triggerConnType.getDefaultMenuName() + " (" + displayName + ")");
            nodeConnector.setDefaultConnectionType(triggerConnType);
            nodeConnector.addConnectionProperty(triggerConnType, triggerConnType.getRGB(), triggerConnType.getDefaultLineStyle());
            listConnector.add(nodeConnector);
        }
    }
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) INode(org.talend.core.model.process.INode) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) EConnectionType(org.talend.core.model.process.EConnectionType) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 3 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class DCSchemaController method createButtonCommand.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createButtonCommand(org
     * .eclipse.swt.widgets.Button)
     */
@SuppressWarnings("unchecked")
protected Command createButtonCommand(Button button) {
    Button inputButton = button;
    Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
    Node node;
    if (elem instanceof Node) {
        node = (Node) elem;
    } else {
        // else instanceof Connection
        node = (Node) ((Connection) elem).getSource();
    }
    String componentName = node.getComponent().getName();
    initConnectionParameters();
    IContextManager manager;
    if (part == null) {
        manager = new EmptyContextManager();
    } else {
        manager = part.getProcess().getContextManager();
    }
    IElement oldElement = elem;
    if (isUseExistingConnection()) {
        this.elem = connectionNode;
        initConnectionParametersWithContext(connectionNode, manager.getDefaultContext());
    } else {
        initConnectionParametersWithContext(elem, manager.getDefaultContext());
    }
    this.elem = oldElement;
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IDCService.class)) {
        return null;
    }
    IDCService restService = (IDCService) GlobalServiceRegister.getDefault().getService(IDCService.class);
    restService.setupRestHelperInstance(connParameters.getHost(), connParameters.getPort(), connParameters.getUserName(), connParameters.getPassword(), connParameters.getDirectory(), connParameters.isHttps());
    String entityName = elem.getPropertyValue("ENTITY").toString().replaceAll("\"", "");
    IMetadataTable inputMetadata = null, inputMetaCopy = null;
    Connection inputConec = null;
    String propertyName = (String) inputButton.getData(PARAMETER_NAME);
    IElementParameter param = node.getElementParameter(propertyName);
    IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
    String connectionName = null;
    if (connectionParam != null) {
        connectionName = (String) connectionParam.getValue();
    }
    boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
    for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
        if (connec.isActivate() && (EConnectionType.FLOW_MAIN.equals(connec.getLineStyle()) || EConnectionType.TABLE.equals(connec.getLineStyle()) || EConnectionType.FLOW_MERGE.equals(connec.getLineStyle()) || EConnectionType.FLOW_REF.equals(connec.getLineStyle()))) {
            if (connectionName != null && !connec.getName().equals(connectionName)) {
                continue;
            }
            inputMetadata = connec.getMetadataTable();
            inputMetaCopy = inputMetadata.clone();
            inputConec = connec;
            if (connec.getSource().isReadOnly()) {
                inputReadOnlyNode = true;
            } else {
                for (IElementParameter curParam : connec.getSource().getElementParameters()) {
                    if (curParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE || curParam.getFieldType() == EParameterFieldType.DCSCHEMA) {
                        if (curParam.isReadOnly()) {
                            inputReadOnlyParam = true;
                        }
                    }
                }
            }
            // check if the inputMetadata is readonly
            if (inputMetadata != null) {
                for (IMetadataColumn column : inputMetadata.getListColumns()) {
                    IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
                    columnCopied.setCustom(column.isCustom());
                    columnCopied.setReadOnly(column.isReadOnly());
                }
                inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
                inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
            }
            // store the value for Dialog
            Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
            oneInput.put(inputMetaCopy, inputReadOnly);
            inputInfos.put(connec.getSource(), oneInput);
        }
    }
    if (connectionParam != null && inputMetadata == null) {
        //$NON-NLS-1$
        MessageDialog.openError(//$NON-NLS-1$
        button.getShell(), //$NON-NLS-1$
        Messages.getString("SchemaTypeController.inputNotSet"), //$NON-NLS-1$
        Messages.getString("SchemaTypeController.connectionNotAvaliable"));
        return null;
    }
    IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
    // check if the outputMetadata is readonly
    IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
    IMetadataTable outputMetaCopy = originaleOutputTable.clone();
    for (IMetadataColumn column : originaleOutputTable.getListColumns()) {
        IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
        columnCopied.setCustom(column.isCustom());
        columnCopied.setReadOnly(column.isReadOnly());
    }
    outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
    outputMetaCopy.sortCustomColumns();
    // create the MetadataDialog
    MetadataDialog metaDialog = null;
    if (inputMetadata != null) {
        if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
            MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
            //$NON-NLS-1$
            metaDialogForMerge.setText(Messages.getString("SchemaController.schemaOf") + node.getLabel());
            metaDialogForMerge.setInputReadOnly(inputReadOnly);
            metaDialogForMerge.setOutputReadOnly(outputReadOnly);
            if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
                outputMetaCopy = metaDialogForMerge.getOutputMetaData();
                // check if the metadata is modified
                boolean modified = false;
                if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                    modified = true;
                } else {
                    if (inputMetadata != null) {
                        // Notice: the Map inputInfos maybe is modified by the dialog.
                        Set<INode> inputNodes = inputInfos.keySet();
                        for (INode inputNode : inputNodes) {
                            Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                            inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                            if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
                                modified = true;
                            }
                        }
                    }
                }
                // create the changeMetadataCommand
                if (modified) {
                    Command changeMetadataCommand = null;
                    // only output, no input
                    if (inputInfos.isEmpty()) {
                        changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
                    } else {
                        Set<INode> inputNodes = inputInfos.keySet();
                        int count = 0;
                        for (INode inputNode : inputNodes) {
                            Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                            inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                            if (count == 0) {
                                changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
                            } else {
                                changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
                            }
                            count++;
                        }
                    }
                    return changeMetadataCommand;
                }
            }
        } else {
            Node inputNode = (Node) (inputConec.getSource());
            if (inputMetaCopy.getAttachedConnector() == null) {
                INodeConnector mainConnector;
                if (inputNode.isELTComponent()) {
                    mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
                } else {
                    mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
                }
                inputMetaCopy.setAttachedConnector(mainConnector.getName());
            }
            metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
        }
    } else {
        metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
    }
    /*
         * Datacert: Populating data in the edit schema dialog
         *
         * @author : virtusa
         */
    List<IMetadataColumn> columnList = new ArrayList<IMetadataColumn>();
    String prefix = "";
    if (componentName.equalsIgnoreCase(Messages.getString("DataCertController.tDataCertDenormalize.componentName"))) {
        String denorCol = elem.getPropertyValue("DC_COLUMN_DENORMALIZE").toString().replaceAll("\"", "");
        ;
        prefix = denorCol;
        IMetadataTable inputTable = null;
        if (node.getIncomingConnections() != null && node.getIncomingConnections().size() > 0) {
            IConnection inputConn = node.getIncomingConnections().get(0);
            if (inputConn != null) {
                inputTable = inputConn.getMetadataTable();
            }
        }
        if (inputTable != null) {
            for (IMetadataColumn inCol : inputTable.getListColumns()) {
                if (!inCol.getLabel().equals(denorCol)) {
                    columnList.add(inCol);
                }
            }
        }
    }
    restService.addColumnsToSchema(entityName, componentName, prefix, columnList);
    outputMetaCopy.setListColumns(columnList);
    outputMetaCopy.setComment("Attribute Metadata");
    outputMetaCopy.setLabel("Attribute Metadata");
    outputMetaCopy.setTableName(entityName);
    if (metaDialog != null) {
        //$NON-NLS-1$
        metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
        metaDialog.setInputReadOnly(false);
        metaDialog.setOutputReadOnly(false);
        if (metaDialog.open() == MetadataDialog.OK) {
            outputMetaCopy = metaDialog.getOutputMetaData();
            boolean modified = false;
            if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                modified = true;
            }
            if (modified) {
                Node inputNode = null;
                if (inputConec != null) {
                    inputNode = (Node) inputConec.getSource();
                }
                ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
                return changeMetadataCommand;
            }
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) INodeConnector(org.talend.core.model.process.INodeConnector) Button(org.eclipse.swt.widgets.Button) MetadataDialog(org.talend.core.ui.metadata.dialog.MetadataDialog) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IContextManager(org.talend.core.model.process.IContextManager) IElement(org.talend.core.model.process.IElement) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) Command(org.eclipse.gef.commands.Command) HashMap(java.util.HashMap) Map(java.util.Map) MetadataDialogForMerge(org.talend.core.ui.metadata.dialog.MetadataDialogForMerge)

Example 4 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class ReplaceMultiFlowBytReplicateMigrationTask method checkMaxOutputAndUpdate.

/**
     * DOC nrousseau Comment method "checkMaxOutputAndUpdate".
     * 
     * @param processItem
     * @param processType
     * @param component
     */
@SuppressWarnings("unchecked")
private boolean checkMaxOutputAndUpdate(Item processItem, ProcessType processType, IComponent component, NodeType nodeTypeSource) throws PersistenceException {
    boolean modified = false;
    String nodeSourceUniqueName = ComponentUtilities.getNodeUniqueName(nodeTypeSource);
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    List<INodeConnector> nodeConnectors = (List<INodeConnector>) component.createConnectors(null);
    for (INodeConnector nodeConnector : nodeConnectors) {
        if (nodeConnector.getBaseSchema().equals("FLOW") && nodeConnector.getMaxLinkOutput() == 1) {
            //$NON-NLS-1$
            List<ConnectionType> connections = getConnectionsToMove(processType, nodeConnector, nodeSourceUniqueName);
            if (connections != null) {
                List<Rectangle> targetPos = getTargetsRectangle(connections);
                Rectangle startPos = getNodeRectangle(processType, nodeSourceUniqueName);
                Integer tReplicateYPos = 0;
                Integer tReplicateXPos = Integer.MAX_VALUE;
                for (Rectangle rect : targetPos) {
                    if (rect.x < tReplicateXPos) {
                        tReplicateXPos = rect.x;
                    }
                    tReplicateYPos += rect.y;
                }
                tReplicateXPos = (tReplicateXPos + startPos.x) / 2;
                tReplicateYPos = tReplicateYPos / targetPos.size();
                int tempVar = tReplicateXPos / GRID_SIZE;
                tReplicateXPos = tempVar * GRID_SIZE;
                tempVar = tReplicateYPos / GRID_SIZE;
                tReplicateYPos = tempVar * GRID_SIZE;
                Point tReplicatePos = findLocationForNode(processType, new Point(tReplicateXPos, tReplicateYPos));
                addtReplicateComponent(processType, tReplicatePos, nodeTypeSource, nodeSourceUniqueName, nodeConnector, connections);
                modified = true;
            }
        }
    }
    if (modified) {
        factory.save(processItem);
    }
    return modified;
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) INodeConnector(org.talend.core.model.process.INodeConnector) Point(org.eclipse.draw2d.geometry.Point) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class SchemaReferenceController method createButtonCommand.

@Override
protected Command createButtonCommand(Button button) {
    if (checkForRepositoryShema(button)) {
        return null;
    }
    Button inputButton = button;
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    if (inputButton.getData(NAME).equals(SCHEMA)) {
        // this map wil hold the all input connection for the tUnite component
        Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
        INode node;
        if (elem instanceof Node) {
            node = (INode) elem;
        } else {
            // else instanceof Connection
            node = ((IConnection) elem).getSource();
        }
        IMetadataTable inputMetadata = null, inputMetaCopy = null;
        Connection inputConec = null;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
        String connectionName = null;
        if (connectionParam != null) {
            connectionName = (String) connectionParam.getValue();
        }
        Object obj = button.getData(FORCE_READ_ONLY);
        boolean forceReadOnly = false;
        if (obj != null) {
            forceReadOnly = (Boolean) obj;
        }
        boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
        for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
            if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE) || connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) || connec.getLineStyle() == EConnectionType.FLOW_REF)) {
                if (connectionName != null && !connec.getName().equals(connectionName)) {
                    continue;
                }
                inputMetadata = connec.getMetadataTable();
                inputMetaCopy = inputMetadata.clone();
                inputConec = connec;
                if (connec.getSource().isReadOnly()) {
                    inputReadOnlyNode = true;
                } else {
                    for (IElementParameter curParam : connec.getSource().getElementParameters()) {
                        if (curParam.getFieldType() == EParameterFieldType.SCHEMA_REFERENCE) {
                            if (curParam.isReadOnly()) {
                                inputReadOnlyParam = true;
                            }
                        }
                    }
                }
                // check if the inputMetadata is readonly
                if (inputMetadata != null) {
                    for (IMetadataColumn column : inputMetadata.getListColumns(true)) {
                        IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
                        columnCopied.setCustom(column.isCustom());
                        columnCopied.setReadOnly(column.isReadOnly());
                    }
                    inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
                    inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
                }
                // store the value for Dialog
                Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
                oneInput.put(inputMetaCopy, inputReadOnly);
                inputInfos.put(connec.getSource(), oneInput);
            }
        }
        if (connectionParam != null && inputMetadata == null) {
            //$NON-NLS-1$
            MessageDialog.openError(//$NON-NLS-1$
            button.getShell(), //$NON-NLS-1$
            Messages.getString("SchemaReferenceController.inputNotSet"), //$NON-NLS-1$
            Messages.getString("SchemaReferenceController.connectionNotAvaliable"));
            return null;
        }
        IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
        // check if the outputMetadata is readonly
        IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
        // when several schema_type button ,need get the right one which is opening
        //$NON-NLS-1$
        IElementParameter schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        // need setRepository here
        if (!param.getContext().equals(schemaParam.getContext())) {
            //$NON-NLS-1$
            schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        }
        if (schemaParam != null && EmfComponent.REPOSITORY.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(true);
            }
        } else if (schemaParam != null && EmfComponent.BUILTIN.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(false);
            }
        }
        IMetadataTable outputMetaCopy = originaleOutputTable.clone(true);
        for (IMetadataColumn column : originaleOutputTable.getListColumns(true)) {
            IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
            columnCopied.setCustom(column.isCustom());
            columnCopied.setReadOnly(column.isReadOnly());
        }
        outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
        //$NON-NLS-1$
        IElementParameter schemaTypeParam = param.getChildParameters().get("SCHEMA_TYPE");
        List<IElementParameterDefaultValue> defaultValues = schemaTypeParam.getDefaultValues();
        for (IElementParameterDefaultValue elementParameterDefaultValue : defaultValues) {
            if (elementParameterDefaultValue.getDefaultValue() instanceof MetadataTable) {
                MetadataTable table = (MetadataTable) elementParameterDefaultValue.getDefaultValue();
                outputMetaCopy.setReadOnlyColumnPosition(table.getReadOnlyColumnPosition());
                break;
            }
        }
        outputMetaCopy.sortCustomColumns();
        if (!forceReadOnly) {
            outputReadOnly = prepareReadOnlyTable(outputMetaCopy, param.isReadOnly(), node.isReadOnly());
        } else {
            outputReadOnly = true;
        }
        MetadataDialog metaDialog = null;
        if (inputMetadata != null) {
            if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
                MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
                //$NON-NLS-1$
                metaDialogForMerge.setText(Messages.getString("SchemaReferenceController.schemaOf") + node.getLabel());
                metaDialogForMerge.setInputReadOnly(inputReadOnly);
                metaDialogForMerge.setOutputReadOnly(outputReadOnly);
                if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
                    outputMetaCopy = metaDialogForMerge.getOutputMetaData();
                    // check if the metadata is modified
                    boolean modified = false;
                    if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                        modified = true;
                    } else {
                        if (inputMetadata != null) {
                            // Notice: the Map inputInfos maybe is modified by the dialog.
                            Set<INode> inputNodes = inputInfos.keySet();
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
                                    modified = true;
                                }
                            }
                        }
                    }
                    // create the changeMetadataCommand
                    if (modified) {
                        if (switchParam != null) {
                            switchParam.setValue(Boolean.FALSE);
                        }
                        Command changeMetadataCommand = null;
                        // only output, no input
                        if (inputInfos.isEmpty()) {
                            changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
                        } else {
                            Set<INode> inputNodes = inputInfos.keySet();
                            int count = 0;
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (count == 0) {
                                    changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
                                } else {
                                    changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
                                }
                                count++;
                            }
                        }
                        return changeMetadataCommand;
                    }
                }
            } else {
                INode inputNode = (inputConec.getSource());
                if (inputMetaCopy.getAttachedConnector() == null) {
                    INodeConnector mainConnector;
                    if (inputNode.isELTComponent()) {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
                    } else {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
                    }
                    inputMetaCopy.setAttachedConnector(mainConnector.getName());
                }
                metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
            }
        } else {
            metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
        }
        if (metaDialog != null) {
            //$NON-NLS-1$
            metaDialog.setText(Messages.getString("SchemaReferenceController.schema.title", node.getLabel()));
            metaDialog.setInputReadOnly(inputReadOnly);
            metaDialog.setOutputReadOnly(outputReadOnly);
            if (metaDialog.open() == MetadataDialog.OK) {
                inputMetaCopy = metaDialog.getInputMetaData();
                outputMetaCopy = metaDialog.getOutputMetaData();
                boolean modified = false;
                if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                    modified = true;
                } else {
                    if (inputMetadata != null) {
                        if (!inputMetaCopy.sameMetadataAs(inputMetadata, IMetadataColumn.OPTIONS_NONE)) {
                            modified = true;
                        }
                    }
                }
                if (modified) {
                    if (switchParam != null) {
                        switchParam.setValue(Boolean.FALSE);
                    }
                    INode inputNode = null;
                    if (inputConec != null) {
                        inputNode = inputConec.getSource();
                    }
                    // update the component schema
                    if (param instanceof GenericElementParameter) {
                        GenericElementParameter genericElementParameter = (GenericElementParameter) param;
                        String paramName = genericElementParameter.getName();
                        ComponentProperties componentProperties = node.getComponentProperties();
                        if (componentProperties != null) {
                            org.talend.daikon.properties.property.Property schemaProperty = componentProperties.getValuedProperty(paramName);
                            if (schemaProperty != null) {
                                SchemaUtils.updateComponentSchema(node, outputMetaCopy, null);
                            }
                        }
                    }
                    if (node.getComponent().isSchemaAutoPropagated()) {
                        ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
                        return changeMetadataCommand;
                    } else {
                        ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
                        changeMetadataCommand.setPropagate(Boolean.FALSE);
                        return changeMetadataCommand;
                    }
                }
            }
        }
    } else if (inputButton.getData(NAME).equals(RETRIEVE_SCHEMA)) {
        Node node = (Node) elem;
        // String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        final Command cmd = RetrieveSchemaHelper.retrieveSchemasCommand(node);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (inputButton.getData(NAME).equals(RESET_COLUMNS)) {
        Node node = (Node) elem;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        final Command cmd = SynchronizeSchemaHelper.createCommand(node, param);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter schemaParam = elem.getElementParameter(paramName);
        ERepositoryObjectType type = ERepositoryObjectType.METADATA_CON_TABLE;
        String filter = schemaParam.getFilter();
        RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), type, filter);
        if (dialog.open() == RepositoryReviewDialog.OK) {
            RepositoryNode node = dialog.getResult();
            while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
                node = node.getParent();
            }
            IRepositoryViewObject object = dialog.getResult().getObject();
            Property property = object.getProperty();
            String id = property.getId();
            // The name is Table Name.
            String name = object.getLabel();
            if (name != null) {
                if (elem instanceof Node) {
                    //$NON-NLS-1$
                    String value = id + " - " + name;
                    //$NON-NLS-1$
                    paramName = paramName + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                    Command selectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(value));
                    executeCommand(selectorCommand);
                }
            }
            //$NON-NLS-1$
            String value = id + " - " + name;
            //$NON-NLS-1$
            String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
            org.talend.core.model.metadata.builder.connection.Connection connection = null;
            if (elem instanceof Node) {
                IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
                connection = MetadataToolHelper.getConnectionFromRepository(value);
                // For validation rule.
                boolean isValRulesLost = false;
                IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
                if (currentValRuleObj != null) {
                    List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(value);
                    if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
                        if (!MessageDialog.openConfirm(button.getShell(), //$NON-NLS-1$
                        Messages.getString("SchemaReferenceController.validationrule.title.confirm"), Messages.getString("SchemaReferenceController.validationrule.selectMetadataMsg"))) {
                            //$NON-NLS-1$
                            return null;
                        } else {
                            isValRulesLost = true;
                        }
                    }
                }
                if (repositoryMetadata == null) {
                    repositoryMetadata = new MetadataTable();
                }
                if (switchParam != null) {
                    switchParam.setValue(Boolean.FALSE);
                }
                CompoundCommand cc = new CompoundCommand();
                RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, null, null);
                changeMetadataCommand.setConnection(connection);
                cc.add(changeMetadataCommand);
                if (isValRulesLost) {
                    ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
                }
                return cc;
            }
        }
    } else if (button.getData(NAME).equals(COPY_CHILD_COLUMNS)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter param = elem.getElementParameter(paramName);
        IElementParameter processParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
        IElementParameter processIdParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
        String id = (String) processIdParam.getValue();
        Item item = ItemCacheManager.getProcessItem(id);
        Node node = (Node) elem;
        copySchemaFromChildJob(node, item);
        // pop up the schema dialog
        MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), node.getMetadataList().get(0), node, getCommandStack());
        //$NON-NLS-1$
        metaDialog.setText(Messages.getString("SchemaReferenceController.schemaOf") + node.getLabel());
        if (metaDialog.open() == MetadataDialog.OK) {
            IMetadataTable outputMetaData = metaDialog.getOutputMetaData();
            return new ChangeMetadataCommand(node, param, null, outputMetaData);
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) RepositoryNode(org.talend.repository.model.RepositoryNode) INode(org.talend.core.model.process.INode) INodeConnector(org.talend.core.model.process.INodeConnector) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) Button(org.eclipse.swt.widgets.Button) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) MetadataDialog(org.talend.core.ui.metadata.dialog.MetadataDialog) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) RepositoryNode(org.talend.repository.model.RepositoryNode) RepositoryReviewDialog(org.talend.repository.ui.dialog.RepositoryReviewDialog) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HashMap(java.util.HashMap) Map(java.util.Map) MetadataDialogForMerge(org.talend.core.ui.metadata.dialog.MetadataDialogForMerge)

Aggregations

INodeConnector (org.talend.core.model.process.INodeConnector)76 ArrayList (java.util.ArrayList)37 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)31 INode (org.talend.core.model.process.INode)31 Node (org.talend.designer.core.ui.editor.nodes.Node)31 IConnection (org.talend.core.model.process.IConnection)27 IElementParameter (org.talend.core.model.process.IElementParameter)22 Process (org.talend.designer.core.ui.editor.process.Process)21 List (java.util.List)20 Connection (org.talend.designer.core.ui.editor.connections.Connection)17 IJobletProviderService (org.talend.core.ui.IJobletProviderService)14 HashMap (java.util.HashMap)11 NodeConnector (org.talend.designer.core.model.components.NodeConnector)11 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)9 EConnectionType (org.talend.core.model.process.EConnectionType)9 Map (java.util.Map)8 IExternalNode (org.talend.core.model.process.IExternalNode)7 IProcess (org.talend.core.model.process.IProcess)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 Point (org.eclipse.draw2d.geometry.Point)6