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;
}
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;
}
Aggregations