use of org.talend.sdk.component.form.internal.converter.impl.widget.FieldSetWidgetConverter in project component-runtime by Talend.
the class UiSchemaConverter method convert.
@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
return cs.thenCompose(context -> {
final String type = context.getProperty().getType().toLowerCase(Locale.ROOT);
switch(type) {
case "object":
final Map<String, String> gridLayouts = context.getProperty().getMetadata().entrySet().stream().filter(e -> e.getKey().startsWith("ui::gridlayout::") && e.getKey().endsWith("::value")).collect(toMap(e -> e.getKey().substring("ui::gridlayout::".length(), e.getKey().length() - "::value".length()), Map.Entry::getValue, (a, b) -> {
throw new IllegalArgumentException("Can't merge " + a + " and " + b);
}, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)));
if (!gridLayouts.isEmpty()) {
return new GridLayoutWidgetConverter(schemas, properties, actions, client, family, gridLayoutFilter != null && gridLayouts.containsKey(gridLayoutFilter) ? singletonMap(gridLayoutFilter, gridLayouts.get(gridLayoutFilter)) : gridLayouts).convert(CompletableFuture.completedFuture(context));
}
return new FieldSetWidgetConverter(schemas, properties, actions, client, family).convert(CompletableFuture.completedFuture(context));
case "boolean":
includedProperties.add(context.getProperty());
return new ToggleWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
case "enum":
includedProperties.add(context.getProperty());
return new DataListWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
case "number":
includedProperties.add(context.getProperty());
return new NumberWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
case "array":
includedProperties.add(context.getProperty());
final String nestedPrefix = context.getProperty().getPath() + "[].";
final int from = nestedPrefix.length();
final Collection<SimplePropertyDefinition> nested = properties.stream().filter(prop -> prop.getPath().startsWith(nestedPrefix) && prop.getPath().indexOf('.', from) < 0).collect(toList());
if (!nested.isEmpty()) {
return new ObjectArrayWidgetConverter(schemas, properties, actions, nested, family, client, gridLayoutFilter).convert(CompletableFuture.completedFuture(context));
}
return new MultiSelectTagWidgetConverter(schemas, properties, actions, client, family).convert(CompletableFuture.completedFuture(context));
case "string":
default:
if (context.getProperty().getPath().endsWith("[]")) {
return CompletableFuture.completedFuture(context);
}
includedProperties.add(context.getProperty());
if ("true".equalsIgnoreCase(context.getProperty().getMetadata().get("ui::credential"))) {
return new CredentialWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
} else if (context.getProperty().getMetadata().containsKey("ui::code::value")) {
return new CodeWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
} else if (context.getProperty().getMetadata() != null && context.getProperty().getMetadata().containsKey("action::dynamic_values")) {
return new MultiSelectTagWidgetConverter(schemas, properties, actions, client, family).convert(CompletableFuture.completedFuture(context));
} else if (context.getProperty().getMetadata().containsKey("ui::textarea") && Boolean.valueOf(context.getProperty().getMetadata().get("ui::textarea"))) {
return new TextAreaWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
}
return new TextWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
}
});
}
Aggregations