Skip to content
Snippets Groups Projects
Commit 1a73b424 authored by Simon Barner's avatar Simon Barner
Browse files

Keep Combo values (EENum literals, EReference objects) sorted

* Use TreeMap for return value

Issue-Ref: 4092
Issue-Url: af3#4092



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent 5ff9f142
No related branches found
No related tags found
1 merge request!1474092: Implement a JFX controller for the creation and visualization of reference lists
This commit is part of merge request !147. Comments created here will be created in the context of that merge request.
AnnotationFxViewPart.java ca1548c49aa3842a9436262531464ba345b83688 GREEN
AnnotationTreeTableUIProvider.java 9efdeb7261cafe9dfe763daf20af186c906c3ec3 YELLOW
AnnotationViewFXController.java 7d62ea076e87b14c4916935d3466168503c83c6f YELLOW
AnnotationViewFXController.java c2b3e6a1cbffae55b88bff93418fa5797585d75d YELLOW
AnnotationsFXUtils.java e180d593b69b1e4b90adf83ba47753b29f9d6ff8 YELLOW
ColumnHandle.java 7b0fe536d4eb9faa63c4d812f0c078cf83d0fd42 GREEN
FXAnnotationFilterContentProvider.java ca4587ef5dce1288ee4d7bf3bea5bd544ce6b89e GREEN
......@@ -18,7 +18,6 @@ package org.fortiss.tooling.base.ui.annotation.view.fx;
import static java.util.Collections.emptyMap;
import static java.util.Collections.sort;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.getValueLabel;
import static org.fortiss.tooling.base.ui.annotation.view.fx.FXAnnotationFilterContentProvider.HIERARCHY_LEVELS_ALL;
import static org.fortiss.tooling.base.ui.annotation.view.fx.FXAnnotationFilterContentProvider.HIERARCHY_LEVELS_CURRENT;
......@@ -29,15 +28,18 @@ import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstParentWithType
import static org.fortiss.tooling.kernel.utils.LoggingUtils.showWarning;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
......@@ -451,9 +453,21 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
EClassifier eType = featureDescriptor.getEType(specification);
if(eType instanceof EEnum) {
EList<EEnumLiteral> allLiterals = ((EEnum)eType).getELiterals();
return allLiterals.stream().collect(toMap(l -> l.getInstance(), l -> l.getLiteral()));
Map<Object, String> rval = new TreeMap<>(new Comparator<Object>() {
@Override
public int compare(Object e1, Object e2) {
return Integer.compare(((Enumerator)e1).getValue(),
((Enumerator)e2).getValue());
}
});
for(EEnumLiteral lit : featureDescriptor.getEnumLiterals((EEnum)eType, modelElement)) {
rval.put(lit.getInstance(), lit.getLiteral());
}
return rval;
} else if(eType instanceof EClass) {
EObject root = featureDescriptor.getValueRootElement(modelElement);
......@@ -461,19 +475,22 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
return emptyMap();
}
EList<EObject> values = new BasicEList<EObject>();
EList<EObject> refValues = new BasicEList<EObject>();
if(featureDescriptor.getEReferenceScope() == EReferenceScope.SUB_MODEL) {
values.add(root);
refValues.add(root);
}
Class<? extends EObject> clazz = (Class<? extends EObject>)eType.getInstanceClass();
for(EObject obj : getChildrenWithType(root, clazz)) {
if(featureDescriptor.isAvailableObject(obj, specification, modelElement)) {
values.add(obj);
refValues.add(obj);
}
}
sort(values, new HierarchicalNameComparator());
return values.stream().collect(toMap(v -> v, v -> getValueLabel(v, root)));
Map<Object, String> rval = new TreeMap<>(new HierarchicalNameComparator());
for(EObject obj : refValues) {
rval.put(obj, getValueLabel(obj, root));
}
return rval;
}
return emptyMap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment