handle terms without idInVoc in NomenclaturalStatusType comparator
authorKatja Luther <k.luther@bgbm.org>
Thu, 2 May 2019 13:06:36 +0000 (15:06 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 2 May 2019 13:06:36 +0000 (15:06 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NomenclaturalStatusElement.java

index 7afbe1c1cd6a1a13d0175f7ed1280af298bb16d9..290afe6425a8c281e0f82ed29675b474eed86e3e 100644 (file)
@@ -14,10 +14,10 @@ import java.util.Comparator;
 import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.term.TermVocabulary;
-import eu.etaxonomy.cdm.model.term.VocabularyEnum;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
+import eu.etaxonomy.cdm.model.term.VocabularyEnum;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
@@ -52,7 +52,23 @@ public class NomenclaturalStatusElement extends AbstractReferencedEntityElement<
        public void createControls(ICdmFormElement element, int style) {
            TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
 
-           Comparator<NomenclaturalStatusType> termComparator= (NomenclaturalStatusType t1, NomenclaturalStatusType t2) -> t1.getIdInVocabulary().compareTo(t2.getIdInVocabulary());
+           Comparator<NomenclaturalStatusType> termComparator= new Comparator<NomenclaturalStatusType>() {
+
+            @Override
+            public int compare(NomenclaturalStatusType t1, NomenclaturalStatusType t2) {
+                if (t1.getIdInVocabulary() == t2.getIdInVocabulary()){
+                    return 0;
+                }
+                if (t1.getIdInVocabulary() == null ){
+                    return t1.getLabel().compareTo(t2.getIdInVocabulary());
+                }
+                if (t2.getIdInVocabulary() == null){
+                    return t1.getIdInVocabulary().compareTo(t2.getLabel());
+                }
+                return t1.getIdInVocabulary().compareTo(t2.getIdInVocabulary());
+            }
+        };
+
                nomenclaturalStatusTypeCombo = formFactory.createDefinedTermComboElement(vocabulary, this, "Status", null,true, style, true);
                nomenclaturalStatusTypeCombo.setTermComparator(termComparator);
                ruleConsideredText = formFactory.createTextWithLabelElement(this, "Rule Considered", "", style);