Search in sources :

Example 1 with ModularType

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

the class ModularTypeOptionExtractor method getOption.

@Override
public ModularType getOption(Field field, Object sourceObject, String key) {
    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;
    }
    Map<String, Object> data = mapConverter.convert(field.getType(), sourceObject, typeKey).second;
    ModularType t = null;
    Object actualType = data.get(typeKey);
    if (actualType != null) {
        t = createModularType(field, actualType.toString(), data);
        if (t == null) {
            Clog.e("Could not find modular type [{}] for {} {} in class {}, falling back to default [{}]", actualType, field.getType().getSimpleName(), field.getName(), field.getDeclaringClass().getSimpleName(), getDefaultType(field));
        }
    }
    actualType = data.get(null);
    if (actualType != null) {
        t = createModularType(field, actualType.toString(), data);
        if (t == null) {
            Clog.e("Could not find modular type [{}] for {} {} in class {}, falling back to default [{}]", actualType, field.getType().getSimpleName(), field.getName(), field.getDeclaringClass().getSimpleName(), getDefaultType(field));
        }
    }
    return t;
}
Also used : ImpliedKey(com.eden.orchid.api.options.annotations.ImpliedKey) ModularType(com.eden.orchid.api.theme.components.ModularType)

Example 2 with ModularType

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

the class ModularTypeOptionExtractor method createModularType.

private ModularType createModularType(Field field, String selectedTypeKey, Map<String, Object> data) {
    Set<? extends ModularType> itemTypes = (Set<? extends ModularType>) contextProvider.get().resolveSet(field.getType());
    for (ModularType itemType : itemTypes) {
        if (itemType.getType().equals(selectedTypeKey)) {
            ModularType type = contextProvider.get().resolve(itemType.getClass());
            type.extractOptions(contextProvider.get(), data);
            return type;
        }
    }
    return null;
}
Also used : Set(java.util.Set) ModularType(com.eden.orchid.api.theme.components.ModularType)

Aggregations

ModularType (com.eden.orchid.api.theme.components.ModularType)2 ImpliedKey (com.eden.orchid.api.options.annotations.ImpliedKey)1 Set (java.util.Set)1