Search in sources :

Example 31 with PropertyChangeCommand

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

the class NameAndLabelsReferenceController method createCommand.

public Command createCommand(Button button) {
    Object paramObj = button.getData(PARAM_OBJ);
    if (paramObj instanceof GenericElementParameter) {
        GenericElementParameter gParam = (GenericElementParameter) paramObj;
        if (gParam != null) {
            callBeforeActive(gParam);
            NameAndLabelsDialog nameAndLabelsDialog = new NameAndLabelsDialog(composite.getShell(), ComponentsUtils.getFormalPossibleValues(gParam), this.isInWizard());
            if (nameAndLabelsDialog.open() == IDialogConstants.OK_ID) {
                String propertyName = (String) button.getData(PARAMETER_NAME);
                String result = StringUtils.trimToEmpty(nameAndLabelsDialog.getResult());
                Text moduleText = (Text) hashCurControls.get(propertyName);
                moduleText.setText(result);
                PropertyChangeCommand pcc = new PropertyChangeCommand(elem, propertyName, result);
                return pcc;
            }
        }
    }
    return null;
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) Text(org.eclipse.swt.widgets.Text)

Example 32 with PropertyChangeCommand

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

the class ComponentChooseDialog method createRefreshingPropertiesCommand.

/**
     * DOC bqian Comment method "createRefreshingPropertiesCommand".
     *
     * @param selectedNode
     * @param node
     */
