final Form schemaForm = new Form(FORM);
schemaForm.setModel(new CompoundPropertyModel(schema));
schemaForm.setOutputMarkupId(Boolean.TRUE);
final AjaxTextFieldPanel name =
new AjaxTextFieldPanel("name", getString("name"), new PropertyModel<String>(schema, "name"));
name.addRequiredLabel();
name.setEnabled(createFlag);
final AjaxTextFieldPanel conversionPattern = new AjaxTextFieldPanel("conversionPattern",
getString("conversionPattern"), new PropertyModel<String>(schema, "conversionPattern"));
final IModel<List<String>> validatorsList = new LoadableDetachableModel<List<String>>() {
private static final long serialVersionUID = 5275935387613157437L;
@Override
protected List<String> load() {
return schemaRestClient.getAllValidatorClasses();
}
};
final AjaxDropDownChoicePanel<String> validatorClass = new AjaxDropDownChoicePanel<String>("validatorClass",
getString("validatorClass"), new PropertyModel(schema, "validatorClass"));
((DropDownChoice) validatorClass.getField()).setNullValid(true);
validatorClass.setChoices(validatorsList.getObject());
final AjaxDropDownChoicePanel<AttributeSchemaType> type = new AjaxDropDownChoicePanel<AttributeSchemaType>(
"type", getString("type"), new PropertyModel(schema, "type"));
type.setChoices(Arrays.asList(AttributeSchemaType.values()));
type.addRequiredLabel();
final AjaxTextFieldPanel enumerationValuesPanel =
new AjaxTextFieldPanel("panel", "enumerationValues", new Model<String>(null));
final MultiValueSelectorPanel<String> enumerationValues =
new MultiValueSelectorPanel<String>("enumerationValues",
new Model(),
enumerationValuesPanel);
schemaForm.add(enumerationValues);
enumerationValues.setModelObject((Serializable) getEnumValuesAsList(schema.getEnumerationValues()));
final MultiValueSelectorPanel<String> enumerationKeys =
new MultiValueSelectorPanel<String>("enumerationKeys",
new Model(),
new AjaxTextFieldPanel("panel", "enumerationKeys", new Model<String>(null)));
schemaForm.add(enumerationKeys);
enumerationKeys.setModelObject((Serializable) getEnumValuesAsList(schema.getEnumerationKeys()));
if (AttributeSchemaType.Enum == schema.getType()) {
enumerationValues.setEnabled(Boolean.TRUE);
enumerationKeys.setEnabled(Boolean.TRUE);
enumerationValuesPanel.addRequiredLabel();
} else {
enumerationValues.setEnabled(Boolean.FALSE);
enumerationKeys.setEnabled(Boolean.FALSE);
}
type.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (AttributeSchemaType.Enum.ordinal() == Integer.parseInt(type.getField().getValue())) {
if (!enumerationValuesPanel.isRequired()) {
enumerationValuesPanel.addRequiredLabel();
}
enumerationValues.setEnabled(Boolean.TRUE);
enumerationValues.setModelObject((Serializable) getEnumValuesAsList(schema.getEnumerationValues()));
enumerationKeys.setEnabled(Boolean.TRUE);
enumerationKeys.setModelObject((Serializable) getEnumValuesAsList(schema.getEnumerationKeys()));
} else {
if (enumerationValuesPanel.isRequired()) {
enumerationValuesPanel.removeRequiredLabel();
}
final List<String> values = new ArrayList<String>();
values.add("");
enumerationValues.setEnabled(Boolean.FALSE);