private static final long serialVersionUID = 4949588177564901031L;
@Override
protected void populateItem(final ListItem<SchemaMappingTO> item) {
final SchemaMappingTO mappingTO = item.getModelObject();
final AttributableType entity;
if (mappingTO.getIntMappingType() != null) {
entity = mappingTO.getIntMappingType().getAttributableType();
} else {
entity = null;
}
attrTypes = getAttributeTypes(entity);
item.add(new AjaxDecoratedCheckbox("toRemove", new Model<Boolean>(Boolean.FALSE)) {
private static final long serialVersionUID = 7170946748485726506L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
int index = -1;
for (int i = 0; i < resourceTO.getMappings().size() && index == -1; i++) {
if (mappingTO.equals(resourceTO.getMappings().get(i))) {
index = i;
}
}
if (index != -1) {
resourceTO.getMappings().remove(index);
item.getParent().removeAll();
target.add(mappingContainer);
}
}
@Override
protected IAjaxCallDecorator getAjaxCallDecorator() {
return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
private static final long serialVersionUID = -7927968187160354605L;
@Override
public CharSequence preDecorateScript(final CharSequence script) {
return "if (confirm('" + getString("confirmDelete") + "'))" + "{" + script + "} "
+ "else {this.checked = false;}";
}
};
}
});
final AjaxDropDownChoicePanel intAttrNames = new AjaxDropDownChoicePanel<String>("intAttrNames",
getString("intAttrNames"), new PropertyModel(mappingTO, "intAttrName"));
intAttrNames.setChoices(schemaNames);
intAttrNames.setRequired(true);
intAttrNames.setStyleShet(fieldStyle);
item.add(intAttrNames);
final AjaxDropDownChoicePanel typesPanel = new AjaxDropDownChoicePanel("intMappingTypes",
new ResourceModel("intMappingTypes", "intMappingTypes").getObject(),
new PropertyModel<IntMappingType>(mappingTO, "intMappingType"));
// typesPanel onChange behavior provided below ...
typesPanel.setRequired(true);
typesPanel.setChoices(attrTypes);
typesPanel.setStyleShet(fieldStyle);
item.add(typesPanel);
final AjaxDropDownChoicePanel mappingTypesPanel = new AjaxDropDownChoicePanel("mappingTypes",
new ResourceModel("mappingTypes", "mappingTypes").getObject(), new Model(entity));
mappingTypesPanel.setChoices(Arrays.asList(AttributableType.values()));
mappingTypesPanel.setStyleShet(defFieldStyle);
item.add(mappingTypesPanel);
mappingTypesPanel.getField().add(new AjaxFormComponentUpdatingBehavior(onchange) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
attrTypes = getAttributeTypes((AttributableType) mappingTypesPanel.getModelObject());
typesPanel.setChoices(attrTypes);
intAttrNames.setChoices(Collections.emptyList());
target.add(typesPanel.getField());
target.add(intAttrNames.getField());
}
});
final FieldPanel extAttrName;
extAttrName = new AjaxTextFieldPanel("extAttrName", new ResourceModel("extAttrNames",
"extAttrNames").getObject(), new PropertyModel<String>(mappingTO, "extAttrName"));
((AjaxTextFieldPanel) extAttrName).setChoices(schemaNames);
boolean required = false;
if (mappingTO != null && !mappingTO.isAccountid() && !mappingTO.isPassword()) {
required = true;
}
extAttrName.setRequired(required);
extAttrName.setEnabled(required);
extAttrName.setStyleShet(fieldStyle);
item.add(extAttrName);
final AjaxTextFieldPanel mandatory = new AjaxTextFieldPanel("mandatoryCondition", new ResourceModel(
"mandatoryCondition", "mandatoryCondition").getObject(), new PropertyModel(mappingTO,
"mandatoryCondition"));
mandatory.setChoices(Arrays.asList(new String[]{"true", "false"}));
mandatory.setStyleShet(shortFieldStyle);
item.add(mandatory);
final AjaxCheckBoxPanel accountId = new AjaxCheckBoxPanel("accountId", new ResourceModel("accountId",
"accountId").getObject(), new PropertyModel(mappingTO, "accountid"));
accountId.getField().add(new AjaxFormComponentUpdatingBehavior(onchange) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
extAttrName.setEnabled(!accountId.getModelObject() && !mappingTO.isPassword());
extAttrName.setModelObject(null);
extAttrName.setRequired(!accountId.getModelObject());
target.add(extAttrName);
}
});
item.add(accountId);
final AjaxCheckBoxPanel password = new AjaxCheckBoxPanel("password", new ResourceModel("password",
"password").getObject(), new PropertyModel(mappingTO, "password"));
password.getField().add(new AjaxFormComponentUpdatingBehavior(onchange) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
extAttrName.setEnabled(!mappingTO.isAccountid() && !password.getModelObject());
extAttrName.setModelObject(null);
extAttrName.setRequired(!password.getModelObject());
target.add(extAttrName);
setAccountId((IntMappingType) typesPanel.getModelObject(), accountId, password);
target.add(accountId);
}
});
item.add(password);
typesPanel.getField().add(new AjaxFormComponentUpdatingBehavior(onchange) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
setAttrNames((IntMappingType) typesPanel.getModelObject(), intAttrNames);
target.add(intAttrNames);
setAccountId((IntMappingType) typesPanel.getModelObject(), accountId, password);
target.add(accountId);
}
});
setAttrNames(mappingTO.getIntMappingType(), intAttrNames);
setAccountId(mappingTO.getIntMappingType(), accountId, password);
}
};
mappings.setReuseItems(true);
mappingContainer.add(mappings);
addMappingBtn = new IndicatingAjaxButton("addUserSchemaMappingBtn", new ResourceModel("add")) {
private static final long serialVersionUID = -4804368561204623354L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
resourceTO.getMappings().add(new SchemaMappingTO());
target.add(mappingContainer);
}
};
addMappingBtn.setDefaultFormProcessing(false);