Skip to content

Commit

Permalink
MID-3362 small cleanup of delta panel and modifications panel
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Oct 21, 2022
1 parent 6e3b150 commit 3bf0a44
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@

package com.evolveum.midpoint.web.component.model.delta;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.schema.util.ValueDisplayUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.schema.util.ValueDisplayUtil;

/**
* @author Pavol
*/
public class ContainerItemDto implements Serializable, Comparable {

public static final String F_ATTRIBUTE = "attribute";
public static final String F_VALUE = "value";

private String attribute;
private Object value;
private int order;
Expand All @@ -46,7 +43,6 @@ public int getOrder() {
}

public static Collection<? extends ContainerItemDto> createContainerValueDtoList(Item item) {

List<ContainerItemDto> retval = new ArrayList<>();

String attribute = getItemName(item);
Expand Down Expand Up @@ -74,6 +70,7 @@ private static int getOrder(Object o) {
}
}
}

return Integer.MAX_VALUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@

package com.evolveum.midpoint.web.component.model.delta;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContainerValue;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContainerValue;

/**
* @author Pavol
*/
public class ContainerValueDto implements Serializable {

public static final String F_ITEM_LIST = "itemList";

private List<ContainerItemDto> itemList;

public ContainerValueDto(PrismContainerValue value) {

itemList = new ArrayList<>();

for (Object o : value.getItems()) {
Expand All @@ -34,4 +31,8 @@ public ContainerValueDto(PrismContainerValue value) {

Collections.sort(itemList);
}

public List<ContainerItemDto> getItemList() {
return itemList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>

<table border="1">
<table class="table table-bordered">
<tr>
<th><wicket:message key="ContainerValuePanel.label.attribute"/></th>
<th><wicket:message key="ContainerValuePanel.label.value"/></th>
Expand All @@ -19,6 +18,5 @@
<td wicket:id="value"/>
</tr>
</table>

</wicket:panel>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@

package com.evolveum.midpoint.web.component.model.delta;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;

public class ContainerValuePanel extends BasePanel<ContainerValueDto> {

private static final Trace LOGGER = TraceManager.getTrace(ModificationsPanel.class);
private static final long serialVersionUID = 1L;

private static final String ID_ITEM = "item";
private static final String ID_ATTRIBUTE = "attribute";
Expand All @@ -30,19 +28,20 @@ public ContainerValuePanel(String id, IModel<ContainerValueDto> model) {
}

protected void initLayout() {
add(new ListView<>(ID_ITEM, () -> getModelObject().getItemList()) {

add(new ListView<ContainerItemDto>(ID_ITEM, new PropertyModel(getModel(), ContainerValueDto.F_ITEM_LIST)) {
@Override
protected void populateItem(ListItem<ContainerItemDto> item) {
item.add(new Label(ID_ATTRIBUTE, new PropertyModel(item.getModel(), ContainerItemDto.F_ATTRIBUTE)));
if (item.getModelObject().getValue() instanceof ContainerValueDto) {
item.add(new ContainerValuePanel(ID_VALUE, new PropertyModel(item.getModel(), ContainerItemDto.F_VALUE)));
} else { // should be String
item.add(new Label(ID_VALUE, new PropertyModel(item.getModel(), ContainerItemDto.F_VALUE)));
item.add(new Label(ID_ATTRIBUTE, () -> item.getModelObject().getAttribute()));

Object value = item.getModelObject().getValue();
if (value instanceof ContainerValueDto) {
item.add(new ContainerValuePanel(ID_VALUE, () -> (ContainerValueDto) value));
} else {
// should be String
item.add(new Label(ID_VALUE, () -> value));
}
}
});
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@

package com.evolveum.midpoint.web.component.model.delta;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.prism.delta.ContainerDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class DeltaDto implements Serializable {

public static final String F_CHANGE_TYPE = "changeType";
public static final String F_OID = "oid";
public static final String F_OBJECT_TO_ADD = "objectToAdd";
public static final String F_MODIFICATIONS = "modifications";

private String changeType;
private String oid;
private List<ModificationDto> modifications;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>

<!--<wicket:message key="DeltaPanel.label.changeType"/> -->

<span wicket:id="changeType"></span> <span wicket:id="oidLabel"/> <span wicket:id="oid" />
<span wicket:id="changeType"/> <span wicket:id="oidLabel"/> <span wicket:id="oid"/>
<br/>
<!--<br/>-->

<span wicket:id="objectToAddLabel"/> <span wicket:id="objectToAdd" />
<span wicket:id="objectToAddLabel"/> <span wicket:id="objectToAdd"/>
<br/>
<b><span wicket:id="modificationsLabel"/></b>
<span wicket:id="modifications" />
<span wicket:id="modifications"/>
<br/>

</wicket:panel>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;

public class DeltaPanel extends BasePanel<DeltaDto> {

private static final Trace LOGGER = TraceManager.getTrace(DeltaPanel.class);
private static final long serialVersionUID = 1L;

private static final String ID_CHANGE_TYPE = "changeType";
private static final String ID_OID = "oid";
Expand All @@ -36,34 +32,30 @@ public DeltaPanel(String id, IModel<DeltaDto> model) {
}

protected void initLayout() {
Label changeType = new Label(ID_CHANGE_TYPE, new PropertyModel<String>(getModel(), DeltaDto.F_CHANGE_TYPE));
Label changeType = new Label(ID_CHANGE_TYPE, () -> getModelObject().getChangeType());
add(changeType);

VisibleBehaviour isAdd = new VisibleBehaviour(() -> getModel().getObject().isAdd());
VisibleEnableBehaviour isNotAdd = new VisibleBehaviour(() -> !getModel().getObject().isAdd());
VisibleBehaviour isAdd = new VisibleBehaviour(() -> getModelObject().isAdd());
VisibleEnableBehaviour isNotAdd = new VisibleBehaviour(() -> !getModelObject().isAdd());

Label oidLabel = new Label(ID_OID_LABEL, new ResourceModel("DeltaPanel.label.oid"));
Label oidLabel = new Label(ID_OID_LABEL, createStringResource("DeltaPanel.label.oid"));
oidLabel.add(isNotAdd);
add(oidLabel);
Label oid = new Label(ID_OID, new PropertyModel<String>(getModel(), DeltaDto.F_OID));

Label oid = new Label(ID_OID, () -> getModelObject().getOid());
oid.add(isNotAdd);
add(oid);

VisibleBehaviour never = new VisibleBehaviour(() -> false);

Label objectToAddLabel = new Label(ID_OBJECT_TO_ADD_LABEL, new ResourceModel("DeltaPanel.label.objectToAdd"));
//objectToAddLabel.add(isAdd);
objectToAddLabel.add(never);
Label objectToAddLabel = new Label(ID_OBJECT_TO_ADD_LABEL, createStringResource("DeltaPanel.label.objectToAdd"));
objectToAddLabel.add(VisibleBehaviour.ALWAYS_INVISIBLE);
add(objectToAddLabel);

ContainerValuePanel objectToAddPanel =
new ContainerValuePanel(ID_OBJECT_TO_ADD,
new PropertyModel<>(getModel(), DeltaDto.F_OBJECT_TO_ADD));
ContainerValuePanel objectToAddPanel = new ContainerValuePanel(ID_OBJECT_TO_ADD, () -> getModelObject().getObjectToAdd());
objectToAddPanel.add(isAdd);
add(objectToAddPanel);

Label modificationsLabel = new Label(ID_MODIFICATIONS_LABEL, new ResourceModel("DeltaPanel.label.modifications"));
modificationsLabel.add(never);
Label modificationsLabel = new Label(ID_MODIFICATIONS_LABEL, createStringResource("DeltaPanel.label.modifications"));
modificationsLabel.add(VisibleBehaviour.ALWAYS_INVISIBLE);
add(modificationsLabel);

ModificationsPanel modificationsPanel = new ModificationsPanel(ID_MODIFICATIONS, getModel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

package com.evolveum.midpoint.web.component.model.delta;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReferenceValue;
Expand All @@ -17,19 +22,11 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.util.ValueDisplayUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Preliminary version.
*/
public class ModificationDto implements Serializable {

public static final String F_ATTRIBUTE = "attribute";
public static final String F_CHANGE_TYPE = "changeType";
public static final String F_VALUE = "value";
private static final String ADD = "ADD";
private static final String REPLACE = "REPLACE";
private static final String DELETE = "DELETE";
Expand All @@ -47,6 +44,18 @@ public ModificationDto(String attribute, String type, Object value) {
isPropertyDelta = true;
}

public String getAttribute() {
return attribute;
}

public String getChangeType() {
return changeType;
}

public boolean isPropertyDelta() {
return isPropertyDelta;
}

public Object getValue() {
return value;
}
Expand Down Expand Up @@ -85,7 +94,7 @@ private static String getItemName(ItemDelta delta) {
}
ItemPath path = delta.getPath();
List<?> segments = path.getSegments();
for (int i = segments.size()-1; i >= 0; i--) {
for (int i = segments.size() - 1; i >= 0; i--) {
Object component = segments.get(i);
if (ItemPath.isName(component)) {
StringBuilder retval = new StringBuilder(ItemPath.toName(component).getLocalPart());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>

<table border="1">
<table class="table table-bordered">
<tr>
<th><wicket:message key="ModificationsPanel.label.attribute"/></th>
<th><wicket:message key="ModificationsPanel.label.change"/></th>
Expand All @@ -21,6 +20,5 @@
<td wicket:id="value"/>
</tr>
</table>

</wicket:panel>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

package com.evolveum.midpoint.web.component.model.delta;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;

public class ModificationsPanel extends BasePanel<DeltaDto> {

private static final Trace LOGGER = TraceManager.getTrace(ModificationsPanel.class);
private static final long serialVersionUID = 1L;

private static final String ID_MODIFICATION = "modification";
private static final String ID_ATTRIBUTE = "attribute";
Expand All @@ -28,20 +25,23 @@ public class ModificationsPanel extends BasePanel<DeltaDto> {

public ModificationsPanel(String id, IModel<DeltaDto> model) {
super(id, model);

initLayout();
}

protected void initLayout() {

add(new ListView<ModificationDto>(ID_MODIFICATION, new PropertyModel(getModel(), DeltaDto.F_MODIFICATIONS)) {
add(new ListView<>(ID_MODIFICATION, () -> getModelObject().getModifications()) {
@Override
protected void populateItem(ListItem<ModificationDto> item) {
item.add(new Label(ID_ATTRIBUTE, new PropertyModel(item.getModel(), ModificationDto.F_ATTRIBUTE)));
item.add(new Label(ID_CHANGE_TYPE, new PropertyModel(item.getModel(), ModificationDto.F_CHANGE_TYPE)));
if (item.getModelObject().getValue() instanceof ContainerValueDto) {
item.add(new ContainerValuePanel(ID_VALUE, new Model((ContainerValueDto) item.getModelObject().getValue())));
} else { // should be String
item.add(new Label(ID_VALUE, new PropertyModel(item.getModel(), ModificationDto.F_VALUE)));
item.add(new Label(ID_ATTRIBUTE, () -> item.getModelObject().getAttribute()));
item.add(new Label(ID_CHANGE_TYPE, () -> item.getModelObject().getChangeType()));

Object value = item.getModelObject().getValue();
if (value instanceof ContainerValueDto) {
item.add(new ContainerValuePanel(ID_VALUE, () -> (ContainerValueDto) value));
} else {
// should be String
item.add(new Label(ID_VALUE, () -> value));
}
}
});
Expand Down

0 comments on commit 3bf0a44

Please sign in to comment.