Search in sources :

Example 1 with IGenericWizardService

use of org.talend.core.runtime.services.IGenericWizardService in project tdi-studio-se by Talend.

the class ChangeValuesFromRepository method execute.

@SuppressWarnings("unchecked")
@Override
public void execute() {
    // Force redraw of Commponents propoerties
    elem.setPropertyValue(updataComponentParamName, new Boolean(true));
    boolean allowAutoSwitch = true;
    IElementParameter elemParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    if (elemParam != null) {
        // add for TDI-8053
        elemParam.setValue(Boolean.FALSE);
        allowAutoSwitch = (Boolean) elemParam.getValue();
    }
    if (!allowAutoSwitch && (elem instanceof Node)) {
        // force the autoSwitch to true if the schema is empty and if the
        // query is not set.
        Node node = (Node) elem;
        boolean isSchemaEmpty = false;
        if (node.getMetadataList().size() > 0) {
            isSchemaEmpty = node.getMetadataList().get(0).getListColumns().size() == 0;
        } else {
            isSchemaEmpty = true;
        }
        for (IElementParameter curParam : node.getElementParameters()) {
            if (curParam.getFieldType().equals(EParameterFieldType.MEMO_SQL)) {
                if (curParam.getDefaultValues().size() > 0) {
                }
            }
        }
        if (isSchemaEmpty) {
            allowAutoSwitch = true;
        }
        if (((INode) elem).getComponent().getName().equals("tWebService")) {
            //$NON-NLS-1$
            allowAutoSwitch = true;
        }
    }
    if (propertyName.split(":")[1].equals(propertyTypeName)) {
        //$NON-NLS-1$
        elem.setPropertyValue(propertyName, value);
        if (allowAutoSwitch) {
            // Update spark mode to YARN_CLIENT if repository
            if (elem instanceof IProcess) {
                if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(((IProcess) elem).getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(((IProcess) elem).getComponentsType())) {
                    if (EmfComponent.REPOSITORY.equals(value)) {
                        IElementParameter sparkLocalParam = ((IProcess) elem).getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
                        IElementParameter sparkParam = ((IProcess) elem).getElementParameter(HadoopConstants.SPARK_MODE);
                        if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
                            sparkLocalParam.setValue(false);
                        }
                        if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
                            sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
                        }
                    }
                }
            }
            setOtherProperties();
        }
    } else {
        oldMetadata = (String) elem.getPropertyValue(propertyName);
        elem.setPropertyValue(propertyName, value);
        if (allowAutoSwitch) {
            setOtherProperties();
        }
    }
    String propertyParamName = null;
    if (elem.getElementParameter(propertyName).getParentParameter() != null) {
        IElementParameter param = elem.getElementParameter(propertyName).getParentParameter();
        if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
            propertyParamName = param.getName();
        }
    }
    if (propertyName.split(":")[1].equals(propertyTypeName) && (EmfComponent.BUILTIN.equals(value))) {
        //$NON-NLS-1$
        for (IElementParameter param : elem.getElementParameters()) {
            if (param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                continue;
            }
            boolean paramFlag = JobSettingsConstants.isExtraParameter(param.getName());
            //$NON-NLS-1$
            boolean extraFlag = JobSettingsConstants.isExtraParameter(propertyName.split(":")[0]);
            if (paramFlag == extraFlag) {
                // for memo sql
                if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
                    IElementParameter querystoreParam = elem.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE, param.getCategory());
                    if (querystoreParam != null) {
                        Map<String, IElementParameter> childParam = querystoreParam.getChildParameters();
                        if (childParam != null) {
                            IElementParameter queryTypeParam = childParam.get(EParameterName.QUERYSTORE_TYPE.getName());
                            if (queryTypeParam != null && EmfComponent.REPOSITORY.equals(queryTypeParam.getValue())) {
                                continue;
                            }
                        }
                    }
                }
                if (param.getRepositoryValue() != null) {
                    param.setReadOnly(false);
                    // for job settings extra.(feature 2710)
                    param.setRepositoryValueUsed(false);
                }
            }
        }
    } else {
        oldValues.clear();
        List<ComponentProperties> componentProperties = null;
        IGenericWizardService wizardService = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
            wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
        }
        if (wizardService != null && wizardService.isGenericConnection(connection)) {
            componentProperties = wizardService.getAllComponentProperties(connection, null);
        }
        IElementParameter propertyParam = elem.getElementParameter(propertyName);
        List<IElementParameter> elementParameters = new ArrayList<>(elem.getElementParameters());
        for (IElementParameter param : elementParameters) {
            String repositoryValue = param.getRepositoryValue();
            if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
                continue;
            }
            boolean isGenericRepositoryValue = RepositoryToComponentProperty.isGenericRepositoryValue(connection, componentProperties, param.getName());
            if (repositoryValue == null && isGenericRepositoryValue) {
                repositoryValue = param.getName();
                param.setRepositoryValue(repositoryValue);
                param.setRepositoryValueUsed(true);
            }
            if (repositoryValue == null || param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                continue;
            }
            String componentName = elem instanceof INode ? (((INode) elem).getComponent().getName()) : null;
            boolean b = elem instanceof INode && (//$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tHL7Input") || //$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tAdvancedFileOutputXML") || ((INode) elem).getComponent().getName().equals("tMDMOutput") || ((INode) elem).getComponent().getName().equals("tWebService") || ((INode) elem).getComponent().getName().equals("tCreateTable") || //$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tWriteJSONField"));
            if ((//$NON-NLS-1$
            "TYPE".equals(repositoryValue) || (isGenericRepositoryValue || param.isShow(elem.getElementParameters())) || b) && (!param.getName().equals(propertyTypeName))) {
                if (param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                    continue;
                }
                Object objectValue = null;
                if (connection instanceof XmlFileConnection && this.dragAndDropAction == true && repositoryValue.equals("FILE_PATH") && reOpenXSDBool == true) {
                    objectValue = RepositoryToComponentProperty.getXmlAndXSDFileValue((XmlFileConnection) connection, repositoryValue);
                } else if (connection instanceof SalesforceSchemaConnection && "MODULENAME".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    if (this.moduleUnit != null) {
                        objectValue = moduleUnit.getModuleName();
                    } else {
                        objectValue = null;
                    }
                } else // module which was the last one be retrived
                if (connection instanceof SalesforceSchemaConnection && "CUSTOM_MODULE_NAME".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    if (this.moduleUnit != null) {
                        objectValue = moduleUnit.getModuleName();
                    } else {
                        objectValue = null;
                    }
                } else if (connection instanceof MDMConnection) {
                    if (table == null) {
                        IMetadataTable metaTable = null;
                        if (((Node) elem).getMetadataList().size() > 0) {
                            metaTable = ((Node) elem).getMetadataList().get(0);
                        }
                        objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, metaTable);
                    } else {
                        objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, table);
                    }
                } else if (connection instanceof WSDLSchemaConnection && "USE_PROXY".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    objectValue = ((WSDLSchemaConnection) connection).isUseProxy();
                } else {
                    IMetadataTable metaTable = table;
                    if (metaTable == null && elem instanceof Node) {
                        INodeConnector conn = ((Node) elem).getConnectorFromType(EConnectionType.FLOW_MAIN);
                        if (conn != null && conn.getMaxLinkOutput() == 1) {
                            metaTable = ((Node) elem).getMetadataFromConnector(conn.getName());
                        }
                    }
                    objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, metaTable, componentName);
                }
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IJsonFileService.class)) {
                    IJsonFileService jsonService = (IJsonFileService) GlobalServiceRegister.getDefault().getService(IJsonFileService.class);
                    boolean paramChanged = jsonService.changeFilePathFromRepository(connection, param, elem, objectValue);
                    if (paramChanged) {
                        continue;
                    }
                }
                if (objectValue != null) {
                    oldValues.put(param.getName(), param.getValue());
                    if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("TYPE")) {
                        //$NON-NLS-1$
                        String dbVersion = "";
                        if (connection instanceof DatabaseConnection) {
                            dbVersion = ((DatabaseConnection) connection).getDbVersionString();
                        }
                        boolean found = false;
                        String[] list = param.getListRepositoryItems();
                        for (int i = 0; (i < list.length) && (!found); i++) {
                            if (objectValue.equals(list[i])) {
                                found = true;
                                elem.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                            }
                        }
                        IElementParameter elementParameter = null;
                        IElementParameter elementParameter2 = null;
                        if (EParameterName.DB_TYPE.getName().equals(param.getName())) {
                            elementParameter = elem.getElementParameter(EParameterName.DB_VERSION.getName());
                            elementParameter2 = elem.getElementParameter(EParameterName.SCHEMA_DB.getName());
                        } else {
                            elementParameter = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_VERSION.getName()));
                            elementParameter2 = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.SCHEMA_DB.getName()));
                        }
                        String dbType = "";
                        if (param.getValue() != null) {
                            int indexOfItemFromList = param.getIndexOfItemFromList(param.getValue().toString());
                            if (indexOfItemFromList != -1) {
                                dbType = param.getListItemsDisplayCodeName()[indexOfItemFromList];
                            }
                        }
                        // Some DB not need fill the schema parameter for the JobSetting View "Extra" ,"Stats&Logs"
                        if (elementParameter2 != null && !elementParameter2.isShow(elem.getElementParameters()) && !elementParameter2.getValue().equals("")) {
                            elementParameter2.setValue("");
                        }
                        if (StatsAndLogsConstants.JDBC.equals(dbType)) {
                            IElementParameter dbNameParm = elem.getElementParameter(EParameterName.DBNAME.getName());
                            if (dbNameParm != null) {
                                dbNameParm.setValue("");
                            }
                        } else {
                            IElementParameter rulParam = elem.getElementParameter(EParameterName.URL.getName());
                            if (rulParam != null) {
                                rulParam.setValue("");
                            }
                            IElementParameter classParam = elem.getElementParameter(EParameterName.DRIVER_CLASS.getName());
                            if (classParam != null) {
                                classParam.setValue("");
                            }
                            IElementParameter jarParam = elem.getElementParameter(EParameterName.DRIVER_JAR.getName());
                            if (jarParam != null) {
                                jarParam.setValue(new ArrayList<Map<String, Object>>());
                            }
                        }
                        JobSettingVersionUtil.setDbVersion(elementParameter, dbVersion, false);
                        DesignerUtilities.setSchemaDB(elementParameter2, param.getValue());
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("FRAMEWORK_TYPE")) {
                        //$NON-NLS-1$
                        String[] list = param.getListItemsDisplayName();
                        for (int i = 0; i < list.length; i++) {
                            if (objectValue.equals(list[i])) {
                                elem.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("EDI_VERSION")) {
                        String[] list = param.getListItemsDisplayName();
                        for (String element : list) {
                            if (objectValue.toString().toUpperCase().equals(element)) {
                                elem.setPropertyValue(param.getName(), objectValue);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("DRIVER")) {
                        String[] list = param.getListItemsDisplayCodeName();
                        for (String element : list) {
                            if (objectValue.toString().toUpperCase().equals(element)) {
                                elem.setPropertyValue(param.getName(), objectValue);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("CONNECTION_MODE")) {
                        //$NON-NLS-1$
                        if (!objectValue.equals(param.getValue())) {
                            //$NON-NLS-1$
                            PropertyChangeCommand cmd = new PropertyChangeCommand(elem, "CONNECTION_MODE", objectValue);
                            cmd.execute();
                        }
                    } else {
                        if (repositoryValue.equals("ENCODING")) {
                            //$NON-NLS-1$
                            IElementParameter paramEncoding = param.getChildParameters().get(EParameterName.ENCODING_TYPE.getName());
                            if (connection instanceof FTPConnection) {
                                if (((FTPConnection) connection).getEcoding() != null) {
                                    paramEncoding.setValue(((FTPConnection) connection).getEcoding());
                                } else {
                                    paramEncoding.setValue(EmfComponent.ENCODING_TYPE_CUSTOM);
                                }
                            } else {
                                if (objectValue instanceof String) {
                                    String str = TalendTextUtils.removeQuotes((String) objectValue);
                                    if (str.equals(EmfComponent.ENCODING_TYPE_UTF_8)) {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_UTF_8);
                                    } else if (str.equals(EmfComponent.ENCODING_TYPE_ISO_8859_15)) {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_ISO_8859_15);
                                    } else {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_CUSTOM);
                                    // paramEncoding.setRepositoryValueUsed(true);
                                    }
                                }
                            }
                        } else if (repositoryValue.equals("CSV_OPTION")) {
                            //$NON-NLS-1$
                            setOtherProperties();
                        }
                        if (repositoryValue.equals("MODULENAME")) {
                            //$NON-NLS-1$
                            List list = new ArrayList();
                            Object[] listItemsValue = elem.getElementParameter("MODULENAME").getListItemsValue();
                            for (Object element : listItemsValue) {
                                list.add(element);
                            }
                            if (list != null && !list.contains(objectValue)) {
                                //$NON-NLS-1$
                                objectValue = "CustomModule";
                            }
                        }
                        // hywang add for excel 2007
                        if (repositoryValue.equals(EParameterName.FILE_PATH.getName())) {
                            String filePath = "";
                            if (connection.isContextMode()) {
                                ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
                                if (contextItem != null) {
                                    String selectedContext = contextItem.getDefaultContext();
                                    final ContextType contextTypeByName = ContextUtils.getContextTypeByName(contextItem, selectedContext, true);
                                    filePath = ConnectionContextHelper.getOriginalValue(contextTypeByName, objectValue.toString());
                                }
                            } else {
                                filePath = TalendTextUtils.removeQuotes(objectValue.toString());
                            }
                            boolean versionCheckFor2007 = false;
                            if (filePath != null && filePath.endsWith(".xlsx")) {
                                versionCheckFor2007 = true;
                            }
                            if (elem.getElementParameter("VERSION_2007") != null) {
                                elem.setPropertyValue("VERSION_2007", versionCheckFor2007);
                            }
                        }
                        if (param.getFieldType().equals(EParameterFieldType.FILE)) {
                            if (objectValue != null) {
                                objectValue = objectValue.toString().replace("\\", "/");
                            }
                        }
                        elem.setPropertyValue(param.getName(), objectValue);
                    }
                    param.setRepositoryValueUsed(true);
                } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("XML_MAPPING")) {
                    //$NON-NLS-1$
                    List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
                    if (((Node) elem).getMetadataList().size() > 0) {
                        IMetadataTable metaTable = ((Node) elem).getMetadataList().get(0);
                        //$NON-NLS-1$
                        RepositoryToComponentProperty.getTableXmlFileValue(//$NON-NLS-1$
                        connection, //$NON-NLS-1$
                        "XML_MAPPING", //$NON-NLS-1$
                        param, table, metaTable);
                        param.setRepositoryValueUsed(true);
                    }
                } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("WSDL_PARAMS") && connection != null) {
                    //$NON-NLS-1$
                    List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
                    table.clear();
                    ArrayList parameters = ((WSDLSchemaConnection) connection).getParameters();
                    if (parameters != null) {
                        for (Object object : parameters) {
                            Map<String, Object> map2 = new HashMap<String, Object>();
                            //$NON-NLS-1$
                            map2.put("VALUE", TalendTextUtils.addQuotes(object.toString()));
                            table.add(map2);
                        }
                    }
                    param.setRepositoryValueUsed(true);
                } else if (param.getFieldType().equals(EParameterFieldType.TEXT) && "XPATH_QUERY".equals(param.getRepositoryValue())) {
                    //$NON-NLS-1$
                    param.setRepositoryValueUsed(true);
                } else {
                    // For SAP
                    String paramName = param.getName();
                    if ("SAP_PROPERTIES".equals(paramName) || "MAPPING_INPUT".equals(paramName) || // INPUT_PARAMS should be MAPPING_INPUT,bug16426
                    "SAP_FUNCTION".equals(paramName) || "OUTPUT_PARAMS".equals(paramName) || "SAP_ITERATE_OUT_TYPE".equals(paramName) || "SAP_ITERATE_OUT_TABLENAME".equals(paramName)) {
                        SAPParametersUtils.retrieveSAPParams(elem, connection, param, getSapFunctionLabel());
                    }
                    if ("GATEWAYSERVICE".equals(paramName) || "PROGRAMID".equals(paramName) || "FORMAT_XML".equals(paramName) || "FILE_IDOC_XML".equals(paramName) || "FORMAT_HTML".equals(paramName) || "FILE_IDOC_HTML".equals(paramName)) {
                        SAPParametersUtils.getSAPIDocParams(elem, connection, param, getSapIDocLabel());
                    }
                }
                if (param.isRepositoryValueUsed()) {
                    if (("GENERATION_MODE").equals(param.getName())) {
                        param.setReadOnly(true);
                    } else {
                        param.setReadOnly(false);
                    }
                }
            }
        }
        // (bug 5198)
        IElementParameter parentParameter = propertyParam.getParentParameter();
        if (parentParameter != null) {
            IElementParameter param = parentParameter.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            if (param != null && propertyParam == param) {
                // avoid to process twice.
                ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) param.getValue());
                if (connItem != null) {
                    if (elem instanceof Node) {
                        ConnectionContextHelper.addContextForNodeParameter((Node) elem, connItem, ignoreContextMode);
                    } else if (elem instanceof Process) {
                        ConnectionContextHelper.addContextForProcessParameter((Process) elem, connItem, param.getCategory(), ignoreContextMode);
                    }
                }
            }
        }
    }
    toUpdate = false;
    // change AS400 value
    for (IElementParameter curParam : elem.getElementParameters()) {
        if (curParam.getFieldType().equals(EParameterFieldType.AS400_CHECK)) {
            setOtherProperties();
        }
        // change the HL7 Version
        if (connection instanceof HL7Connection) {
            if (curParam.getName().equals("HL7_VER")) {
                String hl7VersionString = connection.getVersion();
                if (hl7VersionString != null) {
                    hl7VersionString = hl7VersionString.replace(".", "");
                    curParam.setValue(hl7VersionString);
                }
            }
        }
        setDefaultValues(curParam, elem);
    }
    if (elem instanceof Node) {
        // Xstream Cdc Type Mode
        boolean isXstreamCdcTypeMode = false;
        if (connection != null && connection instanceof DatabaseConnection) {
            String cdcTypeMode = ((DatabaseConnection) connection).getCdcTypeMode();
            if (CDCTypeMode.XSTREAM_MODE == CDCTypeMode.indexOf(cdcTypeMode)) {
                isXstreamCdcTypeMode = true;
            }
        }
        if (isXstreamCdcTypeMode && ((Node) elem).getComponent().getName().equals("tOracleCDC")) {
            //$NON-NLS-1$
            IMetadataTable table = ((Node) elem).getMetadataList().get(0);
            IElementParameter schemaParam = elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
            schemaParam.setValueToDefault(elem.getElementParameters());
            table.setListColumns((((IMetadataTable) schemaParam.getValue()).clone(true)).getListColumns());
        }
        ((Process) ((Node) elem).getProcess()).checkProcess();
        // Added TDQ-11688 show regex when "built-in"
        ITDQPatternService service = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
            service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
        }
        if (service != null && service.isSinglePatternNode(elem)) {
            IElementParameter regexParameter = ((Node) elem).getElementParameter("PATTERN_REGEX");
            if (regexParameter != null) {
                regexParameter.setShow(EmfComponent.BUILTIN.equals(this.value));
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) 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) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList) ITDQPatternService(org.talend.core.ITDQPatternService) IProcess(org.talend.core.model.process.IProcess) WSDLSchemaConnection(org.talend.core.model.metadata.builder.connection.WSDLSchemaConnection) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) FTPConnection(org.talend.core.model.metadata.builder.connection.FTPConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) IJsonFileService(org.talend.core.service.IJsonFileService) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Map(java.util.Map) HashMap(java.util.HashMap) HL7Connection(org.talend.core.model.metadata.builder.connection.HL7Connection)

