Search in sources :

Example 1 with ComponentContextPropertyValueEvaluator

use of org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator in project tdi-studio-se by Talend.

the class Component method addPropertyParameters.

private void addPropertyParameters(final List<ElementParameter> listParam, final INode node, String formName, EComponentCategory category) {
    ComponentProperties props = node.getComponentProperties();
    Form form = props.getForm(formName);
    List<ElementParameter> parameters = ComponentsUtils.getParametersFromForm(node, this.isInitializing(), category, props, form);
    props.setValueEvaluator(new ComponentContextPropertyValueEvaluator(node));
    ComponentService componentService = ComponentsUtils.getComponentService();
    for (ElementParameter parameter : parameters) {
        if (parameter instanceof GenericElementParameter) {
            GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
            genericElementParameter.setComponentService(componentService);
        }
    }
    listParam.addAll(parameters);
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) ComponentContextPropertyValueEvaluator(org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator) ComponentService(org.talend.components.api.service.ComponentService)

Example 2 with ComponentContextPropertyValueEvaluator

use of org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator in project tdi-studio-se by Talend.

the class DynamicComposite method resetParameters.

public List<ElementParameter> resetParameters() {
    final List<ElementParameter> newParameters = new ArrayList<>();
    List<ElementParameter> currentParameters = (List<ElementParameter>) element.getElementParameters();
    List<ElementParameter> parameters = new ArrayList<>();
    ComponentService componentService = internalService.getComponentService();
    Connection theConnection = null;
    if (connectionItem != null) {
        theConnection = connectionItem.getConnection();
    }
    Properties properties = null;
    PropertyValueEvaluator evaluator = null;
    if (element instanceof FakeElement) {
        properties = form.getProperties();
        evaluator = new MetadataContextPropertyValueEvaluator(theConnection);
        currentParameters.clear();
    } else {
        properties = ((INode) element).getComponentProperties();
        evaluator = new ComponentContextPropertyValueEvaluator((INode) element);
    }
    if (properties instanceof ComponentProperties) {
        if (form != null) {
            properties.setValueEvaluator(evaluator);
            properties.refreshLayout(form);
        }
        // For context display.
        properties.setValueEvaluator(null);
        boolean isInitializing = false;
        if (element instanceof INode) {
            INode node = (INode) element;
            IComponent component = node.getComponent();
            if (component instanceof AbstractBasicComponent) {
                isInitializing = ((AbstractBasicComponent) component).isInitializing();
            }
        }
        parameters = ComponentsUtils.getParametersFromForm(element, isInitializing, section, (ComponentProperties) properties, form);
        addUpdateParameterIfNotExist(parameters);
        properties.setValueEvaluator(evaluator);
    }
    for (ElementParameter parameter : parameters) {
        if (parameter instanceof GenericElementParameter) {
            GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
            genericElementParameter.setComponentService(componentService);
            genericElementParameter.setDrivedByForm(drivedByForm);
            genericElementParameter.callBeforePresent();
            genericElementParameter.removePropertyChangeListener(this);
            genericElementParameter.addPropertyChangeListener(this);
            if (wizardPropertyChangeListener != null && IGenericConstants.NAME_PROPERTY.equals(parameter.getName())) {
                genericElementParameter.addPropertyChangeListener(wizardPropertyChangeListener);
            }
            if (EParameterFieldType.SCHEMA_REFERENCE.equals(genericElementParameter.getFieldType())) {
                if (genericElementParameter.getChildParameters().size() == 0) {
                    IElementParameter schemaParameter = element.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE, section);
                    genericElementParameter.getChildParameters().putAll(schemaParameter.getChildParameters());
                }
            } else if (EParameterFieldType.NAME_SELECTION_AREA.equals(genericElementParameter.getFieldType()) && theConnection != null) {
                List<NamedThing> values = new ArrayList<>();
                List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(theConnection, SubContainer.class);
                List<String> tableLabels = new ArrayList<>();
                for (MetadataTable metaTable : metadataTables) {
                    tableLabels.add(metaTable.getLabel());
                }
                List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(genericElementParameter);
                for (NamedThing possibleValue : possibleValues) {
                    if (tableLabels.contains(possibleValue.getName())) {
                        values.add(possibleValue);
                    }
                }
                genericElementParameter.setValue(values);
            }
            if (properties != null && isRepository(element)) {
                String repositoryValue = genericElementParameter.getRepositoryValue();
                if (genericElementParameter.isShow(currentParameters) && (repositoryValue != null) && (!genericElementParameter.getName().equals(EParameterName.PROPERTY_TYPE.getName())) && genericElementParameter.getCategory() == section) {
                    org.talend.daikon.properties.property.Property property = properties.getValuedProperty(genericElementParameter.getName());
                    if (property != null && property.getTaggedValue(IGenericConstants.REPOSITORY_VALUE) != null) {
                        genericElementParameter.setRepositoryValueUsed(true);
                        genericElementParameter.setReadOnly(true);
                    }
                }
            }
        }
    }
    boolean added = false;
    for (ElementParameter currentParameter : currentParameters) {
        if (EParameterName.UPDATE_COMPONENTS.getName().equals(currentParameter.getName())) {
            currentParameter.setValue(true);
        }
        if (currentParameter.isSerialized() && currentParameter.getCategory().equals(section)) {
            if (!added) {
                newParameters.addAll(parameters);
                added = true;
            }
            continue;
        }
        newParameters.add(currentParameter);
    }
    if (element instanceof FakeElement) {
        newParameters.addAll(reverseParameters(parameters));
    }
    element.setElementParameters(newParameters);
    return newParameters;
}
Also used : INode(org.talend.core.model.process.INode) ComponentProperties(org.talend.components.api.properties.ComponentProperties) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) PropertyValueEvaluator(org.talend.daikon.properties.property.PropertyValueEvaluator) ComponentContextPropertyValueEvaluator(org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator) MetadataContextPropertyValueEvaluator(org.talend.metadata.managment.ui.wizard.context.MetadataContextPropertyValueEvaluator) IElementParameterEventProperties(org.talend.designer.core.generic.constants.IElementParameterEventProperties) IContextEventProperties(org.talend.designer.core.generic.constants.IContextEventProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Properties(org.talend.daikon.properties.Properties) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) ComponentService(org.talend.components.api.service.ComponentService) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataContextPropertyValueEvaluator(org.talend.metadata.managment.ui.wizard.context.MetadataContextPropertyValueEvaluator) NamedThing(org.talend.daikon.NamedThing) FakeElement(org.talend.designer.core.model.FakeElement) SubContainer(org.talend.repository.generic.model.genericMetadata.SubContainer) AbstractBasicComponent(org.talend.designer.core.model.components.AbstractBasicComponent) ComponentContextPropertyValueEvaluator(org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator)

Aggregations

ComponentProperties (org.talend.components.api.properties.ComponentProperties)2 ComponentService (org.talend.components.api.service.ComponentService)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 ComponentContextPropertyValueEvaluator (org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator)2 ElementParameter (org.talend.designer.core.model.components.ElementParameter)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)1 IComponent (org.talend.core.model.components.IComponent)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 INode (org.talend.core.model.process.INode)1 NamedThing (org.talend.daikon.NamedThing)1 Properties (org.talend.daikon.properties.Properties)1 Form (org.talend.daikon.properties.presentation.Form)1 PropertyValueEvaluator (org.talend.daikon.properties.property.PropertyValueEvaluator)1 IContextEventProperties (org.talend.designer.core.generic.constants.IContextEventProperties)1 IElementParameterEventProperties (org.talend.designer.core.generic.constants.IElementParameterEventProperties)1 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)1 FakeElement (org.talend.designer.core.model.FakeElement)1