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);
}
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations