Search in sources :

Example 1 with ComponentReferenceProperties

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

the class ComponentRefController method refresh.

@Override
public void refresh(IElementParameter param, boolean check) {
    GenericElementParameter gParam = (GenericElementParameter) param;
    ComponentReferenceProperties props = (ComponentReferenceProperties) gParam.getWidget().getContent();
    String paramName = param.getName();
    CCombo combo = (CCombo) hashCurControls.get(paramName);
    if (combo == null || combo.isDisposed()) {
        return;
    }
    INode currentNode = (INode) elem;
    List<INode> refNodes = getRefNodes(param, props);
    List<String> itemsLabel = new ArrayList<>();
    List<String> itemsValue = new ArrayList<>();
    // First item is this component (see also createComboCommand)
    // FIXME - I18N for this message
    itemsLabel.add("Use this Component");
    itemsValue.add(currentNode.getUniqueName());
    String selectedValue;
    Object referenceType = props.referenceType.getValue();
    if (referenceType != null && referenceType.equals(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE)) {
        selectedValue = TalendTextUtils.removeQuotes(props.componentInstanceId.getStringValue());
    } else {
        selectedValue = currentNode.getUniqueName();
    }
    for (INode node : refNodes) {
        final String uniqueName = node.getUniqueName();
        if (uniqueName.equals(currentNode.getUniqueName())) {
            continue;
        }
        String displayName = (String) node.getElementParameter(EParameterName.LABEL.getName()).getValue();
        if (displayName == null) {
            //$NON-NLS-1$
            displayName = uniqueName + " - " + displayName;
        }
        if (displayName.indexOf("__UNIQUE_NAME__") != -1) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            displayName = displayName.replaceAll("__UNIQUE_NAME__", uniqueName);
        } else {
            //$NON-NLS-1$
            displayName = uniqueName + " - " + displayName;
        }
        itemsLabel.add(displayName);
        itemsValue.add(uniqueName);
        labelToValueMap.put(displayName, uniqueName);
    }
    param.setListItemsDisplayName(itemsLabel.toArray(new String[0]));
    param.setListItemsDisplayCodeName(itemsLabel.toArray(new String[0]));
    param.setListItemsValue(itemsValue.toArray(new String[0]));
    combo.setItems(itemsLabel.toArray(new String[0]));
    String iLabel = null;
    int selection = 0;
    for (int i = 0; i < itemsValue.size(); i++) {
        String iValue = itemsValue.get(i);
        if ((selectedValue == null && (((INode) elem).getUniqueName()).equals(iValue)) || (selectedValue != null && selectedValue.equals(iValue))) {
            iLabel = itemsLabel.get(i);
            break;
        }
        selection++;
    }
    if (StringUtils.isNotEmpty(iLabel)) {
        combo.setText(iLabel);
        combo.select(selection);
    }
}
Also used : INode(org.talend.core.model.process.INode) CCombo(org.eclipse.swt.custom.CCombo) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ArrayList(java.util.ArrayList) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Point(org.eclipse.swt.graphics.Point)

Example 2 with ComponentReferenceProperties

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

the class ComponentRefController method createControl.

@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
    DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, cbCtrl);
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    if (param.isRepositoryValueUsed()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
        //$NON-NLS-1$
        decoration.setDescription(Messages.getString("ComboController.valueFromRepository"));
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
    }
    Control cLayout = dField.getLayoutControl();
    CCombo combo = (CCombo) dField.getControl();
    FormData data;
    combo.setEditable(false);
    cLayout.setBackground(subComposite.getBackground());
    combo.setEnabled(!param.isReadOnly());
    GenericElementParameter gParam = (GenericElementParameter) param;
    ComponentReferenceProperties props = (ComponentReferenceProperties) gParam.getWidget().getContent();
    combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (!(event.getSource() instanceof CCombo)) {
                return;
            }
            Command cmd = createComboCommand(event, gParam, props);
            executeCommand(cmd);
        }
    });
    combo.setData(PARAMETER_NAME, param.getName());
    int nbLines = param.getNbLines();
    if (nbLines > 5) {
        combo.setVisibleItemCount(nbLines);
    }
    if (elem instanceof Node) {
        combo.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, Messages.getString("ComponentRefController.connectionLabel"));
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(Messages.getString("ComponentRefController.connectionLabel"));
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    // **********************
    hashCurControls.put(param.getName(), combo);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return cLayout;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GC(org.eclipse.swt.graphics.GC) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 3 with ComponentReferenceProperties

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

the class DynamicComposite method isShouldDisParameter.

@Override
protected boolean isShouldDisParameter(IElementParameter curParam) {
    if (EParameterFieldType.PROPERTY_TYPE.equals(curParam.getFieldType())) {
        IElementParameter compRefParameter = elem.getElementParameterFromField(EParameterFieldType.COMPONENT_REFERENCE);
        if (compRefParameter != null) {
            GenericElementParameter gParam = (GenericElementParameter) compRefParameter;
            ComponentReferenceProperties props = (ComponentReferenceProperties) gParam.getWidget().getContent();
            return props.getReference() == null;
        }
    }
    return true;
}
Also used : GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties)

Example 4 with ComponentReferenceProperties

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

the class NewComponentFrameworkMigrationTask method execute.

@Override
public ExecutionResult execute(final Item item) {
    final ProcessType processType = getProcessType(item);
    ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
    Properties props = getPropertiesFromFile();
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType nodeType) {
            if (nodeType == null || props == null) {
                return;
            }
            boolean modified = false;
            Map<String, String> schemaParamMap = new HashMap<>();
            String currComponentName = nodeType.getComponentName();
            String newComponentName = props.getProperty(currComponentName);
            nodeType.setComponentName(newComponentName);
            IComponent component = ComponentsFactoryProvider.getInstance().get(newComponentName, category.getName());
            ComponentProperties compProperties = ComponentsUtils.getComponentProperties(newComponentName);
            FakeNode fNode = new FakeNode(component);
            for (IElementParameter param : fNode.getElementParameters()) {
                if (param instanceof GenericElementParameter) {
                    String paramName = param.getName();
                    NamedThing currNamedThing = ComponentsUtils.getGenericSchemaElement(compProperties, paramName);
                    String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
                    if (oldParamName != null && !(oldParamName = oldParamName.trim()).isEmpty()) {
                        if (currNamedThing instanceof Property && (GenericTypeUtils.isSchemaType((Property<?>) currNamedThing))) {
                            schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
                        }
                        ElementParameterType paramType = getParameterType(nodeType, oldParamName);
                        if (paramType != null) {
                            if (currNamedThing instanceof ComponentReferenceProperties) {
                                ComponentReferenceProperties refProps = (ComponentReferenceProperties) currNamedThing;
                                refProps.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
                                refProps.componentInstanceId.setStoredValue(ParameterUtilTool.convertParameterValue(paramType));
                                refProps.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
                            } else {
                                processMappedElementParameter(props, nodeType, (GenericElementParameter) param, paramType, currNamedThing);
                            }
                            ParameterUtilTool.removeParameterType(nodeType, paramType);
                            modified = true;
                        }
                        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                            //$NON-NLS-1$
                            String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
                            //$NON-NLS-1$
                            String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                            paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
                            if (paramType != null) {
                                paramType.setName(param.getName() + schemaTypeName);
                            }
                            paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
                            if (paramType != null) {
                                paramType.setName(param.getName() + repSchemaTypeName);
                            }
                        }
                    } else {
                        processUnmappedElementParameter(props, nodeType, (GenericElementParameter) param, currNamedThing);
                    }
                } else {
                    if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                        String paramName = param.getName();
                        schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
                        String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
                        //$NON-NLS-1$
                        String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
                        //$NON-NLS-1$
                        String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                        ElementParameterType paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
                        if (paramType != null) {
                            paramType.setName(param.getName() + schemaTypeName);
                        }
                        paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
                        if (paramType != null) {
                            paramType.setName(param.getName() + repSchemaTypeName);
                        }
                    }
                }
            }
            // Migrate schemas
            Map<String, MetadataType> metadatasMap = new HashMap<>();
            EList<MetadataType> metadatas = nodeType.getMetadata();
            for (MetadataType metadataType : metadatas) {
                metadatasMap.put(metadataType.getConnector(), metadataType);
            }
            Iterator<Entry<String, String>> schemaParamIter = schemaParamMap.entrySet().iterator();
            //$NON-NLS-1$
            String uniqueName = ParameterUtilTool.getParameterValue(nodeType, "UNIQUE_NAME");
            while (schemaParamIter.hasNext()) {
                Entry<String, String> schemaParamEntry = schemaParamIter.next();
                String newParamName = schemaParamEntry.getKey();
                String connectorMapping = schemaParamEntry.getValue();
                //$NON-NLS-1$
                String oldConnector = connectorMapping.split("->")[0];
                //$NON-NLS-1$
                String newConnector = connectorMapping.split("->")[1];
                MetadataType metadataType = metadatasMap.get(oldConnector);
                if (metadataType != null) {
                    metadataType.setConnector(newConnector);
                    MetadataEmfFactory factory = new MetadataEmfFactory();
                    factory.setMetadataType(metadataType);
                    IMetadataTable metadataTable = factory.getMetadataTable();
                    Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
                    compProperties.setValue(newParamName, schema);
                }
                if (!oldConnector.equals(newConnector)) {
                    // if connector was changed, we should update the connections
                    for (Object connectionObj : processType.getConnection()) {
                        if (connectionObj instanceof ConnectionType) {
                            ConnectionType connectionType = (ConnectionType) connectionObj;
                            if (connectionType.getSource().equals(uniqueName) && connectionType.getConnectorName().equals(oldConnector)) {
                                connectionType.setConnectorName(newConnector);
                            }
                        }
                    }
                }
            }
            for (Object connectionObj : processType.getConnection()) {
                ConnectionType connection = (ConnectionType) connectionObj;
                if (connection.getSource() != null && connection.getSource().equals(uniqueName)) {
                    if (EConnectionType.FLOW_MAIN.getName().equals(connection.getConnectorName())) {
                        connection.setConnectorName(Connector.MAIN_NAME);
                    }
                }
            }
            if (modified) {
                String serializedProperties = compProperties.toSerialized();
                if (serializedProperties != null) {
                    ElementParameterType pType = //$NON-NLS-1$
                    ParameterUtilTool.createParameterType(//$NON-NLS-1$
                    null, //$NON-NLS-1$
                    "PROPERTIES", serializedProperties);
                    nodeType.getElementParameter().add(pType);
                }
            }
        }
    };
    if (processType != null) {
        boolean modified = false;
        for (Object obj : processType.getNode()) {
            if (obj != null && obj instanceof NodeType) {
                String componentName = ((NodeType) obj).getComponentName();
                String newComponentName = props.getProperty(componentName);
                if (newComponentName == null) {
                    continue;
                }
                IComponentFilter filter = new NameComponentFilter(componentName);
                modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(conversion)) || modified;
            }
        }
        if (modified) {
            try {
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : MetadataEmfFactory(org.talend.designer.core.model.metadata.MetadataEmfFactory) ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Schema(org.apache.avro.Schema) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) ComponentCategory(org.talend.core.model.components.ComponentCategory) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) Entry(java.util.Map.Entry) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) Property(org.talend.daikon.properties.property.Property) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) NamedThing(org.talend.daikon.NamedThing) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 5 with ComponentReferenceProperties

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

the class Component method processCodegenPropInfos.

protected void processCodegenPropInfos(List<CodegenPropInfo> propList, Properties props, String fieldString) {
    for (NamedThing prop : props.getProperties()) {
        if (prop instanceof Properties) {
            if (prop instanceof ComponentReferenceProperties) {
                ComponentReferenceProperties crp = (ComponentReferenceProperties) prop;
                crp.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
                crp.referenceDefinitionName.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
            }
            CodegenPropInfo childPropInfo = new CodegenPropInfo();
            if (fieldString.equals("")) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                childPropInfo.fieldName = "." + prop.getName();
            } else {
                //$NON-NLS-1$
                childPropInfo.fieldName = fieldString + "." + prop.getName();
            }
            childPropInfo.className = prop.getClass().getName();
            childPropInfo.props = (Properties) prop;
            propList.add(childPropInfo);
            processCodegenPropInfos(propList, childPropInfo.props, childPropInfo.fieldName);
        }
    }
}
Also used : NamedThing(org.talend.daikon.NamedThing) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Properties(org.talend.daikon.properties.Properties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties)

Aggregations

ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)7 ComponentProperties (org.talend.components.api.properties.ComponentProperties)4 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)4 Properties (org.talend.daikon.properties.Properties)3 CCombo (org.eclipse.swt.custom.CCombo)2 Point (org.eclipse.swt.graphics.Point)2 Test (org.junit.Test)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 INode (org.talend.core.model.process.INode)2 NamedThing (org.talend.daikon.NamedThing)2 CodegenPropInfo (org.talend.designer.core.generic.model.Component.CodegenPropInfo)2 TestProperties (org.talend.designer.core.generic.utils.TestProperties)2 TestReferencedProperties (org.talend.designer.core.generic.utils.TestReferencedProperties)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 Schema (org.apache.avro.Schema)1 Command (org.eclipse.gef.commands.Command)1 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)1