private List<Command> createRefreshingPropertiesCommand(CompoundCommand cc, RepositoryNode selectedNode, Node node) {
    // List<Command> list = new ArrayList<Command>();
    if (selectedNode.getObject().getProperty().getItem() instanceof ConnectionItem) {
        String propertyId = selectedNode.getObject().getProperty().getId();
        ConnectionItem originalConnectionItem = (ConnectionItem) selectedNode.getObject().getProperty().getItem();
        ConnectionItem connectionItem = originalConnectionItem;
        Connection originalConnection = connectionItem.getConnection();
        Connection connection = connectionItem.getConnection();
        // if component is CDC, replace by the CDC connection.
        if (node.getComponent().getName().contains("CDC")) {
            // to replace by a flag CDC in component? //$NON-NLS-1$
            if (selectedNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem) {
                final DatabaseConnection databaseConnection = (DatabaseConnection) connection;
                CDCConnection cdcConn = databaseConnection.getCdcConns();
                if (cdcConn != null) {
                    EList cdcTypes = cdcConn.getCdcTypes();
                    if (cdcTypes != null && !cdcTypes.isEmpty()) {
                        CDCType cdcType = (CDCType) cdcTypes.get(0);
                        // replace property by CDC property.
                        propertyId = cdcType.getLinkDB();
                        try {
                            IRepositoryViewObject object = ProxyRepositoryFactory.getInstance().getLastVersion(propertyId);
                            if (object != null) {
                                if (object.getProperty().getItem() instanceof DatabaseConnectionItem) {
                                    DatabaseConnectionItem dbConnItem = (DatabaseConnectionItem) object.getProperty().getItem();
                                    // replace connection by CDC connection
                                    connectionItem = dbConnItem;
                                    connection = dbConnItem.getConnection();
                                }
                            }
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        // set cdc type mode.
                        IElementParameter logModeParam = node.getElementParameter(EParameterName.CDC_TYPE_MODE.getName());
                        if (logModeParam != null) {
                            String cdcTypeMode = ((DatabaseConnection) originalConnection).getCdcTypeMode();
                            Command logModeCmd = new PropertyChangeCommand(node, EParameterName.CDC_TYPE_MODE.getName(), CDCTypeMode.LOG_MODE.getName().equals(cdcTypeMode));
                            cc.add(logModeCmd);
                        }
                        // set lib for as400 so far.
                        //$NON-NLS-1$
                        final String name = "SOURCE_LIB";
                        IElementParameter libParam = node.getElementParameter(name);
                        if (libParam != null) {
                            Object propValue;
                            if (connection.isContextMode() && ContextParameterUtils.isContainContextParam(databaseConnection.getSID())) {
                                propValue = databaseConnection.getSID();
                            } else {
                                propValue = TalendTextUtils.addQuotes(databaseConnection.getSID());
                            }
                            Command libSettingCmd = new PropertyChangeCommand(node, name, propValue);
                            cc.add(libSettingCmd);
                        }
                    }
                }
            }
        }
        // fore EBCDIC, by cli
        if ((connectionItem instanceof EbcdicConnectionItem) && PluginChecker.isEBCDICPluginLoaded()) {
            // TDI-20505:integration the drag/drop for EBCDIC connection and EBCDIC metadataTable
            IRepositoryViewObject object = selectedNode.getObject();
            if (selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_EBCDIC) {
                for (MetadataTable table : ConnectionHelper.getTables(originalConnection)) {
                    Command ebcdicCmd = new RepositoryChangeMetadataForEBCDICCommand(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
                    cc.add(ebcdicCmd);
                }
            }
            if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE) {
                MetadataTable table = null;
                if (object instanceof MetadataTableRepositoryObject) {
                    table = ((MetadataTableRepositoryObject) object).getTable();
                }
                Command ebcdicCmd = new RepositoryChangeMetadataForEBCDICCommand(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
                cc.add(ebcdicCmd);
            }
        }
        // fore HL7, by gcui
        if ((selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded()) || (selectedNode.getParent() != null && selectedNode.getParent().getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded())) {
            if (originalConnection instanceof HL7ConnectionImpl) {
                if (((HL7ConnectionImpl) originalConnection).getRoot() != null) {
                    List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();
                    for (Object obj : ((HL7ConnectionImpl) originalConnection).getRoot()) {
                        if (obj instanceof HL7FileNode) {
                            Map<String, String> newMap = new HashMap<String, String>();
                            newMap.put(IHL7Constant.ATTRIBUTE, ((HL7FileNode) obj).getAttribute());
                            newMap.put(IHL7Constant.PATH, ((HL7FileNode) obj).getFilePath());
                            newMap.put(IHL7Constant.COLUMN, ((HL7FileNode) obj).getRelatedColumn());
                            newMap.put(IHL7Constant.ORDER, String.valueOf(((HL7FileNode) obj).getOrder()));
                            newMap.put(IHL7Constant.VALUE, ((HL7FileNode) obj).getDefaultValue());
                            newMap.put(IHL7Constant.REPEATABLE, String.valueOf(((HL7FileNode) obj).isRepeatable()));
                            mapList.add(newMap);
                        }
                    }
                    IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
                    if (externalNode != null && externalNode.getElementParameter("ROOT") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("ROOT").setValue(mapList);
                    }
                    String fileName = ((HL7ConnectionImpl) originalConnection).getOutputFilePath();
                    if (externalNode != null && externalNode.getElementParameter("FILENAME") != null && fileName != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("FILENAME").setValue(TalendTextUtils.addQuotes(fileName));
                    }
                }
            }
            // fore HL7, by gcui
            if (selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded()) {
                for (MetadataTable table : ConnectionHelper.getTablesWithOrders(originalConnection)) {
                    Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(node, IHL7Constant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
                    cc.add(hl7Cmd);
                }
            }
        }
        // for brms
        if ((selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_BRMS && PluginChecker.isBRMSPluginLoaded()) || (selectedNode.getParent() != null && selectedNode.getParent().getObjectType() == ERepositoryObjectType.METADATA_FILE_BRMS && PluginChecker.isBRMSPluginLoaded())) {
            if (originalConnection instanceof BRMSConnectionImpl) {
                if (((BRMSConnectionImpl) originalConnection).getRoot() != null) {
                    List<Map<String, String>> rootList = new ArrayList<Map<String, String>>();
                    List<Map<String, String>> loopList = new ArrayList<Map<String, String>>();
                    List<Map<String, String>> groupList = new ArrayList<Map<String, String>>();
                    for (Object obj : ((BRMSConnectionImpl) originalConnection).getRoot()) {
                        if (obj instanceof XMLFileNode) {
                            Map<String, String> rootMap = new HashMap<String, String>();
                            //$NON-NLS-1$
                            rootMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
                            //$NON-NLS-1$
                            rootMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
                            //$NON-NLS-1$
                            rootMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
                            //$NON-NLS-1$
                            rootMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
                            //$NON-NLS-1$
                            rootMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
                            rootList.add(rootMap);
                        }
                    }
                    for (Object obj : ((BRMSConnectionImpl) originalConnection).getLoop()) {
                        if (obj instanceof XMLFileNode) {
                            Map<String, String> loopMap = new HashMap<String, String>();
                            //$NON-NLS-1$
                            loopMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
                            //$NON-NLS-1$
                            loopMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
                            //$NON-NLS-1$
                            loopMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
                            //$NON-NLS-1$
                            loopMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
                            //$NON-NLS-1$
                            loopMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
                            loopList.add(loopMap);
                        }
                    }
                    for (Object obj : ((BRMSConnectionImpl) originalConnection).getGroup()) {
                        if (obj instanceof XMLFileNode) {
                            Map<String, String> groupMap = new HashMap<String, String>();
                            //$NON-NLS-1$
                            groupMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
                            //$NON-NLS-1$
                            groupMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
                            //$NON-NLS-1$
                            groupMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
                            //$NON-NLS-1$
                            groupMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
                            //$NON-NLS-1$
                            groupMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
                            groupList.add(groupMap);
                        }
                    }
                    IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
                    if (externalNode != null && externalNode.getElementParameter("ROOT") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("ROOT").setValue(rootList);
                    }
                    if (externalNode != null && externalNode.getElementParameter("LOOP") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("LOOP").setValue(loopList);
                    }
                    if (externalNode != null && externalNode.getElementParameter("GROUP") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("GROUP").setValue(groupList);
                    }
                }
            }
        }
        IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
        if (propertyParam != null) {
            propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
            propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).setValue(propertyId);
        }
        IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
        Map<String, IMetadataTable> repositoryTableMap = new HashMap<String, IMetadataTable>();
        if (!originalConnection.isReadOnly()) {
            for (Object tableObj : ConnectionHelper.getTables(originalConnection)) {
                org.talend.core.model.metadata.builder.connection.MetadataTable table;
                table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
                if (factory.getStatus(originalConnectionItem) != ERepositoryStatus.DELETED) {
                    if (!factory.isDeleted(table)) {
                        String value = table.getId();
                        IMetadataTable newTable = ConvertionHelper.convert(table);
                        repositoryTableMap.put(value, newTable);
                    }
                }
            }
        }
        // DesignerPlugin.getDefault().getProxyRepositoryFactory().getLastVersion("")
        if (propertyParam != null) {
            // command used to set property type
            IMetadataTable metadataTable = null;
            // && selectedNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
            if (selectedNode.getObject() instanceof IMetadataTable) {
                metadataTable = (IMetadataTable) selectedNode.getObject();
                if (metadataTable != null && repositoryTableMap.get(metadataTable.getId()) != null) {
                    metadataTable = repositoryTableMap.get(metadataTable.getId());
                }
            }
            // }
            ChangeValuesFromRepository command1 = new ChangeValuesFromRepository(node, connection, metadataTable, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), propertyId, //$NON-NLS-1$
            true);
            command1.setMaps(repositoryTableMap);
            if (selectedNode.getProperties(EProperties.CONTENT_TYPE) != ERepositoryObjectType.METADATA_CON_QUERY) {
                command1.setGuessQuery(true);
            }
            setSAPSpecailValueForCommand(selectedNode, command1);
            // for salesForce module
            SalesforceModuleRepositoryObject sfObject = null;
            if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_SALESFORCE_MODULE) {
                sfObject = (SalesforceModuleRepositoryObject) selectedNode.getObject();
            } else if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE) {
                IRepositoryViewObject object = selectedNode.getParent().getObject();
                if (object instanceof SalesforceModuleRepositoryObject) {
                    sfObject = (SalesforceModuleRepositoryObject) object;
                }
            }
            if (sfObject != null) {
                ModelElement modelElement = sfObject.getModelElement();
                if (modelElement instanceof SalesforceModuleUnit) {
                    command1.setSalesForceModuleUnit((SalesforceModuleUnit) modelElement);
                }
            }
            cc.add(command1);
        }
        // command used to set metadata
        getChangeMetadataCommand(cc, selectedNode, node, originalConnectionItem);
        // command used to set query
        if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_QUERY) {
            IElementParameter queryParam = node.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE);
            QueryRepositoryObject object = (QueryRepositoryObject) selectedNode.getObject();
            Query query = object.getQuery();
            //$NON-NLS-1$
            String value = originalConnectionItem.getProperty().getId() + " - " + query.getLabel();
            if (queryParam != null) {
                RepositoryChangeQueryCommand command3 = new RepositoryChangeQueryCommand(node, query, queryParam.getName() + ":" + EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), //$NON-NLS-1$
                value);
                cc.add(command3);
            }
        } else {
            if (connection instanceof DatabaseConnection && hasQuery(node)) {
                DatabaseConnection connection2 = (DatabaseConnection) connection;
                String schema = connection2.getUiSchema();
                String dbType = connection2.getDatabaseType();
                QueryGuessCommand queryGuessCommand = null;
                if (node.getMetadataList().size() == 0) {
                    queryGuessCommand = new QueryGuessCommand(node, null, schema, dbType);
                } else {
                    // modified by hyWang for bug 7190
                    queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, connection);
                }
                if (queryGuessCommand != null) {
                    cc.add(queryGuessCommand);
                }
            }
        }
    // context, moved to ChangeValuesFromRepository(bug 5198)
    // ConnectionContextHelper.addContextForNodeParameter(node, connectionItem);
    } else if (selectedNode.getObject().getProperty().getItem() instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) selectedNode.getObject().getProperty().getItem();
        // command used to set job
        String value = processItem.getProperty().getId();
        PropertyChangeCommand command4 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_PROCESS.getName(), value);
        cc.add(command4);
        PropertyChangeCommand command5 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_CONTEXT.getName(), processItem.getProcess().getDefaultContext());
        cc.add(command5);
    } else if (selectedNode.getObject().getProperty().getItem() instanceof FileItem) {
        // hywang add for 6484
        if (selectedNode.getObject().getProperty().getItem() instanceof RulesItem) {
            RulesItem rulesItem = (RulesItem) selectedNode.getObject().getProperty().getItem();
            //                String displayName = "Rules:" + rulesItem.getProperty().getLabel(); //$NON-NLS-N$
            IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
            if (propertyParam != null) {
                propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                // propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())
                // .setListItemsDisplayName(new String[] { displayName });
                final String showId = rulesItem.getProperty().getId();
                PropertyChangeCommand command6 = new PropertyChangeCommand(node, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
                cc.add(command6);
            }
        }
    } else if (selectedNode.getObject().getProperty().getItem() instanceof LinkRulesItem) {
        LinkRulesItem linkItem = (LinkRulesItem) selectedNode.getObject().getProperty().getItem();
        IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
        if (propertyParam != null) {
            propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
            // propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())
            // .setListItemsDisplayName(new String[] { displayName });
            final String showId = linkItem.getProperty().getId();
            PropertyChangeCommand command7 = new PropertyChangeCommand(node, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
            cc.add(command7);
        }
    }
    return null;
}
Also used : Query(org.talend.core.model.metadata.builder.connection.Query) HashMap(java.util.HashMap) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ArrayList(java.util.ArrayList) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HL7ConnectionImpl(org.talend.core.model.metadata.builder.connection.impl.HL7ConnectionImpl) SalesforceModuleUnit(org.talend.core.model.metadata.builder.connection.SalesforceModuleUnit) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) BRMSConnectionImpl(org.talend.core.model.metadata.builder.connection.impl.BRMSConnectionImpl) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) Map(java.util.Map) HashMap(java.util.HashMap) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) RulesItem(org.talend.core.model.properties.RulesItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IExternalNode(org.talend.core.model.process.IExternalNode) PolylineConnection(org.eclipse.draw2d.PolylineConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) RepositoryChangeMetadataForEBCDICCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForEBCDICCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) RepositoryChangeMetadataForSAPCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) ConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.ConnectionReconnectCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) RepositoryChangeMetadataForEBCDICCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForEBCDICCommand) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) CDCType(org.talend.core.model.metadata.builder.connection.CDCType)

