Skip to content

Commit

Permalink
FORGE-2703: Fixed usage of CommandController to set values
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Nov 30, 2016
1 parent 39a1e0a commit 508d159
Showing 1 changed file with 3 additions and 22 deletions.
Expand Up @@ -310,34 +310,15 @@ public static String unshellifyName(String name) {
}

public static void populateController(Map<String, Object> requestedInputs, CommandController controller, ConverterFactory converterFactory) {
Map<String, InputComponent<?, ?>> inputs = controller.getInputs();
Set<String> inputKeys = new HashSet<>(inputs.keySet());
if (requestedInputs != null) {
Map<String, InputComponent<?, ?>> inputs = controller.getInputs();
Set<String> inputKeys = new HashSet<>(inputs.keySet());
inputKeys.retainAll(requestedInputs.keySet());
Set<Map.Entry<String, InputComponent<?, ?>>> entries = inputs.entrySet();
for (Map.Entry<String, InputComponent<?, ?>> entry : entries) {
String key = entry.getKey();
InputComponent<?, ?> component = entry.getValue();
Object value = requestedInputs.get(key);
String textValue = null;
if (value instanceof String || value instanceof Number || value instanceof Date) {
textValue = value.toString();
}
if (component != null && textValue != null) {
Converter<String, ?> valueConverter = component.getValueConverter();
if (valueConverter != null) {
value = valueConverter.convert(textValue);
} else {
Class<?> valueType = component.getValueType();
if (valueType.isEnum()) {
Class<? extends Enum> enumType = (Class<? extends Enum>) valueType;
value = Enum.valueOf(enumType, textValue);
}
}
InputComponents.setValueFor(converterFactory, component, value);
} else {
controller.setValueFor(key, value);
}
controller.setValueFor(key, Proxies.unwrap(value));
}
}
}
Expand Down

0 comments on commit 508d159

Please sign in to comment.