final boolean readOnly = templateMode ? false : schemaTO.isReadonly();
final AttributeSchemaType type = templateMode ? AttributeSchemaType.String : schemaTO.getType();
final FieldPanel panel;
switch (type) {
case Boolean:
panel = new AjaxCheckBoxPanel("panel", schemaTO.getName(), new Model<Boolean>());
panel.setRequired(required);
break;
case Date:
final String dataPattern = schemaTO.getConversionPattern() == null
? SyncopeConstants.DEFAULT_DATE_PATTERN
: schemaTO.getConversionPattern();
if (dataPattern.contains("H")) {
panel = new DateTimeFieldPanel("panel", schemaTO.getName(), new Model<Date>(), dataPattern);
if (required) {
panel.addRequiredLabel();
((DateTimeFieldPanel) panel).setFormValidator(form);
}
panel.setStyleSheet("ui-widget-content ui-corner-all");
} else {
panel = new DateTextFieldPanel("panel", schemaTO.getName(), new Model<Date>(), dataPattern);
if (required) {
panel.addRequiredLabel();
}
}
break;
case Enum:
panel = new AjaxDropDownChoicePanel<String>("panel", schemaTO.getName(), new Model<String>());
((AjaxDropDownChoicePanel<String>) panel).setChoices(getEnumeratedValues(schemaTO));
if (StringUtils.isNotBlank(schemaTO.getEnumerationKeys())) {
((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() {
private static final long serialVersionUID = -3724971416312135885L;
private final Map<String, String> valueMap = getEnumeratedKeyValues(schemaTO);
@Override
public String getDisplayValue(final String value) {
return valueMap.get(value) == null ? value : valueMap.get(value);
}
@Override
public String getIdValue(final String value, final int i) {
return value;
}
});
}
if (required) {
panel.addRequiredLabel();
}
break;
case Long:
panel = new SpinnerFieldPanel<Long>("panel", schemaTO.getName(),
Long.class, new Model<Long>(), null, null);
if (required) {
panel.addRequiredLabel();
}
break;
case Double:
panel = new SpinnerFieldPanel<Double>("panel", schemaTO.getName(),
Double.class, new Model<Double>(), null, null);
if (required) {
panel.addRequiredLabel();
}
break;
case Binary:
panel = new BinaryFieldPanel("panel", schemaTO.getName(), new Model<String>(),
schemas.containsKey(schemaTO.getName())
? schemas.get(schemaTO.getName()).getMimeType()
: null);
if (required) {
panel.addRequiredLabel();
}
break;
default:
panel = new AjaxTextFieldPanel("panel", schemaTO.getName(), new Model<String>());
if (required) {
panel.addRequiredLabel();
}
}
panel.setReadOnly(readOnly);
panel.setNewModel(attributeTO.getValues());
return panel;
}