ref #8398 adapting taxeditor to changes in NameRelationship
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NomenclaturalStatusElement.java
index 5945778b80fbe427a195719d63eb44f13d6718d3..3d850d620b931b479f0ec43750955211b3cea344 100644 (file)
@@ -9,15 +9,14 @@
 
 package eu.etaxonomy.taxeditor.ui.section.name;
 
 
 package eu.etaxonomy.taxeditor.ui.section.name;
 
+import java.util.Comparator;
+
 import org.eclipse.swt.events.SelectionListener;
 
 import org.eclipse.swt.events.SelectionListener;
 
-import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
-import eu.etaxonomy.cdm.model.common.VocabularyEnum;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -30,7 +29,6 @@ import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractReferencedEntityEl
 /**
  * @author n.hoffmann
  * @created Nov 5, 2009
 /**
  * @author n.hoffmann
  * @created Nov 5, 2009
- * @version 1.0
  */
 public class NomenclaturalStatusElement extends AbstractReferencedEntityElement<NomenclaturalStatus> implements IEntityElement<NomenclaturalStatus>, ISelectableElement{
 
  */
 public class NomenclaturalStatusElement extends AbstractReferencedEntityElement<NomenclaturalStatus> implements IEntityElement<NomenclaturalStatus>, ISelectableElement{
 
@@ -49,15 +47,41 @@ public class NomenclaturalStatusElement extends AbstractReferencedEntityElement<
        /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement element, int style) {
        /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement element, int style) {
-           TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
-               nomenclaturalStatusTypeCombo = formFactory.createDefinedTermComboElement(vocabulary, this, "Status", null,false, style, true);
+           //TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
+
+           Comparator<NomenclaturalStatusType> termComparator= new Comparator<NomenclaturalStatusType>() {
+
+            @Override
+            public int compare(NomenclaturalStatusType t1, NomenclaturalStatusType t2) {
+                if (t1 == t2){
+                    return 0;
+                }
+                if (t1 == null){
+                    return -1;
+                }
+                if (t2 == null){
+                    return 1;
+                }
+                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(TermType.NomenclaturalStatusType, this, "Status", null,true, style, true);
+               nomenclaturalStatusTypeCombo.setTermComparator(termComparator);
                ruleConsideredText = formFactory.createTextWithLabelElement(this, "Rule Considered", "", style);
 
                super.createControls(element, style);
                ruleConsideredText = formFactory.createTextWithLabelElement(this, "Rule Considered", "", style);
 
                super.createControls(element, style);
-               if (vocabulary.getTerms().contains(NomenclaturalStatusType.ILLEGITIMATE()) && getEntity().getType() == null){
-            nomenclaturalStatusTypeCombo.setSelection(NomenclaturalStatusType.ILLEGITIMATE());
-            getEntity().setType(nomenclaturalStatusTypeCombo.getSelection());
-        }
+
        }
 
        /** {@inheritDoc} */
        }
 
        /** {@inheritDoc} */
@@ -66,6 +90,7 @@ public class NomenclaturalStatusElement extends AbstractReferencedEntityElement<
                super.setEntity(entity);
                if (entity.getType() != null){
                    nomenclaturalStatusTypeCombo.setSelection(entity.getType());
                super.setEntity(entity);
                if (entity.getType() != null){
                    nomenclaturalStatusTypeCombo.setSelection(entity.getType());
+                   nomenclaturalStatusTypeCombo.removeEmptyElement();
                }
                ruleConsideredText.setText(entity.getRuleConsidered());
        }
                }
                ruleConsideredText.setText(entity.getRuleConsidered());
        }