Skip to content

Commit

Permalink
custom columns for projections (MID-7638)
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Mar 28, 2022
1 parent 3fae5ff commit 5e780a5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,11 @@ private boolean pathNotEmpty(ItemPath columnPath) {
return columnPath != null && !columnPath.isEmpty();
}

private IModel<?> getExportableColumnDataModel(IModel<PO> rowModel, GuiObjectColumnType customColumn, ItemPath columnPath, ExpressionType expression) {
protected IModel<?> getExportableColumnDataModel(IModel<PO> rowModel, GuiObjectColumnType customColumn, ItemPath columnPath, ExpressionType expression) {
return new ReadOnlyModel<>(() -> loadExportableColumnDataModel(rowModel, customColumn, columnPath, expression));
}

protected Collection<String> loadExportableColumnDataModel(IModel<PO> rowModel, GuiObjectColumnType customColumn, ItemPath columnPath, ExpressionType expression) {
public Collection<String> loadExportableColumnDataModel(IModel<PO> rowModel, GuiObjectColumnType customColumn, ItemPath columnPath, ExpressionType expression) {
C value = getRowRealValue(rowModel.getObject());
if (value == null) {
return Collections.singletonList("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
Expand All @@ -33,6 +34,7 @@
import com.evolveum.midpoint.gui.api.component.tabs.PanelTab;
import com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory;
import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
Expand Down Expand Up @@ -71,6 +73,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.*;
import com.evolveum.midpoint.web.component.data.ISelectableDataProvider;
import com.evolveum.midpoint.web.component.data.column.AjaxLinkColumn;
import com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn;
import com.evolveum.midpoint.web.component.data.column.ColumnMenuAction;
import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel;
Expand Down Expand Up @@ -192,16 +195,7 @@ protected List<IColumn<PrismContainerValueWrapper<ShadowType>, String>> createDe

@Override
protected IColumn<PrismContainerValueWrapper<ShadowType>, String> createNameColumn(IModel<String> displayModel, GuiObjectColumnType customColumn, ItemPath itemPath, ExpressionType expression) {
IModel<PrismContainerDefinition<ShadowType>> shadowDef = Model.of(getShadowDefinition());
return new PrismPropertyWrapperColumn<ShadowType, String>(shadowDef, ShadowType.F_NAME, ColumnType.LINK, getPageBase()) {
private static final long serialVersionUID = 1L;

@Override
protected void onClick(AjaxRequestTarget target, IModel<PrismContainerValueWrapper<ShadowType>> rowModel) {
getMultivalueContainerListPanel().itemDetailsPerformed(target, rowModel);
target.add(getPageBase().getFeedbackPanel());
}
};
return createProjectionNameColumn(displayModel, customColumn, itemPath, expression);
}

@Override
Expand Down Expand Up @@ -281,6 +275,50 @@ protected MultivalueContainerDetailsPanel<ShadowType> getMultivalueContainerDeta
setOutputMarkupId(true);
}

private IColumn<PrismContainerValueWrapper<ShadowType>, String> createProjectionNameColumn(IModel<String> displayModel, GuiObjectColumnType customColumn, ItemPath itemPath, ExpressionType expression) {
if (expression != null) {
return new AjaxLinkColumn<>(displayModel) {
private static final long serialVersionUID = 1L;

@Override
public IModel<String> createLinkModel(IModel<PrismContainerValueWrapper<ShadowType>> rowModel) {
return new LoadableModel<>() {
@Override
protected String load() {
Collection<String> evaluatedValues = getMultivalueContainerListPanel().loadExportableColumnDataModel(rowModel, customColumn, itemPath, expression);
if (CollectionUtils.isEmpty(evaluatedValues)) {
return "";
}
if (evaluatedValues.size() == 1) {
return evaluatedValues.iterator().next();
}
return String.join(", ", evaluatedValues);
}
};
}


@Override
public void onClick(AjaxRequestTarget target, IModel<PrismContainerValueWrapper<ShadowType>> rowModel) {
getMultivalueContainerListPanel().itemDetailsPerformed(target, rowModel);
target.add(getPageBase().getFeedbackPanel());
}
};
}

IModel<PrismContainerDefinition<ShadowType>> shadowDef = Model.of(getShadowDefinition());
return new PrismPropertyWrapperColumn<ShadowType, String>(shadowDef, ShadowType.F_NAME, ColumnType.LINK, getPageBase()) {
private static final long serialVersionUID = 1L;

@Override
protected void onClick(AjaxRequestTarget target, IModel<PrismContainerValueWrapper<ShadowType>> rowModel) {
getMultivalueContainerListPanel().itemDetailsPerformed(target, rowModel);
target.add(getPageBase().getFeedbackPanel());
}

};
}

private IModel<List<PrismContainerValueWrapper<ShadowType>>> loadShadowModel() {
return () -> {
List<PrismContainerValueWrapper<ShadowType>> items = new ArrayList<>();
Expand Down

0 comments on commit 5e780a5

Please sign in to comment.