Skip to content

Commit

Permalink
better handling of displayName(s) for container creation (MID-7412, M…
Browse files Browse the repository at this point in the history
…ID-7414)
  • Loading branch information
katkav committed Nov 21, 2021
1 parent 1c97c2b commit 6fc0df6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1806,10 +1806,10 @@ public <IW extends ItemWrapper, VW extends PrismValueWrapper, PV extends PrismVa

public <ID extends ItemDefinition, IW extends ItemWrapper> IW createItemWrapper(ID def, PrismContainerValueWrapper<?> parent, WrapperContext ctx) throws SchemaException {

PrismContainerWrapperFactory<?> factory = registry.findContainerWrapperFactory(parent.getDefinition());
ItemWrapperFactory<IW, ?, ?> factory = registry.findWrapperFactory(def, parent.getNewValue());
ctx.setShowEmpty(true);
ctx.setCreateIfEmpty(true);
return (IW) factory.createWrapper(parent, def, ctx);
return factory.createWrapper(parent, def, ctx);
}

public <I extends Item, IW extends ItemWrapper> IW createItemWrapper(I item, ItemStatus status, WrapperContext ctx) throws SchemaException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ protected void processSelectedChildren(AjaxRequestTarget target, List<PrismConta
private void prepareNewContainers(AjaxRequestTarget target, List<PrismContainerDefinition<?>> containers) {
Task task = getPageBase().createSimpleTask("Create child containers");
WrapperContext ctx = new WrapperContext(task, task.getResult());
ctx.setCreateIfEmpty(true);
containers.forEach(container -> {
try {
ItemWrapper iw = getPageBase().createItemWrapper(container, getModelObject(), ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;

import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand All @@ -33,6 +38,8 @@
import com.evolveum.midpoint.web.component.form.CheckFormGroup;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;

import javax.xml.namespace.QName;

/**
* @author katka
*/
Expand All @@ -59,25 +66,43 @@ protected void onInitialize() {
initLayout();
}

private ContainersPopupDto createContainersPopupDto(PrismContainerDefinition<C> def) {
return new ContainersPopupDto(false, def) {

@Override
public String getDisplayName() {
if (getModelObject().getDefinition() == null) {
return super.getDisplayName();
}
QName typeName = getModelObject().getDefinition().getTypeName();
if (typeName == null) {
return super.getDisplayName();
}
return typeName.getLocalPart() + "." + getItemName();
}
};
}

private void initLayout() {

IModel<List<ContainersPopupDto>> popupModel = new LoadableModel<List<ContainersPopupDto>>(false) {
IModel<List<ContainersPopupDto>> popupModel = new LoadableModel<>(false) {

private static final long serialVersionUID = 1L;

@Override
protected List<ContainersPopupDto> load() {
List<PrismContainerDefinition<C>> defs = null;
List<PrismContainerDefinition<C>> defs;
try {
defs = getModelObject().getChildContainers();
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot get children containers for {}, reason {}", e, getModelObject(), e.getMessage());
getSession().error("ListContainersPopup.children.list.failed");
defs = new ArrayList<>();
}
List<ContainersPopupDto> modelObject = new ArrayList<>(defs.size());
List<ContainersPopupDto> modelObject = defs.stream().filter(def -> def.isExperimental() ? WebModelServiceUtils.isEnableExperimentalFeature(getPageBase()) : true)
.map(def -> createContainersPopupDto(def))
.collect(Collectors.toList());

defs.forEach(def -> modelObject.add(new ContainersPopupDto(false, def)));
return modelObject;
}
};
Expand All @@ -89,7 +114,7 @@ protected List<ContainersPopupDto> load() {
@Override
protected void populateItem(ListItem<ContainersPopupDto> item) {

CheckFormGroup checkFormGroup = new CheckFormGroup(ID_SELECTED, new PropertyModel<Boolean>(item.getModel(), "selected"),
CheckFormGroup checkFormGroup = new CheckFormGroup(ID_SELECTED, new PropertyModel<>(item.getModel(), "selected"),
new StringResourceModel("ListContainersPopup.selected"), "col-md-2", "col-md-10") {

protected boolean getLabelVisible() {
Expand Down

0 comments on commit 6fc0df6

Please sign in to comment.