Commit e1e518d7 authored by Thomas Huster's avatar Thomas Huster
Browse files

[23279] fix findings templates comparator on selection dialog

parent 9ba99bd8
Pipeline #22831 passed with stages
in 4 minutes and 12 seconds
......@@ -14,5 +14,6 @@ Require-Bundle: ch.elexis.core.findings;bundle-version="1.0.0",
ch.elexis.core;bundle-version="3.3.0",
ch.elexis.core.data;bundle-version="3.3.0"
Bundle-ActivationPolicy: lazy
Import-Package: org.slf4j
Import-Package: org.apache.commons.lang3;version="3.7.0",
org.slf4j
Service-Component: OSGI-INF/ch.elexis.core.findings.templates.service.FindingsTemplateService.xml
......@@ -13,6 +13,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.URI;
......@@ -83,8 +84,12 @@ public class FindingsTemplateService implements IFindingsTemplateService {
Optional<FindingsTemplates> loaded = loadFindingsTemplates(blob.get());
if (loaded.isPresent()) {
// sort templates alphabetically
ECollections.sort(loaded.get().getFindingsTemplates(),
(l, r) -> l.getTitle().compareTo(r.getTitle()));
ECollections.sort(loaded.get().getFindingsTemplates(), (l, r) -> {
if (l == null || r == null) {
return l != null ? 1 : -1;
}
return ObjectUtils.compare(l.getTitle(), r.getTitle());
});
return loaded.get();
}
}
......
......@@ -2,7 +2,6 @@ package ch.elexis.core.findings.templates.ui.dlg;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
......@@ -177,8 +176,7 @@ public class FindingsSelectionDialog extends TitleAreaDialog {
List<FindingsTemplate> templatesTemp = null;
if (current != null) {
if (current.getInputData() instanceof InputDataGroupComponent)
{
if (current.getInputData() instanceof InputDataGroupComponent) {
// remove component selections
templatesTemp = model.getFindingsTemplates().stream()
.filter(item -> !(item.getInputData() instanceof InputDataGroup
......@@ -191,16 +189,12 @@ public class FindingsSelectionDialog extends TitleAreaDialog {
templatesTemp.add(findingsTemplate);
}
}
}
else {
} else {
// remove self selection
templatesTemp = model.getFindingsTemplates().stream()
.filter(item -> !item.equals(current))
.collect(Collectors.toList());
.filter(item -> !item.equals(current)).collect(Collectors.toList());
}
}
else {
} else {
templatesTemp = model.getFindingsTemplates();
}
......@@ -208,26 +202,25 @@ public class FindingsSelectionDialog extends TitleAreaDialog {
eTemplates.addAll(templatesTemp);
// sort
ECollections.sort(eTemplates, new Comparator<FindingsTemplate>() {
@Override
public int compare(FindingsTemplate o1, FindingsTemplate o2){
if (o1 == null || o2 == null) {
return o1 != null ? 1 : -1;
}
else if (o1.getInputData() instanceof InputDataGroup) {
return -1;
} else if (o2.getInputData() instanceof InputDataGroup) {
return 1;
}
else if (o1.getInputData() instanceof InputDataGroupComponent) {
return -1;
ECollections.sort(eTemplates, (l, r) -> {
if (l == null || r == null) {
return l != null ? 1 : -1;
}
int titleCompare =
ObjectUtils.compare(l.getTitle().toLowerCase(), r.getTitle().toLowerCase());
if (l.getInputData() instanceof InputDataGroup
|| r.getInputData() instanceof InputDataGroup) {
if (l.getInputData().getClass() != r.getInputData().getClass()) {
return l.getInputData() instanceof InputDataGroup ? -1 : 1;
}
else if (o2.getInputData() instanceof InputDataGroupComponent) {
return 1;
}
if (l.getInputData() instanceof InputDataGroupComponent
|| r.getInputData() instanceof InputDataGroupComponent) {
if (l.getInputData().getClass() != r.getInputData().getClass()) {
return l.getInputData() instanceof InputDataGroupComponent ? -1 : 1;
}
return ObjectUtils.compare(o1.getTitle(), o2.getTitle());
}
return titleCompare;
});
}
viewer.setInput(eTemplates);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment