use of org.talend.components.api.component.Connector in project tdi-studio-se by Talend.
the class Component method createConnectors.
@Override
public List<INodeConnector> createConnectors(INode parentNode) {
List<INodeConnector> listConnector = new ArrayList<>();
ComponentProperties componentProperties = ComponentsUtils.getComponentProperties(getName());
Set<? extends Connector> inputConnectors = componentProperties.getPossibleConnectors(false);
if (inputConnectors.isEmpty()) {
INodeConnector connector = null;
connector = addStandardType(listConnector, EConnectionType.FLOW_MAIN, parentNode);
connector.setMaxLinkInput(0);
connector.setMaxLinkOutput(0);
} else {
for (Connector connector : inputConnectors) {
addGenericType(listConnector, EConnectionType.FLOW_MAIN, connector.getName(), parentNode, componentProperties, false);
}
}
Set<? extends Connector> outputConnectors = componentProperties.getPossibleConnectors(true);
List<? extends Connector> sortedOutputConnectors = new ArrayList<>(outputConnectors);
sortedOutputConnectors.sort(new Comparator<Connector>() {
@Override
public int compare(Connector o1, Connector o2) {
if (Connector.MAIN_NAME.equals(o1.getName())) {
return -1;
}
if (Connector.MAIN_NAME.equals(o2.getName())) {
return 1;
}
return 0;
}
});
for (Connector connector : sortedOutputConnectors) {
EConnectionType type = EConnectionType.FLOW_MAIN;
if (Connector.REJECT_NAME.equals(connector.getName())) {
type = EConnectionType.REJECT;
}
addGenericType(listConnector, type, connector.getName(), parentNode, componentProperties, true);
}
addStandardType(listConnector, EConnectionType.RUN_IF, parentNode);
addStandardType(listConnector, EConnectionType.ON_COMPONENT_OK, parentNode);
addStandardType(listConnector, EConnectionType.ON_COMPONENT_ERROR, parentNode);
addStandardType(listConnector, EConnectionType.ON_SUBJOB_OK, parentNode);
addStandardType(listConnector, EConnectionType.ON_SUBJOB_ERROR, parentNode);
Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
createIterateConnectors(topologies, listConnector, parentNode);
for (int i = 0; i < EConnectionType.values().length; i++) {
EConnectionType currentType = EConnectionType.values()[i];
if ((currentType == EConnectionType.FLOW_REF) || (currentType == EConnectionType.FLOW_MERGE)) {
continue;
}
boolean exists = false;
for (INodeConnector curNodeConn : listConnector) {
if (curNodeConn.getDefaultConnectionType().equals(currentType)) {
exists = true;
if (currentType == EConnectionType.FLOW_MAIN) {
curNodeConn.addConnectionProperty(EConnectionType.FLOW_REF, EConnectionType.FLOW_REF.getRGB(), EConnectionType.FLOW_REF.getDefaultLineStyle());
curNodeConn.addConnectionProperty(EConnectionType.FLOW_MERGE, EConnectionType.FLOW_MERGE.getRGB(), EConnectionType.FLOW_MERGE.getDefaultLineStyle());
}
}
}
if (!exists) {
// will add by default all connectors not defined in
NodeConnector nodeConnector = new NodeConnector(parentNode);
nodeConnector.setDefaultConnectionType(currentType);
nodeConnector.setName(currentType.getName());
nodeConnector.setBaseSchema(currentType.getName());
nodeConnector.addConnectionProperty(currentType, currentType.getRGB(), currentType.getDefaultLineStyle());
nodeConnector.setLinkName(currentType.getDefaultLinkName());
nodeConnector.setMenuName(currentType.getDefaultMenuName());
if ((currentType == EConnectionType.PARALLELIZE) || (currentType == EConnectionType.SYNCHRONIZE)) {
nodeConnector.setMaxLinkInput(1);
} else {
nodeConnector.setMaxLinkInput(0);
}
nodeConnector.setMaxLinkOutput(0);
nodeConnector.setMinLinkInput(0);
nodeConnector.setMinLinkOutput(0);
listConnector.add(nodeConnector);
}
}
return listConnector;
}
use of org.talend.components.api.component.Connector in project tdi-studio-se by Talend.
the class ComponentsUtils method getParametersFromForm.
/**
* DOC ycbai Comment method "loadParametersFromForm".
* <p>
* Get element parameters of <code>element</code> from <code>form</code>.
*
* @param node optional, used if there is a component setting up the properties
* @param element
* @param category
* @param form
* @return parameters list
*/
private static List<ElementParameter> getParametersFromForm(IElement element, boolean isInitializing, EComponentCategory category, ComponentProperties rootProperty, Properties compProperties, String parentPropertiesPath, Form form, Widget parentWidget, AtomicInteger lastRowNum) {
List<ElementParameter> elementParameters = new ArrayList<>();
List<String> parameterNames = new ArrayList<>();
EComponentCategory compCategory = category;
if (compCategory == null) {
compCategory = EComponentCategory.BASIC;
}
AtomicInteger lastRN = lastRowNum;
if (lastRN == null) {
lastRN = new AtomicInteger();
}
if (form == null) {
return elementParameters;
}
Properties componentProperties = compProperties;
if (componentProperties == null) {
componentProperties = form.getProperties();
}
if (element instanceof INode) {
INode node = (INode) element;
// Set the properties only one time to get the top-level properties object
if (node.getComponentProperties() == null) {
node.setComponentProperties(rootProperty);
}
}
// Have to initialize for the messages
Collection<Widget> formWidgets = form.getWidgets();
for (Widget widget : formWidgets) {
NamedThing widgetProperty = widget.getContent();
String propertiesPath = getPropertiesPath(parentPropertiesPath, null);
if (widgetProperty instanceof Form) {
Form subForm = (Form) widgetProperty;
Properties subProperties = subForm.getProperties();
// Reset properties path
if (!isSameComponentProperties(componentProperties, widgetProperty)) {
propertiesPath = getPropertiesPath(parentPropertiesPath, subProperties.getName());
}
elementParameters.addAll(getParametersFromForm(element, isInitializing, compCategory, rootProperty, subProperties, propertiesPath, subForm, widget, lastRN));
continue;
}
GenericElementParameter param = new GenericElementParameter(element, rootProperty, form, widget, getComponentService());
String parameterName = propertiesPath.concat(param.getName());
param.setName(parameterName);
param.setCategory(compCategory);
param.setShow(parentWidget == null ? !widget.isHidden() : !parentWidget.isHidden() && !widget.isHidden());
int rowNum = 0;
if (widget.getOrder() != 1) {
rowNum = lastRN.get();
} else {
rowNum = widget.getRow();
if (parentWidget != null) {
rowNum += parentWidget.getRow();
}
rowNum = rowNum + lastRN.get();
}
param.setNumRow(rowNum);
lastRN.set(rowNum);
// handle form...
EParameterFieldType fieldType = getFieldType(widget, widgetProperty);
param.setFieldType(fieldType != null ? fieldType : EParameterFieldType.TEXT);
if (widgetProperty instanceof SchemaProperty) {
boolean found = false;
// set a default connector
param.setContext(EConnectionType.FLOW_MAIN.getName());
for (Connector connector : rootProperty.getPossibleConnectors(true)) {
if (!(((SchemaProperty) widgetProperty).getValue() instanceof Schema)) {
continue;
}
if (connector instanceof PropertyPathConnector) {
//$NON-NLS-1$
String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
if (parameterName.equals(linkedSchema)) {
found = true;
param.setContext(connector.getName());
IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
Schema schema = ((SchemaProperty) widgetProperty).getValue();
defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
param.getDefaultValues().add(defaultValue);
}
}
}
if (!found) {
// compatibility.
for (Connector connector : rootProperty.getPossibleConnectors(false)) {
if (!(((SchemaProperty) widgetProperty).getValue() instanceof Schema)) {
continue;
}
if (connector instanceof PropertyPathConnector) {
//$NON-NLS-1$
String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
if (parameterName.equals(linkedSchema)) {
if (GenericNodeConnector.INPUT_CONNECTOR.equals(connector.getName())) {
param.setContext(EConnectionType.FLOW_MAIN.getName());
} else {
param.setContext(connector.getName());
}
IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
Schema schema = ((SchemaProperty) widgetProperty).getValue();
defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
param.getDefaultValues().add(defaultValue);
}
}
}
}
}
if (widgetProperty instanceof PresentationItem) {
param.setValue(widgetProperty.getDisplayName());
} else if (widgetProperty instanceof Property) {
Property property = (Property) widgetProperty;
param.setRequired(property.isRequired());
param.setValue(getParameterValue(element, property, fieldType));
boolean isNameProperty = IGenericConstants.NAME_PROPERTY.equals(param.getParameterName());
if (EParameterFieldType.NAME_SELECTION_AREA.equals(fieldType) || EParameterFieldType.JSON_TABLE.equals(fieldType) || EParameterFieldType.CLOSED_LIST.equals(fieldType) || EParameterFieldType.CHECK.equals(fieldType) || isNameProperty) {
// Disable context support for those filed types and name parameter.
param.setSupportContext(false);
} else {
param.setSupportContext(isSupportContext(property));
}
property.setTaggedValue(IComponentConstants.SUPPORT_CONTEXT, param.isSupportContext());
Object cmTV = property.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE);
param.setReadOnly(Boolean.valueOf(String.valueOf(cmTV)));
boolean isDynamic = Boolean.valueOf(String.valueOf(property.getTaggedValue(IGenericConstants.IS_DYNAMIC)));
param.setContextMode(isDynamic);
List<?> values = property.getPossibleValues();
if (values != null || EParameterFieldType.CLOSED_LIST.equals(fieldType)) {
if (values == null) {
values = Collections.emptyList();
}
param.setPossibleValues(values);
List<String> possVals = new ArrayList<>();
List<String> possValsDisplay = new ArrayList<>();
for (Object obj : values) {
String value = null;
String valueDisplay = null;
if (obj instanceof NamedThing) {
NamedThing nal = (NamedThing) obj;
value = nal.getName();
valueDisplay = nal.getDisplayName();
} else {
value = String.valueOf(obj);
valueDisplay = String.valueOf(obj);
}
String pvDisplayName = property.getPossibleValuesDisplayName(obj);
if (StringUtils.isNotBlank(pvDisplayName) && !"null".equals(pvDisplayName)) {
//$NON-NLS-1$
valueDisplay = pvDisplayName;
}
possVals.add(value);
possValsDisplay.add(valueDisplay);
}
param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
param.setListItemsDisplayCodeName(possValsDisplay.toArray(new String[0]));
param.setListItemsValue(possVals.toArray(new String[0]));
}
} else if (fieldType != null && fieldType.equals(EParameterFieldType.TABLE) && widgetProperty instanceof Properties) {
Properties table = (Properties) widgetProperty;
Form mainForm = table.getForm(Form.MAIN);
param.setDisplayName(mainForm.getTitle());
//$NON-NLS-1$
List<ElementParameter> parameters = getParametersFromForm(new FakeElement("table"), mainForm);
// table is always empty by default
param.setSupportContext(false);
List<String> codeNames = new ArrayList<>();
List<String> possValsDisplay = new ArrayList<>();
for (ElementParameter curParam : parameters) {
curParam.setFilter(null);
curParam.setContext(null);
curParam.setShowIf(null);
curParam.setNotShowIf(null);
curParam.setReadOnlyIf(null);
curParam.setNotReadOnlyIf(null);
curParam.setNoContextAssist(false);
curParam.setRaw(false);
curParam.setReadOnly(false);
fillDefaultValsForListType(curParam);
codeNames.add(curParam.getName());
possValsDisplay.add(curParam.getDisplayName());
}
param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
param.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
param.setListItemsValue(parameters.toArray(new ElementParameter[0]));
String[] listItemsShowIf = new String[parameters.size()];
String[] listItemsNotShowIf = new String[parameters.size()];
param.setListItemsShowIf(listItemsShowIf);
param.setListItemsNotShowIf(listItemsNotShowIf);
param.setValue(GenericTableUtils.getTableValues(table, param));
param.setBasedOnSchema(Boolean.valueOf(String.valueOf(widget.getConfigurationValue(Widget.HIDE_TOOLBAR_WIDGET_CONF))));
}
if (!param.isReadOnly()) {
param.setReadOnly(widget.isReadonly() || element.isReadOnly());
}
// For issue TUP-16139
if (EParameterFieldType.COMPONENT_REFERENCE.equals(fieldType) && param.getNumRow() == 2 && EComponentCategory.BASIC.equals(compCategory)) {
param.setNumRow(1);
}
param.setSerialized(true);
param.setDynamicSettings(true);
// Avoid adding duplicate prameter.
if (!parameterNames.contains(parameterName)) {
elementParameters.add(param);
parameterNames.add(parameterName);
}
}
return elementParameters;
}
use of org.talend.components.api.component.Connector in project tdi-studio-se by Talend.
the class GenericElementParameter method updateSchema.
private void updateSchema() {
IElement element = this.getElement();
if (element instanceof Node) {
Node node = (Node) element;
List<INodeConnector> connectors = node.getConnectorsFromType(EConnectionType.FLOW_MAIN);
for (INodeConnector connector : connectors) {
if (connector instanceof GenericNodeConnector) {
Connector componentConnector = ((GenericNodeConnector) connector).getComponentConnector();
Schema schema = null;
schema = getRootProperties().getSchema(componentConnector, ((GenericNodeConnector) connector).isOutput());
IMetadataTable mainTable = node.getMetadataFromConnector(connector.getName());
if (schema != null && mainTable != null) {
MetadataTable metadataTable = MetadataToolAvroHelper.convertFromAvro(schema);
IMetadataTable newTable = MetadataToolHelper.convert(metadataTable);
if (!mainTable.sameMetadataAs(newTable) || !newTable.sameMetadataAs(mainTable)) {
mainTable.setListColumns(newTable.getListColumns());
List<IElementParameter> schemaParameters = node.getElementParametersFromField(EParameterFieldType.SCHEMA_REFERENCE);
updateSchemaParameters(schemaParameters, connector.getName(), schema);
if (this.askPropagate == null && node.getOutgoingConnections().size() != 0) {
boolean hasPropagation = false;
for (IConnection connection : node.getOutgoingConnections()) {
if (connector.getName().equals(connection.getConnectorName())) {
if (isSchemaPropagated(connection.getTarget())) {
hasPropagation = true;
break;
}
}
}
if (hasPropagation) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
askPropagate = ChangeMetadataCommand.askPropagate();
}
});
}
}
if (this.askPropagate != null && this.askPropagate) {
for (IConnection connection : node.getOutgoingConnections()) {
if (connector.getName().equals(connection.getConnectorName())) {
INode target = connection.getTarget();
if (!isSchemaPropagated(target)) {
continue;
}
ChangeMetadataCommand cmd = new ChangeMetadataCommand(target, null, null, newTable, null);
cmd.setPropagate(true);
IProcess process = node.getProcess();
if (process instanceof org.talend.designer.core.ui.editor.process.Process) {
CommandStack commandStack = ((org.talend.designer.core.ui.editor.process.Process) process).getCommandStack();
commandStack.execute(cmd);
}
}
}
}
}
}
}
}
this.askPropagate = null;
}
}
use of org.talend.components.api.component.Connector in project tdi-studio-se by Talend.
the class Component method setupConnector.
/**
* DOC nrousseau Comment method "setupConnector".
*
* @param node
* @param rootProperty
* @param paramName
* @param schemaProperty
* @param found
* @return
*/
private boolean setupConnector(final INode node, List<ElementParameter> listParam, String paramName, SchemaProperty schemaProperty, boolean isOutput) {
ComponentProperties rootProperty = node.getComponentProperties();
boolean found = false;
for (Connector connector : rootProperty.getPossibleConnectors(isOutput)) {
if (!(schemaProperty.getValue() instanceof Schema)) {
continue;
}
Schema schema = schemaProperty.getValue();
if (connector instanceof PropertyPathConnector) {
//$NON-NLS-1$
String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
if (paramName.equals(linkedSchema)) {
found = true;
ElementParameter param = new ElementParameter(node);
param.setName(paramName);
param.setFieldType(EParameterFieldType.SCHEMA_REFERENCE);
param.setShow(false);
if (!isOutput) {
param.setContext(EConnectionType.FLOW_MAIN.getName());
} else {
param.setContext(connector.getName());
}
param.setCategory(EComponentCategory.TECHNICAL);
IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
param.getDefaultValues().add(defaultValue);
listParam.add(param);
}
}
}
return found;
}
Aggregations