use of com.evolveum.midpoint.web.component.form.multivalue.GenericMultiValueLabelEditPanel in project midpoint by Evolveum.
the class ConstructionAssociationPanel method initLayout.
protected void initLayout() {
ListView<ResourceAssociationDefinition> associationsPanel = new ListView<ResourceAssociationDefinition>(ID_ASSOCIATIONS, refinedAssociationDefinitionsModel) {
@Override
protected void populateItem(ListItem<ResourceAssociationDefinition> item) {
GenericMultiValueLabelEditPanel associationReferencesPanel = new GenericMultiValueLabelEditPanel<ObjectReferenceType>(ID_ASSOCIATION_REFERENCE_PANEL, getShadowReferencesModel(item.getModelObject()), Model.of(WebComponentUtil.getAssociationDisplayName(item.getModelObject())), ID_LABEL_SIZE, ID_INPUT_SIZE, true) {
private static final long serialVersionUID = 1L;
@Override
protected boolean isEditButtonEnabled() {
return false;
}
@Override
protected void addValuePerformed(AjaxRequestTarget target) {
addNewShadowRefValuePerformed(target, item.getModelObject());
}
protected void addFirstPerformed(AjaxRequestTarget target) {
addNewShadowRefValuePerformed(target, item.getModelObject());
}
@Override
protected IModel<String> createTextModel(final IModel<ObjectReferenceType> model) {
return new IModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
ObjectReferenceType obj = model.getObject();
if (obj == null) {
return "";
}
return WebComponentUtil.getDisplayNameOrName(obj, getPageBase(), OPERATION_LOAD_SHADOW_DISPLAY_NAME);
}
};
}
@Override
protected void removeValuePerformed(AjaxRequestTarget target, ListItem<ObjectReferenceType> item) {
try {
ObjectReferenceType removedShadowRef = item.getModelObject();
PrismContainerWrapper<ConstructionType> constructionContainerWrapper = ConstructionAssociationPanel.this.getModelObject();
PrismContainerWrapper<ResourceObjectAssociationType> associationWrapper = constructionContainerWrapper.findContainer(ConstructionType.F_ASSOCIATION);
associationWrapper.getValues().forEach(associationValueWrapper -> {
if (ValueStatus.DELETED.equals(associationValueWrapper.getStatus())) {
return;
}
ResourceObjectAssociationType associationValue = associationValueWrapper.getRealValue();
// ResourceObjectAssociationType assoc = (ResourceObjectAssociationType) associationValue.asContainerable();
if (associationValue == null || associationValue.getOutbound() == null || associationValue.getOutbound().getExpression() == null || ExpressionUtil.getShadowRefValue(associationValue.getOutbound().getExpression(), ConstructionAssociationPanel.this.getPageBase().getPrismContext()) == null) {
return;
}
List<ObjectReferenceType> shadowRefList = ExpressionUtil.getShadowRefValue(associationValue.getOutbound().getExpression(), ConstructionAssociationPanel.this.getPageBase().getPrismContext());
shadowRefList.forEach(shadowRef -> {
if (shadowRef.equals(removedShadowRef)) {
associationValueWrapper.setStatus(ValueStatus.DELETED);
}
});
});
} catch (SchemaException ex) {
LOGGER.error("Couldn't remove association value: {}", ex.getLocalizedMessage());
}
super.removeValuePerformed(target, item);
}
};
associationReferencesPanel.setOutputMarkupId(true);
item.add(associationReferencesPanel);
}
};
associationsPanel.setOutputMarkupId(true);
add(associationsPanel);
}
Aggregations