Skip to content

Commit

Permalink
MID-3362 attemp to localize delta visualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Nov 9, 2022
1 parent 08fefd7 commit 95cfc4f
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public Object getValue() {
return value;
}

public String getAttribute() {
return attribute;
}

public String getChangeType() {
return changeType;
}

public static Collection<? extends ModificationDto> createModificationDtoList(PropertyDelta delta) {

String attribute = getItemName(delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

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;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

public class ModificationsPanel extends BasePanel<DeltaDto> {

private static final Trace LOGGER = TraceManager.getTrace(ModificationsPanel.class);
Expand All @@ -36,12 +38,20 @@ protected void initLayout() {
add(new ListView<ModificationDto>(ID_MODIFICATION, new PropertyModel(getModel(), DeltaDto.F_MODIFICATIONS)) {
@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)));
item.add(new Label(ID_ATTRIBUTE, () -> item.getModelObject().getAttribute()));
item.add(new Label(ID_CHANGE_TYPE, () -> item.getModelObject().getChangeType()));

if (item.getModelObject().getValue() instanceof ContainerValueDto) {
item.add(new ContainerValuePanel(ID_VALUE, new Model((ContainerValueDto) item.getModelObject().getValue())));
item.add(new ContainerValuePanel(ID_VALUE, () -> (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_VALUE, () -> {
Object value = item.getModelObject().getValue();
if (value instanceof PolyString) {
return WebComponentUtil.getTranslatedPolyString((PolyString) value);
}

return value;
}));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@

package com.evolveum.midpoint.web.component.prism.show;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.visualizer.*;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.model.api.visualizer.Name;
import com.evolveum.midpoint.model.api.visualizer.SceneDeltaItem;
import com.evolveum.midpoint.model.api.visualizer.SceneItem;
import com.evolveum.midpoint.model.api.visualizer.SceneItemValue;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.web.util.PolyStringComparator;

public class SceneItemDto implements Serializable {

public static final String F_NAME = "name";
Expand Down Expand Up @@ -54,7 +57,7 @@ public String getNewValue() {

public List<SceneItemLineDto> computeLines() {
List<SceneItemLineDto> rv = new ArrayList<>();
Collator collator = WebComponentUtil.getCollator();

if (!isDelta()) {
for (SceneItemValue itemValue : sceneItem.getNewValues()) {
rv.add(new SceneItemLineDto(this, null, itemValue, false));
Expand All @@ -68,16 +71,10 @@ public List<SceneItemLineDto> computeLines() {
List<? extends SceneItemValue> addedValues = deltaItem.getAddedValues();
Comparator<? super SceneItemValue> comparator =
(s1, s2) -> {
String value1 = s1 == null ? null : s1.getText();
String value2 = s2 == null ? null : s2.getText();
if (value1 == null && value2 == null) {
return 0;
} else if (value1 == null) {
return -1;
} else if (value2 == null) {
return 1;
}
return collator.compare(value1, value2);
PolyString value1 = s1 == null ? null : s1.getText();
PolyString value2 = s2 == null ? null : s2.getText();

return PolyStringComparator.COMPARE_TRANSLATED.compare(value1, value2);
};
deletedValues.sort(comparator);
addedValues.sort(comparator);
Expand All @@ -97,16 +94,11 @@ public List<SceneItemLineDto> computeLines() {
} else if (s2.isDelta()){
return -1;
}
String value1 = s1.getNewValue() == null ? null : s1.getNewValue().getText();
String value2 = s2.getNewValue() == null ? null : s2.getNewValue().getText();
if (value1 == null && value2 == null) {
return 0;
} else if (value1 == null) {
return -1;
} else if (value2 == null) {
return 1;
}
return collator.compare(value1, value2);

PolyString value1 = s1.getNewValue() == null ? null : s1.getNewValue().getText();
PolyString value2 = s2.getNewValue() == null ? null : s2.getNewValue().getText();

return PolyStringComparator.COMPARE_TRANSLATED.compare(value1, value2);
};
rv.sort(comparator);
return rv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.polystring.PolyString;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -95,7 +97,7 @@ public void onClick(AjaxRequestTarget target) {
link.add(visibleIfReference);
add(link);

final Label additionalText = new Label(ID_ADDITIONAL_TEXT, () -> getModelObject() != null ? getModelObject().getAdditionalText() : null);
final Label additionalText = new Label(ID_ADDITIONAL_TEXT, () -> getModelObject() != null ? WebComponentUtil.getTranslatedPolyString(getModelObject().getAdditionalText()) : null);
add(additionalText);
}

Expand Down Expand Up @@ -144,11 +146,16 @@ public String getObject() {
WebComponentUtil.getDisplayNameOrName(((Objectable) val.getSourceValue()).asPrismObject());
}
}
String textValue = getModelObject() != null ? getModelObject().getText() : null;
if (textValue != null && textValue.isEmpty()) {
textValue = createStringResource("SceneItemLinePanel.emptyLabel").getString();
PolyString textValue = getModelObject().getText();
if (textValue == null) {
return null;
}
return textValue;

if (textValue.getOrig().isEmpty()) {
return createStringResource("SceneItemLinePanel.emptyLabel").getString();
}

return WebComponentUtil.getTranslatedPolyString(textValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.web.util;

import java.text.Collator;
import java.util.Comparator;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.polystring.PolyString;

/**
* Created by Viliam Repan (lazyman).
*/
public class PolyStringComparator implements Comparator<PolyString> {

public static final PolyStringComparator COMPARE_TRANSLATED = new PolyStringComparator(true);

public static final PolyStringComparator COMPARE_ORIG = new PolyStringComparator(false);

private boolean translate;

public PolyStringComparator(boolean translate) {
this.translate = translate;
}

@Override
public int compare(PolyString o1, PolyString o2) {
if (o1 == null && o2 == null) {
return 0;
} else if (o1 == null) {
return -1;
} else if (o2 == null) {
return 1;
}

Collator collator = WebComponentUtil.getCollator();
String s1 = translate ? WebComponentUtil.getTranslatedPolyString(o1) : o1.getOrig();
String s2 = translate ? WebComponentUtil.getTranslatedPolyString(o2) : o2.getOrig();

return collator.compare(s1, s2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ private String translate(PolyStringTranslationType translation, Locale locale) {
String result;
List<PolyStringTranslationArgumentType> arguments = translation.getArgument();
if (arguments == null) {
result = translate(key, null, locale, key);
result = translate(key, null, locale, null);
} else {
result = translate(key, arguments.toArray(), locale, key);
result = translate(key, arguments.toArray(), locale, null);
}
if (result != null) {
return result;
} else {
return translateFromFallback(translation, locale, null);
return translateFromFallback(translation, locale, key);
}
}

Expand Down

0 comments on commit 95cfc4f

Please sign in to comment.