Skip to content

Commit

Permalink
MID-6271 linked reference panel cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed May 20, 2022
1 parent e76e9b5 commit 2279b40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div>
<div class="pull-left" wicket:id="icon" />
<a style="padding-left: 10px;" wicket:id="nameLink" >
<span wicket:id="nameLinkText"/>
</a>
</div>
<div wicket:id="icon" />
<a wicket:id="nameLink">
<span wicket:id="nameLinkText"/>
</a>
</wicket:panel>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
*/
package com.evolveum.midpoint.web.component.data;

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

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.PrismObject;
Expand All @@ -32,6 +31,7 @@
* Created by honchar
*/
public class LinkedReferencePanel<R extends Referencable> extends BasePanel<R> {

private static final long serialVersionUID = 1L;

private static final String ID_ICON = "icon";
Expand All @@ -55,8 +55,7 @@ protected void onInitialize() {
}

public void initReferencedObjectModel() {

referenceModel = new LoadableModel<PrismReferenceValue>() {
referenceModel = new LoadableModel<>() {

@Override
protected PrismReferenceValue load() {
Expand All @@ -80,8 +79,9 @@ protected PrismReferenceValue load() {

private void initLayout() {
setOutputMarkupId(true);
add(AttributeAppender.append("class", "d-flex flex-wrap gap-2"));

IModel<DisplayType> displayModel = new ReadOnlyModel<>(() -> {
IModel<DisplayType> displayModel = () -> {

PrismReferenceValue ref = referenceModel.getObject();
if (ref == null) {
Expand All @@ -96,13 +96,13 @@ private void initLayout() {
displayType.setIcon(WebComponentUtil.createIconType(WebComponentUtil.createDefaultBlackIcon(ref.getTargetType())));
}
return displayType;
});
};

ImagePanel imagePanel = new ImagePanel(ID_ICON, displayModel);
imagePanel.setOutputMarkupId(true);
add(imagePanel);

AjaxLink<PrismReferenceValue> nameLink = new AjaxLink<PrismReferenceValue>(ID_NAME, referenceModel) {
AjaxLink<PrismReferenceValue> nameLink = new AjaxLink<>(ID_NAME, referenceModel) {
@Override
public void onClick(AjaxRequestTarget ajaxRequestTarget) {
WebComponentUtil.dispatchToObjectDetailsPage(referenceModel.getObject(), LinkedReferencePanel.this, false);
Expand All @@ -119,15 +119,14 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {
nameLink.setOutputMarkupId(true);
add(nameLink);

Label nameLinkText = new Label(ID_NAME_TEXT, new ReadOnlyModel<>(() -> {
Label nameLinkText = new Label(ID_NAME_TEXT, () -> {
PrismReferenceValue ref = referenceModel.getObject();
if (ref == null) {
return "";
}
return WebComponentUtil.getReferencedObjectDisplayNameAndName(ref.asReferencable(), false, getPageBase());
}));
});
nameLinkText.setOutputMarkupId(true);
nameLink.add(nameLinkText);
}

}

0 comments on commit 2279b40

Please sign in to comment.