commit b32cbeab9266e20daa3f8c65ce4aad1729d98554
Author: Katja Luther <k.luther@bgbm.org>
Date:   Mon Aug 21 14:14:56 2017 +0200

    fix #6918: use comparator in rank combobox if sortRankHierarchically is set

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java
index 0956e31db..8f0d39a2d 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java
@@ -42,6 +42,18 @@ public class TermComboElement<T extends DefinedTermBase>
 
 	private Comparator<T> termComparator;
 
+	public Comparator<T> getTermComparator() {
+		return termComparator;
+	}
+
+	public void setTermComparator(Comparator<T> termComparator) {
+		this.termComparator = termComparator;
+		List<T> termsWithoutNull = terms.subList(1, terms.size());
+		
+		populateTerms(termsWithoutNull);
+		
+	}
+
 	private final TermType termType;
 	private final TermVocabulary termVocabulary;
 	private final Class<T> termClass;
@@ -53,31 +65,31 @@ public class TermComboElement<T extends DefinedTermBase>
 
 	public TermComboElement(CdmFormFactory formFactory,
 			ICdmFormElement parentElement, TermType termType, String labelString, T selection, boolean addEmptyElement,
-			int style, boolean useAbbrevLabel) {
-		this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+			int style, boolean useAbbrevLabel, Comparator<T> comparator) {
+		this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
 	}
 
 	public TermComboElement(CdmFormFactory formFactory,
 	        ICdmFormElement parentElement, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
-	        int style, boolean useAbbrevLabel) {
-	    this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+	        int style, boolean useAbbrevLabel, Comparator<T> comparator) {
+	    this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
 	}
 
     public TermComboElement(CdmFormFactory formFactory,
             ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
             int style) {
-        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, false);
+        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, false, null);
     }
     public TermComboElement(CdmFormFactory formFactory,
             ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
             int style, boolean useAbbrevLabel) {
-        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
 
     }
 
 	private TermComboElement(CdmFormFactory formFactory,
 	        ICdmFormElement parentElement, Class<T> termClass, TermType termType, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
-	        int style, boolean useAbbrevLabel) {
+	        int style, boolean useAbbrevLabel, Comparator<T> comparator) {
         super(formFactory, parentElement);
 
         this.termType = termType;
@@ -85,6 +97,7 @@ public class TermComboElement<T extends DefinedTermBase>
         this.termClass = termClass;
         this.addEmptyElement = addEmptyElement;
         this.useAbbrevLabel = useAbbrevLabel;
+        this.termComparator = comparator;
         if (labelString != null) {
             label.setText(labelString);
         }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
index 665f266ce..892059181 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
@@ -52,6 +52,7 @@ import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.agent.Team;
 import eu.etaxonomy.cdm.model.common.Annotation;
+import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Credit;
 import eu.etaxonomy.cdm.model.common.DefinedTerm;
@@ -919,8 +920,9 @@ public class CdmFormFactory extends FormToolkit {
             ICdmFormElement parentElement,
             String labelString,
             T selection,
-            int style) {
-        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, true, style, false);
+            int style, 
+            Comparator<T> comparator) {
+        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, true, style, false, comparator);
     }
 
     public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
@@ -930,7 +932,16 @@ public class CdmFormFactory extends FormToolkit {
 			T selection,
 			boolean addEmptyElement,
 			int style) {
-        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, false);
+        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, false, null);
+	}
+    
+	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
+			TermType termType,
+			ICdmFormElement parentElement,
+			String labelString,
+			T selection, 
+			int style) {
+		return  this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, true, style, false, null);
 	}
     public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
 			TermType termType,
@@ -940,7 +951,7 @@ public class CdmFormFactory extends FormToolkit {
 			boolean addEmptyElement,
 			int style,
 			boolean useAbbrevLabel) {
-		return createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+		return createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
 	}
 
 
@@ -950,7 +961,7 @@ public class CdmFormFactory extends FormToolkit {
             String labelString,
             T selection,
             int style) {
-        return this.createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, true, style, false);
+        return this.createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, true, style, false, null);
     }
 
 	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
@@ -961,7 +972,7 @@ public class CdmFormFactory extends FormToolkit {
 	        boolean addEmptyElement,
 	        int style,
 	        boolean useAbbrevLabel) {
-	    return createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+	    return createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
 	}
 
 	private <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
@@ -972,15 +983,22 @@ public class CdmFormFactory extends FormToolkit {
 	        T selection,
 	        boolean addEmptyElement,
 	        int style,
-	        boolean useAbbrevLabel) {
+	        boolean useAbbrevLabel,
+	        Comparator<T> comparator) {
 	    if(termType!=null){
-	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
+	        if (comparator!= null){
+	        	element.setTermComparator(comparator);
+	        }
 	        adapt(element);
 	        parentElement.addElement(element);
 	        return element;
 	    }
 	    else if(termVocabulary!=null){
-	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
+	        if (comparator!= null){
+	        	element.setTermComparator(comparator);
+	        }
 	        adapt(element);
 	        parentElement.addElement(element);
 	        return element;
@@ -3005,6 +3023,8 @@ public class CdmFormFactory extends FormToolkit {
         return section;
     }
 
+
+
 //	public RichTextWithLabelElement createRichTextLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int textHeight, int style) {
 //		 RichTextWithLabelElement element = new RichTextWithLabelElement(this, parentElement, labelString,
 //				 initialText, textHeight, style);
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameDetailElement.java
index dc8e0e3d7..169dc7dd4 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameDetailElement.java
@@ -11,6 +11,7 @@ package eu.etaxonomy.taxeditor.ui.section.name;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Comparator;
 
 import org.apache.log4j.Logger;
 import org.eclipse.swt.SWT;
@@ -77,10 +78,21 @@ public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<I
 	/** {@inheritDoc} */
 	@Override
 	protected void createControls(ICdmFormElement formElement, INonViralName nonViralName, int style) {
+		Comparator<Rank> comparator = null;
+		if(PreferencesUtil.getSortRanksHierarchichally()){
+			comparator = new Comparator<Rank>(){
 
+			@Override
+			public int compare(Rank o1, Rank o2) {
+				return o2.compareTo(o1);
+			}
+
+		};
+		}
 	    if (isAdvancedView){
 	    	toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
-	    	combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
+	    	
+	    	combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style, comparator);
 	    	createGenusOrUninomialControls(this, nonViralName, style);
             createInfragenerericEpithetControls(this, nonViralName, style);
             createSpecificEpithetControls(this, nonViralName, style);
@@ -93,7 +105,7 @@ public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<I
         	}
 
     	    if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK)){
-    	        combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
+    	        combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style, comparator);
     	    }
 
     		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS)){
