Search in sources :

Example 16 with GenericElementParameter

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

the class GenericWizardService method creatDynamicComposite.

@Override
public Composite creatDynamicComposite(Composite composite, Element element, EComponentCategory sectionCategory, boolean isCompactView) {
    DynamicComposite dynamicComposite = null;
    if (element != null && element instanceof INode) {
        INode node = (INode) element;
        ComponentProperties props = null;
        if (node.getComponentProperties() == null) {
            props = ComponentsUtils.getComponentProperties(node.getComponent().getName());
        } else {
            props = node.getComponentProperties();
        }
        if (props != null) {
            Form form = props.getForm(EComponentCategory.ADVANCED.equals(sectionCategory) ? Form.ADVANCED : Form.MAIN);
            dynamicComposite = new DynamicComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, sectionCategory, element, isCompactView, composite.getBackground(), form);
            List<ElementParameter> elementParameters = (List<ElementParameter>) node.getElementParameters();
            for (ElementParameter parameter : elementParameters) {
                if (parameter instanceof GenericElementParameter) {
                    GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
                    genericElementParameter.callBeforePresent();
                    genericElementParameter.removePropertyChangeListener(dynamicComposite);
                    genericElementParameter.addPropertyChangeListener(dynamicComposite);
                }
            }
        }
    }
    return dynamicComposite;
}
Also used : INode(org.talend.core.model.process.INode) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) DynamicComposite(org.talend.repository.generic.ui.DynamicComposite) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with GenericElementParameter

use of org.talend.designer.core.generic.model.GenericElementParameter 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)

Example 18 with GenericElementParameter

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

the class ComponentsUtilsTest method testGetFormalPossibleValues.

@Test
public void testGetFormalPossibleValues() {
    ComponentService componentService = ComponentsUtils.getComponentService();
    //$NON-NLS-1$
    ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
    Form form = props.getForm(Form.MAIN);
    Element element = new FakeElement(form.getName());
    Widget testWidget = null;
    Property testProperty = null;
    Collection<Widget> widgets = form.getWidgets();
    Iterator<Widget> widgetsIterator = widgets.iterator();
    while (widgetsIterator.hasNext()) {
        Widget widget = widgetsIterator.next();
        NamedThing content = widget.getContent();
        if (content instanceof Property) {
            testWidget = widget;
            testProperty = (Property) content;
            break;
        }
    }
    assertNotNull(testWidget);
    assertNotNull(testProperty);
    // Test NamedThing type
    List<NamedThing> namedThings = new ArrayList<>();
    namedThings.add(new SimpleNamedThing("p1", "Test P1"));
    namedThings.add(new SimpleNamedThing("p2", "Test P2"));
    namedThings.add(new SimpleNamedThing("p3", "Test P3"));
    testProperty.setPossibleValues(namedThings);
    GenericElementParameter param = new GenericElementParameter(element, props, form, testWidget, componentService);
    param.setPossibleValues(testProperty.getPossibleValues());
    List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(param);
    assertEquals(3, possibleValues.size());
    namedThings.retainAll(possibleValues);
    assertEquals(3, namedThings.size());
    // Test Integer type which is not support yet
    List<Integer> ints = new ArrayList<>();
    ints.add(1);
    ints.add(2);
    ints.add(3);
    testProperty.setPossibleValues(ints);
    param = new GenericElementParameter(element, props, form, testWidget, componentService);
    param.setPossibleValues(testProperty.getPossibleValues());
    possibleValues = ComponentsUtils.getFormalPossibleValues(param);
    assertEquals(0, possibleValues.size());
    // Test StringProperty
    testWidget = null;
    StringProperty testStringProperty = null;
    widgetsIterator = widgets.iterator();
    while (widgetsIterator.hasNext()) {
        Widget widget = widgetsIterator.next();
        NamedThing content = widget.getContent();
        if (content instanceof StringProperty) {
            testWidget = widget;
            testStringProperty = (StringProperty) content;
            break;
        }
    }
    assertNotNull(testWidget);
    assertNotNull(testStringProperty);
    testStringProperty.setPossibleNamedThingValues(namedThings);
    param = new GenericElementParameter(element, props, form, testWidget, componentService);
    param.setPossibleValues(testStringProperty.getPossibleValues());
    possibleValues = ComponentsUtils.getFormalPossibleValues(param);
    assertEquals(3, possibleValues.size());
    List<String> pvNames = new ArrayList<>();
    for (NamedThing pv : possibleValues) {
        pvNames.add(pv.getName());
    }
    for (NamedThing nt : namedThings) {
        assertTrue(pvNames.contains(nt.getName()));
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) Element(org.talend.core.model.process.Element) FakeElement(org.talend.designer.core.model.FakeElement) Widget(org.talend.daikon.properties.presentation.Widget) ArrayList(java.util.ArrayList) StringProperty(org.talend.daikon.properties.property.StringProperty) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) FakeElement(org.talend.designer.core.model.FakeElement) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ComponentService(org.talend.components.api.service.ComponentService) StringProperty(org.talend.daikon.properties.property.StringProperty) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test)