Example 2 with IGenericWizardService

use of org.talend.core.runtime.services.IGenericWizardService in project tdi-studio-se by Talend.

the class AbstractSchemaController method createComboCommand.

@Override
protected Command createComboCommand(CCombo combo) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            if (schemaSelected == null) {
                //$NON-NLS-1$
                schemaSelected = "";
            }
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    Set<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = null;
                    IGenericWizardService wizardService = null;
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                    }
                    if (wizardService != null && wizardService.isGenericItem(item)) {
                        tables = new HashSet<>(wizardService.getMetadataTables(connection));
                    } else {
                        tables = ConnectionHelper.getTables(connection);
                    }
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) List(java.util.List) ArrayList(java.util.ArrayList) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 3 with IGenericWizardService

use of org.talend.core.runtime.services.IGenericWizardService in project tdi-studio-se by Talend.

the class RepositoryChangeMetadataCommand method execute.

@Override
public void execute() {
    node.setPropertyValue(propName, newPropValue);
    String mainSchemaParamName = DesignerUtilities.getMainSchemaParameterName(node);
    if (mainSchemaParamName.equals(propName)) {
        IElementParameter elementParameter = node.getElementParameter(propName);
        if (elementParameter != null) {
            IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
            if (schemaTypeParam != null) {
                if (newPropValue != null && !"".equals(newPropValue)) {
                    //$NON-NLS-1$
                    schemaTypeParam.setValue(EmfComponent.REPOSITORY);
                } else {
                    schemaTypeParam.setValue(EmfComponent.BUILTIN);
                }
            }
        }
    }
    if (node.isExternalNode() && !node.isELTComponent()) {
        for (IElementParameter parameter : node.getElementParameters()) {
            if (parameter.getFieldType() == EParameterFieldType.TABLE) {
                if (!node.getMetadataList().isEmpty() && !node.getMetadataList().get(0).sameMetadataAs(newOutputMetadata)) {
                    parameter.setValue(new ArrayList<Map<String, Object>>());
                }
            }
        }
    }
    // ELT Input/output component need add the schema conetxt in Context Mode
    if (node.isELTComponent()) {
        //$NON-NLS-1$
        IElementParameter schemaParam = node.getElementParameter("ELT_SCHEMA_NAME");
        if (schemaParam != null && schemaParam.getValue() != null && newPropValue != null && connection != null && connection.isContextMode() && ContextParameterUtils.isContainContextParam(schemaParam.getValue().toString())) {
            ConnectionItem connectionItem = MetadataToolHelper.getConnectionItemFromRepository(newPropValue.toString());
            ConnectionContextHelper.addContextForNodeParameter(node, connectionItem, false);
        }
    }
    // IElementParameter schemaTypeParameter =
    // node.getElementParameter(propName).getParentParameter().getChildParameters().get(
    // EParameterName.SCHEMA_TYPE.getName());
    // IElementParameter repositorySchemaTypeParameter = node.getElementParameter(propName).getParentParameter()
    // .getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
    // String schemaType = (String) schemaTypeParameter.getValue();
    // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
    // if (schemaType != null && schemaType.equals(EmfComponent.REPOSITORY)) {
    // repositorySchemaTypeParameter.setShow(true);
    // if (newRepositoryIdValue != null) {
    // oldRepositoryIdValue = (String) repositorySchemaTypeParameter.getValue();
    // repositorySchemaTypeParameter.setValue(newRepositoryIdValue);
    // }
    // } else {
    // repositorySchemaTypeParameter.setShow(false);
    // }
    // Xstream Cdc Type Mode
    boolean isXstreamCdcTypeMode = false;
    if (connection != null && connection instanceof DatabaseConnection) {
        String cdcTypeMode = ((DatabaseConnection) connection).getCdcTypeMode();
        if (CDCTypeMode.XSTREAM_MODE == CDCTypeMode.indexOf(cdcTypeMode)) {
            isXstreamCdcTypeMode = true;
        }
    }
    node.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName()).setValue(true);
    String componentName = node.getComponent().getName();
    if (newOutputMetadata != null) {
        Map<String, String> addMap = newOutputMetadata.getAdditionalProperties();
        if (addMap.get(TaggedValueHelper.SYSTEMTABLENAME) != null && componentName.equals("tAS400CDC")) {
            //$NON-NLS-1$
            setDBTableFieldValue(node, addMap.get(TaggedValueHelper.SYSTEMTABLENAME), oldOutputMetadata.getTableName());
        } else if (isXstreamCdcTypeMode) {
            IElementParameter elementParameter = node.getElementParameter(propName);
            if (elementParameter != null) {
                if (oracleCdcComponent[0].equals(componentName) || oracleCdcComponent[1].equals(componentName)) {
                    IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
                    IElementParameter schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                    if (schemaTypeParam != null) {
                        schemaTypeParam.setValue(EmfComponent.BUILTIN);
                        if (schemaParam != null && schemaParam.getValue() != null && schemaParam.getValue() instanceof IMetadataTable) {
                            newOutputMetadata.setListColumns((((IMetadataTable) schemaParam.getValue()).clone(true)).getListColumns());
                        }
                        if (oracleCdcComponent[1].equals(componentName)) {
                            newOutputMetadata.setListColumns(new ArrayList<IMetadataColumn>());
                        }
                    }
                }
            }
            setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
        } else {
            setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
        }
        //$NON-NLS-1$
        IElementParameter parameter = node.getElementParameter("SAP_FUNCTION");
        if (parameter != null) {
            setSAPFunctionName(node, parameter.getValue() == null ? null : (String) parameter.getValue());
        }
        if (newPropValue instanceof String) {
            if (orginalTable != null && orginalTable instanceof SAPBWTable) {
                String innerIOType = ((SAPBWTable) orginalTable).getInnerIOType();
                String sourceSysName = ((SAPBWTable) orginalTable).getSourceSystemName();
                IElementParameter schemaTypeParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                IMetadataTable metadataTable = null;
                if (schemaTypeParam != null) {
                    metadataTable = node.getMetadataFromConnector(schemaTypeParam.getContext());
                }
                if (metadataTable != null) {
                    if (innerIOType != null) {
                        //$NON-NLS-1$
                        IElementParameter param = node.getElementParameter("INFO_OBJECT_TYPE");
                        if (param != null) {
                            param.setValue(innerIOType);
                            metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_INFOOBJECT_INNER_TYPE, innerIOType);
                        }
                    }
                    if (sourceSysName != null) {
                        //$NON-NLS-1$
                        IElementParameter param = node.getElementParameter("SOURCE_SYSTEM_NAME");
                        if (param != null) {
                            param.setValue(TalendTextUtils.addQuotes(sourceSysName));
                            metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_DATASOURCE_SOURCESYSNAME, sourceSysName);
                        }
                    }
                }
            }
        }
        setTableRelevantParameterValues();
        if (getConnection() != null) {
            // for salesforce
            IElementParameter param = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
            if (param != null && EmfComponent.REPOSITORY.equals(param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getValue())) {
                IElementParameter module = node.getElementParameter("module.moduleName");
                if (module != null) {
                    String repositoryValue = module.getRepositoryValue();
                    if (repositoryValue == null) {
                        List<ComponentProperties> componentProperties = null;
                        IGenericWizardService wizardService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                            wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                        }
                        if (wizardService != null && wizardService.isGenericConnection(getConnection())) {
                            componentProperties = wizardService.getAllComponentProperties(getConnection(), null);
                        }
                        repositoryValue = String.valueOf(RepositoryToComponentProperty.getGenericRepositoryValue(getConnection(), componentProperties, module.getName()));
                    }
                    if (repositoryValue != null) {
                        Object objectValue = RepositoryToComponentProperty.getValue(getConnection(), repositoryValue, newOutputMetadata, node.getComponent().getName());
                        if (objectValue != null) {
                            module.setValue(objectValue);
                        }
                    }
                }
            }
        }
    }
    super.setConnection(connection);
    super.execute();
    String propertyType = (String) node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
    if (propertyType != null) {
        if (propertyType.equals(EmfComponent.REPOSITORY)) {
            String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
            if (lastVersion == null) {
                return;
            }
            Item item = lastVersion.getProperty().getItem();
            if (item instanceof ConnectionItem) {
                List<? extends IElementParameter> elementParameters = new ArrayList(node.getElementParameters());
                for (IElementParameter param : elementParameters) {
                    if (param.getRepositoryValue() != null && !param.getRepositoryValue().equals("")) {
                        //$NON-NLS-1$
                        boolean isCustomSfConn = false;
                        if (item instanceof SalesforceSchemaConnectionItem) {
                            SalesforceSchemaConnection sfConn = (SalesforceSchemaConnection) ((SalesforceSchemaConnectionItem) item).getConnection();
                            isCustomSfConn = sfConn.isUseCustomModuleName();
                        }
                        if (//$NON-NLS-1$
                        param.getRepositoryValue().equals("TYPE") || (param.getRepositoryValue().equals("MODULENAME") && item instanceof SalesforceSchemaConnectionItem && !isCustomSfConn)) {
                            //$NON-NLS-1$
                            continue;
                        }
                        if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("XML_MAPPING")) {
                            //$NON-NLS-1$
                            List<Map<String, Object>> table = (List<Map<String, Object>>) node.getPropertyValue(param.getName());
                            IMetadataTable metaTable = node.getMetadataList().get(0);
                            RepositoryToComponentProperty.getTableXmlFileValue(((ConnectionItem) item).getConnection(), //$NON-NLS-1$
                            "XML_MAPPING", //$NON-NLS-1$
                            param, table, newOutputMetadata);
                            param.setRepositoryValueUsed(true);
                        } else {
                            if (connection != null && (xmlComponent[0].equals(componentName) || xmlComponent[1].equals(componentName) || xmlComponent[2].equals(componentName)) && connection instanceof XmlFileConnection && XmlUtil.isXSDFile(TalendQuoteUtils.removeQuotes(((XmlFileConnection) connection).getXmlFilePath())) && param.getRepositoryValue().equals("FILE_PATH")) {
                            // do nothing
                            } else {
                                Object value = RepositoryToComponentProperty.getValue(((ConnectionItem) item).getConnection(), param.getRepositoryValue(), newOutputMetadata);
                                if (value != null) {
                                    param.setValue(value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    node.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) ArrayList(java.util.ArrayList) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) Item(org.talend.core.model.properties.Item) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) List(java.util.List) SAPBWTable(org.talend.core.model.metadata.builder.connection.SAPBWTable) Map(java.util.Map)

Example 4 with IGenericWizardService

use of org.talend.core.runtime.services.IGenericWizardService in project tdi-studio-se by Talend.

the class ComponentSettingsView method createDynamicComposite.

/**
     * yzhang Comment method "createDynamicComposite".
     * 
     * @param parent
     * @param element
     * @param category
     */
private void createDynamicComposite(final Composite parent, Element element, EComponentCategory category) {
    // DynamicComposite dc = null;
    getParentMap().put(ComponentSettingsView.PARENT, parent);
    getCategoryMap().put(ComponentSettingsView.CATEGORY, category);
    if (element instanceof Node) {
        IComponent component = ((Node) element).getComponent();
        IGenericWizardService wizardService = null;
        boolean generic = false;
        if (EComponentType.GENERIC.equals(component.getComponentType())) {
            generic = true;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
            }
        }
        tabFactory.getTabbedPropertyComposite().setCompactViewVisible(false);
        if (category == EComponentCategory.BASIC) {
            // getElementMap().put(ComponentSettingsView.ELEMENT, element);
            createButtonListener();
            boolean isCompactView = true;
            if (ComponentSettingsView.TABLEVIEW.equals(getPreference().getString(TalendDesignerPrefConstants.VIEW_OPTIONS))) {
                isCompactView = false;
            }
            tabFactory.getTabbedPropertyComposite().setCompactViewVisible(true);
            tabFactory.getTabbedPropertyComposite().setCompactView(isCompactView);
            // Generic
            if (generic && wizardService != null) {
                Composite composite = wizardService.creatDynamicComposite(parent, element, EComponentCategory.BASIC, true);
                if (composite instanceof MultipleThreadDynamicComposite) {
                    dc = (MultipleThreadDynamicComposite) composite;
                }
            } else {
                dc = new MissingSettingsMultiThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, isCompactView);
            }
        } else if (category == EComponentCategory.DYNAMICS_SETTINGS) {
            dc = new AdvancedContextComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, element);
        } else if (category == EComponentCategory.SQL_PATTERN) {
            dc = new SQLPatternComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, element);
        } else if (category == EComponentCategory.ADVANCED) {
            dc = new MissingSettingsMultiThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, true);
            // Generic
            if (generic && wizardService != null) {
                Composite composite = wizardService.creatDynamicComposite(parent, element, EComponentCategory.ADVANCED, true);
                if (composite instanceof MultipleThreadDynamicComposite) {
                    dc = (MultipleThreadDynamicComposite) composite;
                }
            }
        } else {
            dc = new MultipleThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, true);
        }
    } else if (element instanceof Connection) {
        dc = new MainConnectionComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element);
    } else if (element instanceof Note) {
        if (category == EComponentCategory.BASIC) {
            if (parent.getLayout() instanceof FillLayout) {
                FillLayout layout = (FillLayout) parent.getLayout();
                layout.type = SWT.VERTICAL;
                layout.marginHeight = 0;
                layout.marginWidth = 0;
                layout.spacing = 0;
            }
            ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
            scrolled.setExpandHorizontal(true);
            scrolled.setExpandVertical(true);
            scrolled.setMinWidth(600);
            scrolled.setMinHeight(400);
            Composite composite = tabFactory.getWidgetFactory().createComposite(scrolled);
            scrolled.setContent(composite);
            composite.setLayout(new FormLayout());
            FormData d = new FormData();
            d.left = new FormAttachment(0, 0);
            d.right = new FormAttachment(100, 0);
            d.top = new FormAttachment(0, 0);
            d.bottom = new FormAttachment(100, 0);
            composite.setLayoutData(d);
            AbstractNotePropertyComposite c1 = new BasicNotePropertyComposite(composite, (Note) element, tabFactory);
            // AbstractNotePropertyComposite c2 = new TextNotePropertyComposite(composite, (Note) element,
            // tabFactory);
            // FormData data = new FormData();
            // data.top = new FormAttachment(c1.getComposite(), 20, SWT.DOWN);
            // data.left = new FormAttachment(0, 0);
            // data.right = new FormAttachment(100, 0);
            // c2.getComposite().setLayoutData(data);
            parent.layout();
        }
    } else if (element instanceof SubjobContainer) {
        if (category == EComponentCategory.BASIC) {
            dc = new SubjobBasicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, element);
        }
    } else {
        tabFactory.getTabbedPropertyComposite().setCompactViewVisible(false);
        dc = new MultipleThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, true);
    }
    if (parent.getChildren().length == 0) {
        if (parent.getLayout() instanceof FillLayout) {
            FillLayout layout = (FillLayout) parent.getLayout();
            layout.type = SWT.VERTICAL;
            layout.marginHeight = 0;
            layout.marginWidth = 0;
            layout.spacing = 0;
        }
        Composite composite = tabFactory.getWidgetFactory().createComposite(parent);
        composite.setLayout(new FormLayout());
        FormData d = new FormData();
        d.left = new FormAttachment(2, 0);
        d.right = new FormAttachment(100, 0);
        d.top = new FormAttachment(5, 0);
        d.bottom = new FormAttachment(100, 0);
        composite.setLayoutData(d);
        Label alertText = new Label(composite, SWT.NONE);
        //$NON-NLS-1$
        alertText.setText(Messages.getString("ComponentSettingsView.noAdvancedSetting"));
        alertText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
        parent.layout();
    }
    if (dc != null) {
        dc.refresh();
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) MainConnectionComposite(org.talend.designer.core.ui.editor.properties.connections.MainConnectionComposite) Composite(org.eclipse.swt.widgets.Composite) SubjobBasicComposite(org.talend.designer.core.ui.views.subjob.SubjobBasicComposite) AbstractNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.AbstractNotePropertyComposite) MissingSettingsMultiThreadDynamicComposite(org.talend.designer.core.ui.views.properties.composites.MissingSettingsMultiThreadDynamicComposite) BasicNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.BasicNotePropertyComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) AbstractNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.AbstractNotePropertyComposite) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) Label(org.eclipse.swt.widgets.Label) MissingSettingsMultiThreadDynamicComposite(org.talend.designer.core.ui.views.properties.composites.MissingSettingsMultiThreadDynamicComposite) FillLayout(org.eclipse.swt.layout.FillLayout) SubjobBasicComposite(org.talend.designer.core.ui.views.subjob.SubjobBasicComposite) BasicNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.BasicNotePropertyComposite) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) Note(org.talend.designer.core.ui.editor.notes.Note) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MainConnectionComposite(org.talend.designer.core.ui.editor.properties.connections.MainConnectionComposite) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 5 with IGenericWizardService

