@Override
public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window,
final SchemaTO schemaTO, final boolean createFlag) {
final SchemaTO schema = schemaTO == null
? new SchemaTO()
: schemaTO;
final Form<SchemaTO> schemaForm = new Form<SchemaTO>(FORM);
schemaForm.setModel(new CompoundPropertyModel<SchemaTO>(schema));
schemaForm.setOutputMarkupId(true);
final AjaxTextFieldPanel name =
new AjaxTextFieldPanel("name", getString("name"), new PropertyModel<String>(schema, "name"));
name.addRequiredLabel();
name.setEnabled(createFlag);
schemaForm.add(name);
final AjaxDropDownChoicePanel<AttributeSchemaType> type = new AjaxDropDownChoicePanel<AttributeSchemaType>(
"type", getString("type"), new PropertyModel<AttributeSchemaType>(schema, "type"));
type.setChoices(Arrays.asList(AttributeSchemaType.values()));
type.addRequiredLabel();
schemaForm.add(type);
// -- long, double, date
final AjaxTextFieldPanel conversionPattern = new AjaxTextFieldPanel("conversionPattern",
getString("conversionPattern"), new PropertyModel<String>(schema, "conversionPattern"));
schemaForm.add(conversionPattern);
final WebMarkupContainer conversionParams = new WebMarkupContainer("conversionParams");
conversionParams.setOutputMarkupPlaceholderTag(true);
conversionParams.add(conversionPattern);
schemaForm.add(conversionParams);
// -- enum
final AjaxTextFieldPanel enumerationValuesPanel =
new AjaxTextFieldPanel("panel", "enumerationValues", new Model<String>(null));
@SuppressWarnings({ "unchecked", "rawtypes" })
final MultiFieldPanel<String> enumerationValues = new MultiFieldPanel<String>("enumerationValues",
new Model(),
enumerationValuesPanel);
enumerationValues.setModelObject(getEnumValuesAsList(schema.getEnumerationValues()));
@SuppressWarnings({ "unchecked", "rawtypes" })
final MultiFieldPanel<String> enumerationKeys = new MultiFieldPanel<String>("enumerationKeys",
new Model(),
new AjaxTextFieldPanel("panel", "enumerationKeys", new Model<String>(null)));
enumerationKeys.setModelObject(getEnumValuesAsList(schema.getEnumerationKeys()));
final WebMarkupContainer enumParams = new WebMarkupContainer("enumParams");
enumParams.setOutputMarkupPlaceholderTag(true);
enumParams.add(enumerationValues);
enumParams.add(enumerationKeys);
schemaForm.add(enumParams);
// -- encrypted
final AjaxTextFieldPanel secretKey = new AjaxTextFieldPanel("secretKey",
getString("secretKey"), new PropertyModel<String>(schema, "secretKey"));
final AjaxDropDownChoicePanel<CipherAlgorithm> cipherAlgorithm = new AjaxDropDownChoicePanel<CipherAlgorithm>(
"cipherAlgorithm", getString("cipherAlgorithm"),
new PropertyModel<CipherAlgorithm>(schema, "cipherAlgorithm"));
cipherAlgorithm.setChoices(Arrays.asList(CipherAlgorithm.values()));
final WebMarkupContainer encryptedParams = new WebMarkupContainer("encryptedParams");
encryptedParams.setOutputMarkupPlaceholderTag(true);
encryptedParams.add(secretKey);
encryptedParams.add(cipherAlgorithm);
schemaForm.add(encryptedParams);
// -- binary
final AjaxTextFieldPanel mimeType = new AjaxTextFieldPanel("mimeType",
getString("mimeType"), new PropertyModel<String>(schema, "mimeType"));
mimeType.setChoices(mimeTypesInitializer.getMimeTypes());
final WebMarkupContainer binaryParams = new WebMarkupContainer("binaryParams");
binaryParams.setOutputMarkupPlaceholderTag(true);
binaryParams.add(mimeType);
schemaForm.add(binaryParams);
// -- show or hide
showHide(schema, type,
conversionParams, conversionPattern,
enumParams, enumerationValuesPanel, enumerationValues, enumerationKeys,
encryptedParams, secretKey, cipherAlgorithm,
binaryParams, mimeType);
type.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
SchemaModalPage.this.showHide(schema, type,
conversionParams, conversionPattern,
enumParams, enumerationValuesPanel, enumerationValues, enumerationKeys,
encryptedParams, secretKey, cipherAlgorithm,
binaryParams, mimeType);
target.add(schemaForm);
}
});
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<String>(schema, "validatorClass"));
((DropDownChoice) validatorClass.getField()).setNullValid(true);
validatorClass.setChoices(validatorsList.getObject());
schemaForm.add(validatorClass);
final AutoCompleteTextField<String> mandatoryCondition =
new AutoCompleteTextField<String>("mandatoryCondition") {
private static final long serialVersionUID = -2428903969518079100L;
@Override
protected Iterator<String> getChoices(final String input) {
List<String> choices = new ArrayList<String>();
if (Strings.isEmpty(input)) {
choices = Collections.emptyList();
} else if ("true".startsWith(input.toLowerCase())) {
choices.add("true");
} else if ("false".startsWith(input.toLowerCase())) {
choices.add("false");
}
return choices.iterator();
}
};
mandatoryCondition.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
schemaForm.add(mandatoryCondition);
final WebMarkupContainer pwdJexlHelp = JexlHelpUtil.getJexlHelpWebContainer("jexlHelp");
final AjaxLink<Void> pwdQuestionMarkJexlHelp = JexlHelpUtil.getAjaxLink(pwdJexlHelp, "questionMarkJexlHelp");
schemaForm.add(pwdQuestionMarkJexlHelp);
pwdQuestionMarkJexlHelp.add(pwdJexlHelp);
final AjaxCheckBoxPanel multivalue = new AjaxCheckBoxPanel("multivalue", getString("multivalue"),
new PropertyModel<Boolean>(schema, "multivalue"));
schemaForm.add(multivalue);
final AjaxCheckBoxPanel readonly = new AjaxCheckBoxPanel("readonly", getString("readonly"),
new PropertyModel<Boolean>(schema, "readonly"));
schemaForm.add(readonly);
final AjaxCheckBoxPanel uniqueConstraint = new AjaxCheckBoxPanel("uniqueConstraint",
getString("uniqueConstraint"), new PropertyModel<Boolean>(schema, "uniqueConstraint"));
schemaForm.add(uniqueConstraint);
final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
final SchemaTO schemaTO = (SchemaTO) form.getDefaultModelObject();
schemaTO.setEnumerationValues(getEnumValuesAsString(enumerationValues.getView().getModelObject()));
schemaTO.setEnumerationKeys(getEnumValuesAsString(enumerationKeys.getView().getModelObject()));
if (schemaTO.isMultivalue() && schemaTO.isUniqueConstraint()) {
error(getString("multivalueAndUniqueConstr.validation"));
feedbackPanel.refresh(target);
return;
}