Search in sources :

Example 1 with ModularList

use of com.eden.orchid.api.theme.components.ModularList in project Orchid by JavaEden.

the class ModularListOptionExtractor method getDefaultValue.

@Override
public ModularList getDefaultValue(Field field) {
    OrchidContext context = contextProvider.get();
    ModularList modularList = (ModularList) context.resolve(field.getType());
    modularList.initialize(context, new ArrayList<>());
    return modularList;
}
Also used : ModularList(com.eden.orchid.api.theme.components.ModularList) OrchidContext(com.eden.orchid.api.OrchidContext)

Example 2 with ModularList

use of com.eden.orchid.api.theme.components.ModularList in project Orchid by JavaEden.

the class ModularListOptionExtractor method getOption.

@Override
public ModularList getOption(Field field, Object sourceObject, String key) {
    OrchidContext context = contextProvider.get();
    final String typeKey;
    final String valueKey;
    if (field.isAnnotationPresent(ImpliedKey.class)) {
        ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
        typeKey = impliedKey.typeKey();
        valueKey = impliedKey.valueKey();
    } else {
        typeKey = null;
        valueKey = null;
    }
    Iterable iterable = iterableConverter.convert(field.getType(), sourceObject, typeKey, valueKey).second;
    List<Map<String, Object>> jsonArray = new ArrayList<>();
    for (Object o : iterable) {
        Map<String, Object> map = (Map<String, Object>) mapConverter.convert(field.getType(), o).second;
        jsonArray.add(map);
    }
    if (jsonArray.size() > 0) {
        ModularList modularList = (ModularList) contextProvider.get().resolve(field.getType());
        modularList.initialize(context, jsonArray);
        return modularList;
    }
    return null;
}
Also used : ModularList(com.eden.orchid.api.theme.components.ModularList) OrchidContext(com.eden.orchid.api.OrchidContext) ImpliedKey(com.eden.orchid.api.options.annotations.ImpliedKey) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

OrchidContext (com.eden.orchid.api.OrchidContext)2 ModularList (com.eden.orchid.api.theme.components.ModularList)2 ImpliedKey (com.eden.orchid.api.options.annotations.ImpliedKey)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1