Search in sources :

Example 1 with GridLayout

use of org.talend.sdk.component.api.configuration.ui.layout.GridLayout in project component-runtime by Talend.

the class UiParameterEnricher method toConfig.

private Map<String, String> toConfig(final Annotation annotation, final String prefix) {
    // fine
    if (GridLayout.class == annotation.annotationType()) {
        final GridLayout layout = GridLayout.class.cast(annotation);
        return Stream.of(layout.names()).flatMap(name -> Stream.of(annotation.annotationType().getMethods()).filter(m -> m.getDeclaringClass() == annotation.annotationType() && !"names".equals(m.getName())).collect(toMap(m -> prefix + name + "::" + m.getName(), m -> toString(annotation, m, invoke -> {
            if (invoke.getClass().isArray()) {
                final Class<?> component = invoke.getClass().getComponentType();
                if (!Annotation.class.isAssignableFrom(component)) {
                    return null;
                }
                final int length = Array.getLength(invoke);
                if (length == 0) {
                    return "";
                }
                final Collection<Method> mtds = Stream.of(component.getMethods()).filter(mtd -> mtd.getDeclaringClass() == component && "value".equals(mtd.getName())).collect(toList());
                final StringBuilder builder = new StringBuilder("");
                for (int i = 0; i < length; i++) {
                    final Object annot = Array.get(invoke, i);
                    mtds.forEach(p -> builder.append(toString(Annotation.class.cast(annot), p, o -> null)));
                    if (i + 1 < length) {
                        builder.append('|');
                    }
                }
                return builder.toString();
            }
            return null;
        }))).entrySet().stream()).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
    final Map<String, String> config = Stream.of(annotation.annotationType().getMethods()).filter(m -> m.getDeclaringClass() == annotation.annotationType()).collect(toMap(m -> prefix + m.getName(), m -> toString(annotation, m, invoke -> null)));
    return config.isEmpty() ? singletonMap(prefix.substring(0, prefix.length() - "::".length()), "true") : config;
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) ParameterExtensionEnricher(org.talend.sdk.component.spi.parameter.ParameterExtensionEnricher) GridLayouts(org.talend.sdk.component.api.configuration.ui.layout.GridLayouts) Array(java.lang.reflect.Array) Collection(java.util.Collection) Ui(org.talend.sdk.component.api.configuration.ui.meta.Ui) Function(java.util.function.Function) Collectors.joining(java.util.stream.Collectors.joining) InvocationTargetException(java.lang.reflect.InvocationTargetException) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) Type(java.lang.reflect.Type) Map(java.util.Map) Annotation(java.lang.annotation.Annotation) GridLayout(org.talend.sdk.component.api.configuration.ui.layout.GridLayout) Collections.singletonMap(java.util.Collections.singletonMap) ENGLISH(java.util.Locale.ENGLISH) Method(java.lang.reflect.Method) GridLayout(org.talend.sdk.component.api.configuration.ui.layout.GridLayout) Method(java.lang.reflect.Method) Collections.emptyMap(java.util.Collections.emptyMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Array (java.lang.reflect.Array)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 ENGLISH (java.util.Locale.ENGLISH)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Stream (java.util.stream.Stream)1 GridLayout (org.talend.sdk.component.api.configuration.ui.layout.GridLayout)1 GridLayouts (org.talend.sdk.component.api.configuration.ui.layout.GridLayouts)1 Ui (org.talend.sdk.component.api.configuration.ui.meta.Ui)1 ParameterExtensionEnricher (org.talend.sdk.component.spi.parameter.ParameterExtensionEnricher)1