Search in sources :

Example 1 with ImpliedKey

use of com.eden.orchid.api.options.annotations.ImpliedKey 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 ImpliedKey

use of com.eden.orchid.api.options.annotations.ImpliedKey in project Orchid by JavaEden.

the class ModularTypeOptionExtractor method describeDefaultValue.

@Override
public String describeDefaultValue(Field field) {
    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;
    }
    return "Default " + field.getType().getSimpleName() + " of type '" + typeKey + "'";
}
Also used : ImpliedKey(com.eden.orchid.api.options.annotations.ImpliedKey)

Example 3 with ImpliedKey

use of com.eden.orchid.api.options.annotations.ImpliedKey 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)

Example 4 with ImpliedKey

use of com.eden.orchid.api.options.annotations.ImpliedKey in project Orchid by JavaEden.

the class MapOptionExtractor method getOption.

@Override
public Map getOption(Field field, Object sourceObject, String key) {
    final String typeKey;
    if (field.isAnnotationPresent(ImpliedKey.class)) {
        ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
        typeKey = impliedKey.typeKey();
    } else {
        typeKey = null;
    }
    return mapConverter.convert(field.getType(), sourceObject, typeKey).second;
}
Also used : ImpliedKey(com.eden.orchid.api.options.annotations.ImpliedKey)

Aggregations

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