public MethodArgumentPanel(String id, final Argument arg) {
super(id);
add(new Label("index", String.format("Argument #%d", arg.getIndex())));
Class<?> type = arg.getType();
if (type.isPrimitive() || type.isEnum() || hasStringOnlyConstructor(type)) {
Builder builder = AttributeDefinition.builder(new PassThroughStringLocalizer());
MethodUtil.addEnumValues(type, builder);
builder.id("value").name("value");
if (type.equals(boolean.class) || type.equals(Boolean.class)) {
builder.asBoolean();
}
AbstractField<?> field = AttributeEditorUtil.createEditorField("valueEditor", new IModel<String>() {
@Override
public void detach() {
// not required
}
@Override
public void setObject(String object) {
arg.setValue(object);
}
@Override
public String getObject() {
return arg.getValue() != null ? arg.getValue().toString() : null;
}
}, builder.build());
add(field);
} else {
Map<String, String> beanAttrs = new HashMap<String, String>();
arg.setValue(beanAttrs);
arg.setBean(true);