Search in sources :

Example 56 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class GenericConnectionUtil method synNamePropertyWithItem.

/**
     * Syncronize the value of <code>name</code> property between component properties and connection item.
     * 
     * @param item the item which name property belong to.
     * @return return true if property is updated, otherwise return false;
     */
public static boolean synNamePropertyWithItem(GenericConnectionItem item) {
    GenericConnection connection = (GenericConnection) item.getConnection();
    String compPropertiesStr = connection.getCompProperties();
    if (compPropertiesStr == null) {
        return false;
    }
    ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(compPropertiesStr, connection);
    if (componentProperties == null) {
        return false;
    }
    Property nameProperty = (Property) componentProperties.getProperty(IGenericConstants.NAME_PROPERTY);
    if (nameProperty == null) {
        return false;
    }
    Object namePropertyVal = nameProperty.getValue();
    String newName = item.getProperty().getLabel();
    if (newName != null && !newName.equals(namePropertyVal)) {
        nameProperty.setValue(newName);
        connection.setCompProperties(componentProperties.toSerialized());
        return true;
    }
    return false;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Property(org.talend.daikon.properties.property.Property)

Example 57 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class GenericContextUtil method revertPropertiesForContextMode.

public static void revertPropertiesForContextMode(Connection connection, ContextType contextType) {
    if (connection instanceof GenericConnection) {
        GenericConnection conn = (GenericConnection) connection;
        ComponentProperties componentProperties = getComponentProperties(conn);
        revertPropertiesValues(componentProperties, contextType);
        updateComponentProperties(conn, componentProperties);
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection)

Example 58 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class GenericContextUtil method setPropertiesForExistContextMode.

public static void setPropertiesForExistContextMode(Connection connection, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
    if (connection == null) {
        return;
    }
    if (connection instanceof GenericConnection) {
        GenericConnection genericConn = (GenericConnection) connection;
        ComponentProperties componentProperties = getComponentProperties(genericConn);
        ContextItem currentContext = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof GenericConnParamName) {
                String genericVariableName = null;
                GenericConnParamName genericParam = (GenericConnParamName) param;
                if (adaptMap != null && adaptMap.size() > 0) {
                    for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
                        currentContext = entry.getKey();
                        List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                        for (ConectionAdaptContextVariableModel model : modelList) {
                            if (model.getValue().equals(genericParam.getName())) {
                                genericVariableName = model.getName();
                                break;
                            }
                        }
                    }
                }
                if (genericVariableName != null) {
                    genericVariableName = getCorrectVariableName(currentContext, genericVariableName, genericParam);
                    matchContextForAttribues(componentProperties, genericParam, genericVariableName);
                }
            }
        }
        updateComponentProperties(genericConn, componentProperties);
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnParamName(org.talend.metadata.managment.ui.utils.GenericConnParamName) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) ArrayList(java.util.ArrayList) List(java.util.List) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) Map(java.util.Map)

Example 59 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class GenericContextUtil method createContextParameters.

public static List<IContextParameter> createContextParameters(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
    List<IContextParameter> varList = new ArrayList<>();
    if (connection instanceof GenericConnection) {
        GenericConnection conn = (GenericConnection) connection;
        if (conn == null || prefixName == null || paramSet == null || paramSet.isEmpty()) {
            return Collections.emptyList();
        }
        String paramPrefix = prefixName + ConnectionContextHelper.LINE;
        String paramName = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof GenericConnParamName) {
                GenericConnParamName connParamName = (GenericConnParamName) param;
                String name = connParamName.getName();
                ComponentProperties componentProperties = getComponentProperties((GenericConnection) connection);
                Property<?> property = componentProperties.getValuedProperty(name);
                paramName = paramPrefix + connParamName.getContextVar();
                JavaType type = JavaTypesManager.STRING;
                if (property.isFlag(Property.Flags.ENCRYPT)) {
                    type = JavaTypesManager.PASSWORD;
                }
                if (GenericTypeUtils.isIntegerType(property)) {
                    type = JavaTypesManager.INTEGER;
                }
                String value = property == null || property.getValue() == null ? null : StringEscapeUtils.escapeJava(String.valueOf(property.getValue()));
                ConnectionContextHelper.createParameters(varList, paramName, value, type);
            }
        }
    }
    return varList;
}
Also used : JavaType(org.talend.core.model.metadata.types.JavaType) ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnParamName(org.talend.metadata.managment.ui.utils.GenericConnParamName) ArrayList(java.util.ArrayList) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 60 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class DynamicComposite method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent event) {
    String propertyName = event.getPropertyName();
    if (IElementParameterEventProperties.EVENT_PROPERTY_VALUE_CHANGED.equals(propertyName)) {
        reset(true);
    } else if (IElementParameterEventProperties.EVENT_VALIDATE_RESULT_UPDATE.equals(propertyName)) {
        Object newValue = event.getNewValue();
        if (newValue instanceof ValidationResult) {
            updateValidationStatus((ValidationResult) newValue);
        }
    } else if (IElementParameterEventProperties.EVENT_SHOW_DIALOG.equals(propertyName)) {
        Object newValue = event.getNewValue();
        if (newValue instanceof Form) {
            GenericDialog genericDialog = new GenericDialog(getShell(), (Form) newValue);
            genericDialog.setConnectionItem(connectionItem);
            genericDialog.open();
        }
    } else if (IContextEventProperties.EVENT_PROPERTY_EXPORT_CONTEXT.equals(propertyName)) {
        resetComponentProperties();
    } else if (IContextEventProperties.EVENT_PROPERTY_REFRESH_UI.equals(propertyName)) {
        Object newValue = event.getNewValue();
        if (newValue instanceof ComponentProperties) {
            ComponentProperties newComponentProperties = (ComponentProperties) newValue;
            form.getProperties().copyValuesFrom(newComponentProperties);
            reset(true);
        }
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) ValidationResult(org.talend.daikon.properties.ValidationResult)

Aggregations

ComponentProperties (org.talend.components.api.properties.ComponentProperties)76 Test (org.junit.Test)22 Form (org.talend.daikon.properties.presentation.Form)17 Property (org.talend.daikon.properties.property.Property)17 ArrayList (java.util.ArrayList)16 NamedThing (org.talend.daikon.NamedThing)13 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)13 Properties (org.talend.daikon.properties.Properties)10 List (java.util.List)9 IElementParameter (org.talend.core.model.process.IElementParameter)9 INode (org.talend.core.model.process.INode)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Schema (org.apache.avro.Schema)7 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)7 ComponentService (org.talend.components.api.service.ComponentService)7 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)7 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)7 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)7 ElementParameter (org.talend.designer.core.model.components.ElementParameter)7