Example 19 with GenericElementParameter

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

the class ComponentRefController method createComboCommand.

public Command createComboCommand(SelectionEvent event, GenericElementParameter gParam, ComponentReferenceProperties props) {
    Set<String> elementsName;
    Control ctrl;
    elementsName = hashCurControls.keySet();
    for (String name : elementsName) {
        Object o = hashCurControls.get(name);
        if (o instanceof Control) {
            ctrl = (Control) o;
            CCombo combo = (CCombo) event.getSource();
            Object data = ctrl.getData(PARAMETER_NAME);
            if (!(ctrl instanceof CCombo)) {
                continue;
            }
            boolean isDisposed = ((CCombo) ctrl).isDisposed() || combo.isDisposed();
            if (isDisposed) {
                continue;
            }
            if (data != null && data.equals(combo.getData(PARAMETER_NAME))) {
                String newValue = ((CCombo) ctrl).getText();
                String v = labelToValueMap.get(newValue);
                if (v != null) {
                    newValue = v;
                }
                if (!newValue.equals(elem.getPropertyValue(name))) {
                    //$NON-NLS-1$
                    String value = "";
                    List<? extends IElementParameter> params = elem.getElementParametersWithChildrens();
                    IElementParameter propertyParameter = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
                    boolean done = false;
                    for (int i = 0; i < params.size() && !done; i++) {
                        IElementParameter param = params.get(i);
                        if (param.getName().equals(name)) {
                            for (int j = 0; j < param.getListItemsValue().length; j++) {
                                if (((CCombo) ctrl).getText().equals(param.getListItemsDisplayName()[j])) {
                                    value = (String) param.getListItemsValue()[j];
                                    if (j == 0) {
                                        // The first item in the combo is
                                        // this component
                                        props.referenceType.setValue(ComponentReferenceProperties.ReferenceType.THIS_COMPONENT);
                                        props.componentInstanceId.setValue(null);
                                        props.setReference(null);
                                        propertyParameter.setShow(true);
                                    } else {
                                        props.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
                                        props.componentInstanceId.setValue(value);
                                        GenericElementParameter gParameter = (GenericElementParameter) param;
                                        if (gParameter != null && gParameter.getElement() != null && gParameter.getElement() instanceof Node) {
                                            Node node = (Node) gParameter.getElement();
                                            List<INode> refNodes = (List<INode>) node.getProcess().getNodesOfType(props.referenceDefinitionName.getStringValue());
                                            for (INode refNode : refNodes) {
                                                if (refNode.getUniqueName() != null && refNode.getUniqueName().equals(value)) {
                                                    props.setReference(refNode.getComponentProperties());
                                                }
                                            }
                                        }
                                        propertyParameter.setShow(false);
                                    }
                                    done = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (StringUtils.isBlank(value)) {
                        value = ((INode) elem).getUniqueName();
                    }
                    if (value.equals(elem.getPropertyValue(name))) {
                        // anything
                        return null;
                    }
                    return new PropertyChangeCommand(elem, name, value);
                }
            }
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) Point(org.eclipse.swt.graphics.Point) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with GenericElementParameter

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

the class ComponentRefController method getRefNodes.

private List<INode> getRefNodes(IElementParameter param, ComponentReferenceProperties props) {
    callBeforeActive(param);
    List<INode> refNodes = new ArrayList<>();
    if (param instanceof GenericElementParameter) {
        GenericElementParameter gParameter = (GenericElementParameter) param;
        if (gParameter != null && gParameter.getElement() != null && gParameter.getElement() instanceof Node) {
            Node node = (Node) gParameter.getElement();
            refNodes = (List<INode>) node.getProcess().getNodesOfType(props.referenceDefinitionName.getStringValue());
        }
    }
    return refNodes;
}
Also used : INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter)

Aggregations

GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)20 ArrayList (java.util.ArrayList)11 IElementParameter (org.talend.core.model.process.IElementParameter)9 INode (org.talend.core.model.process.INode)8 List (java.util.List)6 ComponentProperties (org.talend.components.api.properties.ComponentProperties)6 ElementParameter (org.talend.designer.core.model.components.ElementParameter)6 ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)5 NamedThing (org.talend.daikon.NamedThing)5 Form (org.talend.daikon.properties.presentation.Form)4 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 Schema (org.apache.avro.Schema)3 CCombo (org.eclipse.swt.custom.CCombo)3 Point (org.eclipse.swt.graphics.Point)3 INodeConnector (org.talend.core.model.process.INodeConnector)3 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)3 Widget (org.talend.daikon.properties.presentation.Widget)3 Property (org.talend.daikon.properties.property.Property)3 FakeElement (org.talend.designer.core.model.FakeElement)3