private static final long serialVersionUID = 4949588177564901031L;
@Override
protected void populateItem(final ListItem<MappingItemTO> item) {
final MappingItemTO mapItem = item.getModelObject();
if (mapItem.getPurpose() == null) {
mapItem.setPurpose(MappingPurpose.BOTH);
}
AttributableType entity = null;
if (mapItem.getIntMappingType() != null) {
entity = mapItem.getIntMappingType().getAttributableType();
}
final List<IntMappingType> attrTypes = new ArrayList<IntMappingType>(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 < getMapping().getItems().size() && index == -1; i++) {
if (mapItem.equals(getMapping().getItems().get(i))) {
index = i;
}
}
if (index != -1) {
getMapping().getItems().remove(index);
item.getParent().removeAll();
target.add(ResourceMappingPanel.this);
}
}
@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
final AjaxCallListener ajaxCallListener = new AjaxCallListener() {
private static final long serialVersionUID = 7160235486520935153L;
@Override
public CharSequence getPrecondition(final Component component) {
return "if (!confirm('" + getString("confirmDelete") + "')) return false;";
}
};
attributes.getAjaxCallListeners().add(ajaxCallListener);
}
});
final AjaxDropDownChoicePanel<String> intAttrNames =
new AjaxDropDownChoicePanel<String>("intAttrNames", getString("intAttrNames"),
new PropertyModel<String>(mapItem, "intAttrName"), false);
intAttrNames.setChoices(schemaNames);
intAttrNames.setRequired(true);
intAttrNames.setStyleSheet(FIELD_STYLE);
intAttrNames.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
item.add(intAttrNames);
final AjaxDropDownChoicePanel<IntMappingType> intMappingTypes =
new AjaxDropDownChoicePanel<IntMappingType>("intMappingTypes",
new ResourceModel("intMappingTypes", "intMappingTypes").getObject(),
new PropertyModel<IntMappingType>(mapItem, "intMappingType"));
intMappingTypes.setRequired(true);
intMappingTypes.setChoices(attrTypes);
intMappingTypes.setStyleSheet(FIELD_STYLE);
item.add(intMappingTypes);
final AjaxDropDownChoicePanel<AttributableType> entitiesPanel =
new AjaxDropDownChoicePanel<AttributableType>("entities",
new ResourceModel("entities", "entities").getObject(), new Model<AttributableType>(entity));
entitiesPanel.setChoices(attrType == AttributableType.ROLE
? Collections.<AttributableType>singletonList(AttributableType.ROLE)
: Arrays.asList(AttributableType.values()));
entitiesPanel.setStyleSheet(DEF_FIELD_STYLE);
entitiesPanel.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
attrTypes.clear();
attrTypes.addAll(getAttributeTypes(entitiesPanel.getModelObject()));
intMappingTypes.setChoices(attrTypes);
intAttrNames.setChoices(Collections.<String>emptyList());
target.add(intMappingTypes.getField());
target.add(intAttrNames.getField());
}
});
item.add(entitiesPanel);
final FieldPanel extAttrNames = new AjaxTextFieldPanel("extAttrName",
new ResourceModel("extAttrNames", "extAttrNames").getObject(),
new PropertyModel<String>(mapItem, "extAttrName"));
((AjaxTextFieldPanel) extAttrNames).setChoices(schemaNames);
boolean required = false;
boolean accountIdOrPassword = mapItem.isAccountid() || mapItem.isPassword();
if (accountIdOrPassword) {
((AjaxTextFieldPanel) extAttrNames).setModelObject(null);
} else if (!schemaNames.isEmpty()) {
required = true;
}
extAttrNames.setRequired(required);
extAttrNames.setEnabled(required);
extAttrNames.setStyleSheet(FIELD_STYLE);
item.add(extAttrNames);
final AjaxTextFieldPanel mandatory = new AjaxTextFieldPanel("mandatoryCondition",
new ResourceModel("mandatoryCondition", "mandatoryCondition").getObject(),
new PropertyModel<String>(mapItem, "mandatoryCondition"));
mandatory.setChoices(Arrays.asList(new String[] {"true", "false"}));
mandatory.setStyleSheet(SHORT_FIELD_STYLE);
item.add(mandatory);
final AjaxCheckBoxPanel accountId = new AjaxCheckBoxPanel("accountId",
new ResourceModel("accountId", "accountId").getObject(),
new PropertyModel<Boolean>(mapItem, "accountid"));
accountId.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
extAttrNames.setEnabled(!accountId.getModelObject() && !mapItem.isPassword());
extAttrNames.setModelObject(null);
extAttrNames.setRequired(!accountId.getModelObject());
target.add(extAttrNames);
if (accountId.getModelObject()) {
mapItem.setMandatoryCondition("true");
mandatory.setEnabled(false);
} else {
mapItem.setMandatoryCondition("false");
mandatory.setEnabled(true);
}
target.add(mandatory);
}
});
item.add(accountId);
final AjaxCheckBoxPanel password = new AjaxCheckBoxPanel("password",
new ResourceModel("password", "password").getObject(),
new PropertyModel<Boolean>(mapItem, "password"));
password.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
extAttrNames.setEnabled(!mapItem.isAccountid() && !password.getModelObject());
extAttrNames.setModelObject(null);
extAttrNames.setRequired(!password.getModelObject());
target.add(extAttrNames);
setAccountId(intMappingTypes.getModelObject(), accountId, password);
target.add(accountId);
}
});
item.add(password);
if (AttributableType.USER != ResourceMappingPanel.this.attrType) {
password.setVisible(false);
}
final AjaxDropDownChoicePanel<MappingPurpose> purpose =
new AjaxDropDownChoicePanel<MappingPurpose>("purpose",
new ResourceModel("purpose", "purpose").getObject(),
new PropertyModel<MappingPurpose>(mapItem, "purpose"),
false);
purpose.setChoices(Arrays.asList(MappingPurpose.values()));
purpose.setStyleSheet(FIELD_STYLE);
purpose.setRequired(true);
purpose.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
item.add(purpose);
intMappingTypes.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
setAttrNames(intMappingTypes.getModelObject(), intAttrNames);
target.add(intAttrNames);
setAccountId(intMappingTypes.getModelObject(), accountId, password);
target.add(accountId);
}
});
setAttrNames(mapItem.getIntMappingType(), intAttrNames);
setAccountId(mapItem.getIntMappingType(), accountId, password);
}
};
mappings.setReuseItems(true);
mappingContainer.add(mappings);
addMappingBtn = new IndicatingAjaxButton("addMappingBtn", new ResourceModel("add")) {
private static final long serialVersionUID = -4804368561204623354L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
getMapping().getItems().add(new MappingItemTO());
target.add(ResourceMappingPanel.this);
}
};
addMappingBtn.setDefaultFormProcessing(false);
addMappingBtn.setEnabled(this.resourceTO.getConnectorId() != null && this.resourceTO.getConnectorId() > 0);