Example 33 with PropertyChangeCommand

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

the class ComponentChooseDialog method createValidationRule.

/**
     * DOC ycbai Comment method "createValidationRule".
     *
     * @param dragModel
     * @param targetEditPart
     */
private void createValidationRule(Object dragModel, EditPart targetEditPart) {
    if (!(dragModel instanceof RepositoryNode && targetEditPart instanceof NodeContainerPart)) {
        return;
    }
    RepositoryNode dragNode = (RepositoryNode) dragModel;
    NodeContainerPart nodePart = (NodeContainerPart) targetEditPart;
    if (dragNode.getObject().getProperty().getItem() instanceof ValidationRulesConnectionItem) {
        Node node = (Node) nodePart.getNodePart().getModel();
        List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(node);
        IRepositoryViewObject valRuleObj = dragNode.getObject();
        String schemaType = (String) node.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
        if (EmfComponent.BUILTIN.equals(schemaType) || !ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, valRuleObj)) {
            MessageDialog.openWarning(editor.getSite().getShell(), //$NON-NLS-1$
            Messages.getString("SchemaTypeController.validationrule.title.warn"), //$NON-NLS-1$
            Messages.getString("SchemaTypeController.validationrule.cannotApplyValMsg"));
            return;
        }
        CompoundCommand cc = new CompoundCommand();
        cc.add(new PropertyChangeCommand(node, EParameterName.VALIDATION_RULES.getName(), true));
        cc.add(new //$NON-NLS-1$
        ChangeValuesFromRepository(//$NON-NLS-1$
        node, //$NON-NLS-1$
        null, //$NON-NLS-1$
        "VALIDATION_RULE_TYPE:VALIDATION_RULE_TYPE", EmfComponent.REPOSITORY));
        cc.add(new PropertyChangeCommand(node, EParameterName.REPOSITORY_VALIDATION_RULE_TYPE.getName(), valRuleObj.getProperty().getId()));
        execCommandStack(cc);
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 34 with PropertyChangeCommand

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

the class UpdateNodeParameterCommand method updateSchema.

@SuppressWarnings("unchecked")
private void updateSchema() {
    Object updateObject = result.getUpdateObject();
    if (updateObject == null) {
        return;
    }
    if (updateObject instanceof Node) {
        // opened job
        Node node = (Node) updateObject;
        boolean builtIn = true;
        final IExternalNode externalNode = node.getExternalNode();
        if (result.getResultType() == EUpdateResult.UPDATE) {
            if (result.isChecked()) {
                if (result.getParameter() instanceof List) {
                    // for ebcdic
                    if (PluginChecker.isEBCDICPluginLoaded()) {
                        IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
                        if (service != null) {
                            if (service.isEbcdicNode(node)) {
                                List<Object> parameter = (List<Object>) result.getParameter();
                                if (parameter.size() >= 2) {
                                    IMetadataTable newTable = (IMetadataTable) parameter.get(0);
                                    String schemaName = (String) parameter.get(1);
                                    IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeLabel(node, schemaName);
                                    if (metadataTable != null) {
                                        MetadataToolHelper.copyTable(newTable, metadataTable);
                                    }
                                    syncSchemaForEBCDIC(node, metadataTable);
                                }
                                return;
                            }
                        }
                    }
                    // for tMap
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
                        IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
                        if (service != null && externalNode != null && externalNode.getExternalData() != null) {
                            List<Object> parameter = (List<Object>) result.getParameter();
                            if (parameter.size() >= 2) {
                                if (node.getComponent() != null && "tMap".equals(node.getComponent().getName())) {
                                    //$NON-NLS-1$
                                    IMetadataTable newTable = (IMetadataTable) parameter.get(0);
                                    String schemaId = (String) parameter.get(1);
                                    service.updateMapperTableEntries(externalNode, schemaId, newTable);
                                    node.setMetadataList(externalNode.getMetadataList());
                                    syncSchemaForTMap(node);
                                    // update metadataList,or it will cause bug 21080
                                    for (IExternalMapTable latestTable : externalNode.getExternalData().getOutputTables()) {
                                        for (IMetadataTable tableExsit : node.getMetadataList()) {
                                            // find table,and update the table
                                            if (latestTable.getName().equals(tableExsit.getTableName())) {
                                                List<IMetadataColumn> newColumns = newTable.getListColumns();
                                                for (IMetadataColumn column : tableExsit.getListColumns()) {
                                                    for (IMetadataColumn newColumn : newColumns) {
                                                        if (tableExsit.getTableName().equals(newTable.getTableName()) && newColumn.getLabel().equals(column.getLabel())) {
                                                            column.setTalendType(newColumn.getTalendType());
                                                            column.setNullable(newColumn.isNullable());
                                                            column.setComment(newColumn.getComment());
                                                            column.setDefault(newColumn.getDefault());
                                                            column.setLength(newColumn.getLength());
                                                            column.setType(newColumn.getType());
                                                            column.setKey(newColumn.isKey());
                                                            column.setPrecision(newColumn.getPrecision());
                                                            break;
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else if (result.getParameter() instanceof IMetadataTable) {
                    IMetadataTable newTable = (IMetadataTable) result.getParameter();
                    // getListColumns());
                    if (newTable != null) {
                        INodeConnector nodeConnector = node.getConnectorFromName(newTable.getAttachedConnector());
                        // if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
                        if (nodeConnector != null) {
                            List<IElementParameter> params = node.getElementParametersFromField(EParameterFieldType.SCHEMA_TYPE);
                            if (params == null || params.isEmpty()) {
                                params = node.getElementParametersFromField(EParameterFieldType.SCHEMA_REFERENCE);
                            }
                            // node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                            if (params != null) {
                                for (IElementParameter param : params) {
                                    if (!newTable.getAttachedConnector().equals(param.getContext())) {
                                        continue;
                                    }
                                    ChangeMetadataCommand cmd = null;
                                    if (param.getChildParameters() != null && param.getChildParameters().get("REPOSITORY_SCHEMA_TYPE") != null && result.getContextModeConnectionItem() != null) {
                                        final Object value = param.getChildParameters().get("REPOSITORY_SCHEMA_TYPE").getValue();
                                        // for sap
                                        String remark = result.getRemark();
                                        String namePrefix = "";
                                        if (remark != null) {
                                            String[] split = remark.split(UpdatesConstants.SEGMENT_LINE);
                                            if (split.length == 2) {
                                                String tableName = split[1];
                                                String[] tableSplit = tableName.split("/");
                                                if (tableSplit.length == 3) {
                                                    namePrefix = tableSplit[0] + "/" + tableSplit[1] + "/";
                                                }
                                            }
                                        }
                                        String idAndName = result.getContextModeConnectionItem().getProperty().getId() + UpdatesConstants.SEGMENT_LINE + namePrefix + newTable.getLabel();
                                        if (idAndName.equals(value)) {
                                            cmd = new ChangeMetadataCommand(node, param, null, newTable);
                                        }
                                    } else {
                                        cmd = new ChangeMetadataCommand(node, param, null, newTable);
                                    }
                                    if (cmd != null) {
                                        // wzhang added to fix 9251. get the current connection.
                                        String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                                        IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
                                        Connection repositoryConn = null;
                                        if (lastVersion != null) {
                                            final Item item = lastVersion.getProperty().getItem();
                                            if (item != null && item instanceof ConnectionItem) {
                                                repositoryConn = ((ConnectionItem) item).getConnection();
                                            }
                                        }
                                        cmd.setConnection(repositoryConn);
                                        if (node.getProcess() instanceof IProcess2) {
                                            IUpdateManager updateManager = ((IProcess2) node.getProcess()).getUpdateManager();
                                            if (updateManager instanceof AbstractUpdateManager) {
                                                cmd.setColumnRenameMap(((AbstractUpdateManager) updateManager).getColumnRenamedMap());
                                            }
                                        }
                                        cmd.setRepositoryMode(true);
                                        cmd.execute(true);
                                    }
                                }
                            } else {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        // }
                        }
                        builtIn = false;
                    }
                }
            }
        } else if (result.getResultType() == EUpdateResult.RENAME) {
            List<Object> parameter = (List<Object>) result.getParameter();
            if (parameter.size() >= 3) {
                IMetadataTable newTable = (IMetadataTable) parameter.get(0);
                String oldSourceId = (String) parameter.get(1);
                String newSourceId = (String) parameter.get(2);
                // for ebcdic
                if (PluginChecker.isEBCDICPluginLoaded()) {
                    IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
                    if (service != null) {
                        if (service.isEbcdicNode(node)) {
                            String[] sourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName(oldSourceId);
                            final String oldSchemaName = sourceIdAndChildName[1];
                            sourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName(newSourceId);
                            final String newSchemaName = sourceIdAndChildName[1];
                            IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeLabel(node, oldSchemaName);
                            if (metadataTable != null && oldSchemaName != null) {
                                List<Map<String, Object>> paramValues = (List<Map<String, Object>>) node.getPropertyValue(IEbcdicConstant.TABLE_SCHEMAS);
                                for (Map<String, Object> line : paramValues) {
                                    if (line.get(IEbcdicConstant.FIELD_SCHEMA).equals(oldSchemaName)) {
                                        line.remove(IEbcdicConstant.FIELD_SCHEMA);
                                        line.put(IEbcdicConstant.FIELD_SCHEMA, newSchemaName);
                                    }
                                }
                                PropertyChangeCommand cmd = new PropertyChangeCommand(node, IEbcdicConstant.TABLE_SCHEMAS, paramValues);
                                cmd.execute();
                                MetadataToolHelper.copyTable(newTable, metadataTable);
                                metadataTable.setLabel(newSchemaName);
                                syncSchemaForEBCDIC(node, metadataTable);
                            }
                        }
                    }
                }
                // for tmap
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
                    IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
                    if (service != null && externalNode != null && externalNode.getExternalData() != null) {
                        parameter = (List<Object>) result.getParameter();
                        if (parameter.size() >= 3) {
                            if (node.getComponent() != null && "tMap".equals(node.getComponent().getName())) {
                                //$NON-NLS-1$
                                newTable = (IMetadataTable) parameter.get(0);
                                String schemaId = (String) parameter.get(1);
                                String newSchemaId = (String) parameter.get(2);
                                service.renameMapperTable(externalNode, schemaId, newSchemaId, newTable);
                                node.setMetadataList(externalNode.getMetadataList());
                                syncSchemaForTMap(node);
                            }
                        }
                    }
                }
                String schemaParamName = UpdatesConstants.SCHEMA + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                IElementParameter repositoryParam = node.getElementParameter(schemaParamName);
                if (repositoryParam == null) {
                    schemaParamName = UpdatesConstants.SCHEMA_FLOW + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                    repositoryParam = node.getElementParameter(schemaParamName);
                }
                if (repositoryParam == null) {
                    IElementParameter schemaParentParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
                    if (schemaParentParam != null) {
                        schemaParamName = schemaParentParam.getName() + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                        repositoryParam = node.getElementParameter(schemaParamName);
                    }
                }
                if (repositoryParam != null && oldSourceId.equals(repositoryParam.getValue())) {
                    node.setPropertyValue(schemaParamName, newSourceId);
                    if (newTable != null) {
                        for (INodeConnector nodeConnector : node.getListConnector()) {
                            if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        }
                    }
                    builtIn = false;
                }
                String inputSchemaParamName = UpdatesConstants.INPUT_SCHEMA + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                IElementParameter inputRepositoryParam = node.getElementParameter(inputSchemaParamName);
                if (inputRepositoryParam != null && oldSourceId.equals(inputRepositoryParam.getValue())) {
                    node.setPropertyValue(inputSchemaParamName, newSourceId);
                    if (newTable != null) {
                        for (INodeConnector nodeConnector : node.getListConnector()) {
                            if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        }
                    }
                    builtIn = false;
                }
                // for tELTAggregate
                schemaParamName = UpdatesConstants.SCHEMA_TARGET + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                repositoryParam = node.getElementParameter(schemaParamName);
                if (repositoryParam != null && oldSourceId.equals(repositoryParam.getValue())) {
                    node.setPropertyValue(schemaParamName, newSourceId);
                    if (newTable != null) {
                        for (INodeConnector nodeConnector : node.getListConnector()) {
                            if (nodeConnector.getBaseSchema().equals(repositoryParam.getContext())) {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        }
                    }
                    builtIn = false;
                }
            }
        } else if (result.getResultType() == EUpdateResult.BUIL_IN) {
            // for tELTAgrregate
            if (UpdatesConstants.SCHEMA_TARGET.equals(result.getParameter())) {
                node.setPropertyValue(UpdatesConstants.SCHEMA_TARGET + ":" + EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
            } else {
                // for ebcdic
                if (PluginChecker.isEBCDICPluginLoaded()) {
                    IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
                    if (service != null) {
                        if (service.isEbcdicNode(node)) {
                            Object parameter = result.getParameter();
                            if (parameter instanceof Map) {
                                Map<String, Object> lineValue = (Map<String, Object>) parameter;
                                lineValue.remove(IEbcdicConstant.FIELD_SCHEMA + IEbcdicConstant.REF_TYPE);
                            }
                            // since it is a build-in ebcdic,should change its property before return
                            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                            return;
                        }
                    }
                }
                if (PluginChecker.isJobLetPluginLoaded()) {
                    IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                    if (service != null && service.isJobletInOutComponent(node)) {
                        node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName() + ":" + EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                    }
                }
                node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                for (IElementParameter param : node.getElementParameters()) {
                    SAPParametersUtils.setNoRepositoryParams(param);
                }
            }
        } else if (result.getResultType() == EUpdateResult.DELETE) {
            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
        } else if (result.getResultType() == EUpdateResult.RELOAD) {
            List<Object> parameter = (List<Object>) result.getParameter();
            String connectionId = null;
            String tableLabel = null;
            IRepositoryViewObject toReload = null;
            IMetadataTable tableToReload = null;
            if (parameter instanceof List) {
                List listParameter = parameter;
                connectionId = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                tableLabel = ((String) listParameter.get(0)).split(UpdatesConstants.SEGMENT_LINE)[0];
            }
            if (connectionId != null) {
                try {
                    toReload = ProxyRepositoryFactory.getInstance().getLastVersion(connectionId);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
            if (toReload != null) {
                Set<MetadataTable> newTables = null;
                Item item = toReload.getProperty().getItem();
                if (item instanceof DatabaseConnectionItem) {
                    DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                    Connection connection = dbItem.getConnection();
                    if (connection instanceof DatabaseConnection) {
                        DatabaseConnection dbConn = (DatabaseConnection) connection;
                        Set<MetadataTable> tables = ProjectNodeHelper.getTablesFromSpecifiedDataPackage(dbConn);
                        if (tables != null && !tables.isEmpty()) {
                            Iterator it = tables.iterator();
                            while (it.hasNext() && tableToReload == null) {
                                MetadataTable table = (MetadataTable) it.next();
                                String label = table.getLabel();
                                if (tableLabel != null) {
                                    if (label != null && label.equals(tableLabel)) {
                                        tableToReload = ConvertionHelper.convert(table);
                                        break;
                                    }
                                }
                            }
                        }
                        newTables = ConnectionHelper.getTables(connection);
                    }
                } else {
                    IGenericWizardService wizardService = null;
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                    }
                    if (wizardService != null && wizardService.isGenericItem(item)) {
                        Connection connection = ((ConnectionItem) item).getConnection();
                        List<MetadataTable> metadataTables = wizardService.getMetadataTables(connection);
                        newTables = new HashSet<>(metadataTables);
                    }
                }
                if (newTables != null && !newTables.isEmpty() && tableToReload == null) {
                    Iterator<MetadataTable> it = newTables.iterator();
                    while (it.hasNext() && tableToReload == null) {
                        MetadataTable table = it.next();
                        String label = table.getLabel();
                        if (tableLabel != null) {
                            if (label != null && label.equals(tableLabel)) {
                                tableToReload = ConvertionHelper.convert(table);
                                break;
                            }
                        }
                    }
                }
                if (tableToReload != null) {
                    int index = -1;
                    List<IMetadataTable> tablesInNode = node.getMetadataList();
                    for (IMetadataTable table : tablesInNode) {
                        if (table.getLabel().equals(tableToReload.getLabel())) {
                            index = tablesInNode.indexOf(table);
                            break;
                        }
                    }
                    if (index >= 0) {
                        IMetadataTable oldTable = tablesInNode.get(index);
                        /* dbms and Connector should be transfer when reloaded the table,20024 */
                        tableToReload.setAttachedConnector(oldTable.getAttachedConnector());
                        tableToReload.setDbms(oldTable.getDbms());
                        tablesInNode.remove(index);
                        tablesInNode.add(index, tableToReload);
                        builtIn = false;
                    }
                }
            }
        }
        // bug 23326
        if (builtIn) {
            // bult-in
            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
        }
    }
}
Also used : IDesignerMapperService(org.talend.core.service.IDesignerMapperService) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) INodeConnector(org.talend.core.model.process.INodeConnector) Item(org.talend.core.model.properties.Item) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Iterator(java.util.Iterator) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IExternalNode(org.talend.core.model.process.IExternalNode) IExternalMapTable(org.talend.core.model.process.node.IExternalMapTable) IUpdateManager(org.talend.core.model.update.IUpdateManager) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) ValidationRulesConnection(org.talend.core.model.metadata.builder.connection.ValidationRulesConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IEBCDICProviderService(org.talend.core.service.IEBCDICProviderService) AbstractUpdateManager(org.talend.core.model.update.AbstractUpdateManager) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) HashMap(java.util.HashMap)

Example 35 with PropertyChangeCommand

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

the class UpdateNodePathCommand method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.commands.Command#execute()
     */
@Override
public void execute() {
    IUpdateItemType updateType = result.getUpdateType();
    if (result == null || updateType == null) {
        return;
    }
    Object updateObject = result.getUpdateObject();
    if (updateObject == null || (!(updateObject instanceof Node))) {
        return;
    }
    // instance of node before might not be good (loaded while check updates needed)
    // so get the instance of the node of the current job in this object.
    IProcess process = (IProcess) result.getJob();
    for (INode node : process.getGraphicalNodes()) {
        if (node.getUniqueName().equals(((Node) updateObject).getUniqueName())) {
            updateObject = node;
            result.setUpdateObject(updateObject);
            break;
        }
    }
    Node node = (Node) updateObject;
    if (updateType instanceof EUpdateItemType) {
        switch((EUpdateItemType) updateType) {
            case MAP_PATH:
                Object parameter = result.getParameter();
                if (!(parameter instanceof List)) {
                    return;
                }
                List<Object> params = (List<Object>) parameter;
                if (params.size() != 3) {
                    return;
                }
                IElementParameter param = (IElementParameter) params.get(0);
                if (param == null) {
                    return;
                }
                String oldPath = (String) params.get(1);
                String newPath = (String) params.get(2);
                String relativeNewPath = new Path(newPath).removeFirstSegments(2).removeFileExtension().toPortableString();
                String fullOldPath = new Path(oldPath).removeFileExtension().toPortableString();
                String relativeOldPath = new Path(oldPath).removeFirstSegments(2).removeFileExtension().toPortableString();
                Object value = TalendTextUtils.removeQuotes(String.valueOf(param.getValue()));
                if (!fullOldPath.equals(value) && !relativeOldPath.equals(value)) {
                    return;
                }
                if (fullOldPath.equals(value)) {
                    String newValue = TalendTextUtils.addQuotes(new Path(newPath).removeFileExtension().toPortableString());
                    param.setValue(newValue);
                } else if (relativeOldPath.equals(value)) {
                    param.setValue(TalendTextUtils.addQuotes(relativeNewPath));
                }
                break;
            default:
        }
    }
    if (node.getProcess() instanceof IProcess2) {
        PropertyChangeCommand pcc = new PropertyChangeCommand(node, EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
        boolean executed = false;
        if (process instanceof IGEFProcess) {
            IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
            if (designerCoreUIService != null) {
                executed = designerCoreUIService.executeCommand((IGEFProcess) process, pcc);
            }
        }
        if (!executed) {
            pcc.execute();
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) INode(org.talend.core.model.process.INode) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) IGEFProcess(org.talend.core.ui.process.IGEFProcess) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) IProcess(org.talend.core.model.process.IProcess)

Aggregations

PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)69 IElementParameter (org.talend.core.model.process.IElementParameter)34 Command (org.eclipse.gef.commands.Command)24 Point (org.eclipse.swt.graphics.Point)18 INode (org.talend.core.model.process.INode)18 Node (org.talend.designer.core.ui.editor.nodes.Node)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Control (org.eclipse.swt.widgets.Control)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)13 RepositoryNode (org.talend.repository.model.RepositoryNode)12 CCombo (org.eclipse.swt.custom.CCombo)11 IConnection (org.talend.core.model.process.IConnection)11 ConnectionItem (org.talend.core.model.properties.ConnectionItem)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)10 Item (org.talend.core.model.properties.Item)10 Button (org.eclipse.swt.widgets.Button)9 Text (org.eclipse.swt.widgets.Text)8 MetadataTable (org.talend.core.model.metadata.MetadataTable)8