commit bfbad836db8ce91707b8eb8e30a01c42ea99e5e4
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Feb 8 13:18:50 2018 +0100

    ref #7234: add possibility to sort named areas by vocabulary order in distribution editor

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistLabelProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistLabelProvider.java
index ade92dbd6..dfd0b565c 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistLabelProvider.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistLabelProvider.java
@@ -11,6 +11,7 @@ package eu.etaxonomy.taxeditor.editor.view.checklist;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -31,8 +32,10 @@ import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.OrderedTermComparator;
 import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator;
 import eu.etaxonomy.cdm.model.common.TermLanguageComparator;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
@@ -136,7 +139,7 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
                             }else{
                                 area = distribution.getArea().getTitleCache();
                             }
-                           
+
                         }else{
                             continue;
                         }
@@ -166,6 +169,7 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
 
     private SortedSet<DefinedTermBase> loadNamedAreas() {
         IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
+
         String values = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS);
 
         if (values != null && values != "") { //$NON-NLS-1$
@@ -181,9 +185,11 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
             }
             ITermService service = CdmStore.getService(ITermService.class);
             termlist = service.find(uuidList);
-            if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
+            if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){
+                return getTermsOrderedByVocabularyOrder(termlist);
+            } else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
                 return getTermsOrderedByIdInVocabulary(termlist);
-            } else {
+            }else{
                 return getTermsOrderedByLabels(termlist, CdmStore.getDefaultLanguage());
             }
         }
@@ -200,6 +206,16 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
         return result;
     }
 
+    public SortedSet<DefinedTermBase> getTermsOrderedByVocabularyOrder(List<DefinedTermBase> listAreas){
+        HashMap<TermVocabulary<DefinedTermBase>, List<DefinedTermBase>> vocs = new HashMap<>();
+        OrderedTermComparator<?> comp = new OrderedTermComparator<>();
+
+        SortedSet<DefinedTermBase> result = new TreeSet(comp.reversed());
+        result.addAll(listAreas);
+
+        return result;
+    }
+
     /**
      * @return the namedAreas
      */
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
index 09a00437d..61bf228ff 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
@@ -84,7 +84,7 @@ public class ChecklistEditorGeneralPreference extends PreferencePage implements
                 PreferencesUtil.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary);
              }
         });
-        
+
         final Button showSymbol = new Button(child, SWT.CHECK);
         boolean isShowSymbol = PreferencesUtil.isShowSymbolInChecklistEditor();
         showSymbol.setText("Show Symbol of the Status, if existing");
@@ -108,7 +108,17 @@ public class ChecklistEditorGeneralPreference extends PreferencePage implements
                 PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
             }
         });
-
+        final Button sortNamedAreaByVocabularyOrder = new Button(child, SWT.CHECK);
+        boolean isSortByVocabularyOrder = PreferencesUtil.isSortNamedAreaByOrderInVocabulary();
+        sortNamedAreaByVocabularyOrder.setText("Sort Areas by Order in Vocabulary");
+        sortNamedAreaByVocabularyOrder.setSelection(isSortByVocabularyOrder);
+        sortNamedAreaByVocabularyOrder.addSelectionListener(new SelectionAdapter(){
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                boolean isSortByVocabularyOrder = sortNamedAreaByVocabularyOrder.getSelection();
+                PreferencesUtil.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder);
+             }
+        });
 
         if(isEditorActivated){
             child.setEnabled(true);
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
index 5fe767f82..82b5ce51f 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
@@ -207,6 +207,7 @@ public interface IPreferenceKeys {
     public static final String ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN= "eu.etaxonomy.taxeditor.abcd_import_configurator.overwriteExistingSpecimens";
     public static final String ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR = "eu.etaxonomy.taxeditor.abcd_import_configurator.defaultAuthor";
     public static final String ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID =  "eu.etaxonomy.taxeditor.abcd_import_configurator.classificationUuid";
+    public static final String ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE = "eu.etaxonomy.taxeditor.abcd_import_configurator.nomenclaturalCode";
     public static final String ALLOW_OVERRIDE_ABCD_IMPORT_CONFIG = "eu.etaxonomy.taxeditor.abcd_import_configurator.allowOverride";
 
 
@@ -220,6 +221,8 @@ public interface IPreferenceKeys {
     public static final String SHOW_ADVANCED_MEDIA_SECTION = "eu.etaxonomy.taxeditor.media.showAdvancedMedia";
     public static final String SHOW_MEDIA_PREVIEW = "eu.etaxonomy.taxeditor.media.showMediaPreview";
     public static final String SORT_TAXA_BY_RANK_AND_NAME = "eu.etaxonomy.taxeditor.selection.taxa.sortByRankAndName";
+    public static final String SORT_NAMED_AREA_BY_VOCABULARY_ORDER = "eu.etaxonomy.taxeditor.distribution.namedArea.sortByVocabularyOrder";
+
 
 
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
index e097b1414..20abb8631 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
@@ -1166,6 +1166,7 @@ public class PreferencesUtil implements IPreferenceKeys {
             config.setReuseExistingDescriptiveGroups(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
             config.setReuseExistingMetaData(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
             config.setReuseExistingTaxaWhenPossible(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
+            config.setNomenclaturalCode(NomenclaturalCode.getByKey(PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
             return config;
 
         }
@@ -1300,6 +1301,19 @@ public static boolean isSortTaxaByRankAndName() {
     return getPreferenceStore().getBoolean(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
 }
 
+/**
+ * @return
+ */
+public static boolean isSortNamedAreaByOrderInVocabulary() {
+
+    return getPreferenceStore().getBoolean(IPreferenceKeys.SORT_NAMED_AREA_BY_VOCABULARY_ORDER);
+}
+
+public static void setSortNamedAreasByOrderInVocabulary(boolean isSortByVocabularyOrder) {
+    getPreferenceStore().setValue(IPreferenceKeys.SORT_NAMED_AREA_BY_VOCABULARY_ORDER, isSortByVocabularyOrder);
+
+}
+
 
 
 }