use of org.talend.core.runtime.services.IGenericWizardService in project tdi-studio-se by Talend.

the class Component method getRepositoryType.

@Override
public String getRepositoryType(Connection connection) {
    String propertiesStr = null;
    IGenericWizardService wizardService = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
    }
    if (wizardService != null) {
        propertiesStr = wizardService.getConnectionProperties(connection);
    }
    ComponentProperties properties = ComponentsUtils.getComponentPropertiesFromSerialized(propertiesStr, connection, false);
    if (properties != null) {
        ComponentWizardDefinition wizardDefinition = getWizardDefinition(properties);
        if (wizardDefinition != null) {
            return wizardDefinition.getName();
        }
    }
    return null;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition)

Aggregations

IGenericWizardService (org.talend.core.runtime.services.IGenericWizardService)8 ArrayList (java.util.ArrayList)6 List (java.util.List)4 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 INode (org.talend.core.model.process.INode)4 ConnectionItem (org.talend.core.model.properties.ConnectionItem)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 Map (java.util.Map)3 ComponentProperties (org.talend.components.api.properties.ComponentProperties)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)3 IConnection (org.talend.core.model.process.IConnection)3 Item (org.talend.core.model.properties.Item)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 HashMap (java.util.HashMap)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 SalesforceSchemaConnection (org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection)2 INodeConnector (org.talend.core.model.process.INodeConnector)2 SAPConnectionItem (org.talend.core.model.properties.SAPConnectionItem)2