sort taxon nodes in taxon filter of DDS editor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / PreferencesUtil.java
index 21d19b53127a93c1ebc8068ded2f408565605dd9..2a2412bc40384137376eb6412cff64a319970ecb 100644 (file)
@@ -14,11 +14,11 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Field;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -27,7 +27,7 @@ import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.UUID;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.preferences.ConfigurationScope;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@@ -48,7 +48,9 @@ import eu.etaxonomy.cdm.api.service.ITermTreeService;
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
 import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
 import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
+import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
 import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.URI;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
@@ -57,9 +59,12 @@ import eu.etaxonomy.cdm.model.common.MarkerType;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
+import eu.etaxonomy.cdm.model.metadata.EnabledComputedDescription;
 import eu.etaxonomy.cdm.model.metadata.IPreferencePredicate;
 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
+import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
+import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingSwapEnum;
 import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
 import eu.etaxonomy.cdm.model.metadata.TermOrder;
 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
@@ -70,6 +75,10 @@ import eu.etaxonomy.cdm.model.term.TermTree;
 import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.cdm.model.term.VocabularyEnum;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByNameComparator;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByRankAndNameComparator;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoNaturalComparator;
 import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
 import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
 import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
@@ -79,7 +88,7 @@ import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
-import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
+import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.TermStore;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
@@ -107,6 +116,8 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     private static TermTree<Feature> preferredTaxonFeatureTree;
 
+
+
     private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
 
     public static IPreferenceStore getPreferenceStore() {
@@ -124,9 +135,11 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     public static String getPreferenceValue(PrefKey prefKey){
         try {
+            //check if there exist a node for the predicate
             if(getEditorPreferences().nodeExists(prefKey.getPredicate())){
                 Preferences predicateNode = getEditorPreferences().node(prefKey.getPredicate());
                 String[] splittedSubject = extractSubjectParts(prefKey.getSubject());
+                //check if the predicate node contains a node for the subject, this should be the last part
                 String value = predicateNode.get(splittedSubject[splittedSubject.length-1], PreferencePredicate.getByKey(prefKey.getPredicate()).getDefaultValue() != null? PreferencePredicate.getByKey(prefKey.getPredicate()).getDefaultValue().toString(): "");
                 int index = splittedSubject.length -2;
                 while (value != null && index >= 0){
@@ -145,7 +158,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     public static List<CdmPreference> getPreference(PreferencePredicate prefPredicate){
         try {
-            List<CdmPreference> prefs = new ArrayList();
+            List<CdmPreference> prefs = new ArrayList<>();
             CdmPreference pref;
             PreferenceSubject subject;
             if(getEditorPreferences().nodeExists(prefPredicate.getKey())){
@@ -159,9 +172,7 @@ public class PreferencesUtil implements IPreferenceKeys {
                     pref = CdmPreference.NewInstance(subject, prefPredicate, value);
                     prefs.add(pref);
                 }
-
             }
-
         } catch (BackingStoreException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
@@ -169,10 +180,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         return null;
     }
 
-    /**
-     * @param childName
-     * @param child
-     */
     private static String createSubjectStringForChildNodes(String subject, Preferences parent) {
         try {
             for (String childName: parent.childrenNames()){
@@ -189,7 +196,7 @@ public class PreferencesUtil implements IPreferenceKeys {
     }
 
     private static String prefKey(String name) {
-        return name + "_"+  ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
+        return name + "_"+  ((ICdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
     }
 
     public static String prefOverrideKey(String name) {
@@ -227,7 +234,6 @@ public class PreferencesUtil implements IPreferenceKeys {
     public static String getStringValue(String name, boolean local) {
 
         CdmPreference pref = getDBPreferenceValue(name);
-        String prefValue = null;
 
         boolean override = getOverrideForPreference(name);
 
@@ -244,13 +250,13 @@ public class PreferencesUtil implements IPreferenceKeys {
                  if (result instanceof String){
                      return (String)result;
                  }else{
-                     return result.toString();
+                     return result != null?result.toString(): null;
                  }
              }
             return pref.getValue();
         }
         //no override but default value
-        IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+        IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
         if (pred != null){
             if (pred.getDefaultValue() instanceof String){
                 return (String)pred.getDefaultValue();
@@ -259,9 +265,6 @@ public class PreferencesUtil implements IPreferenceKeys {
             }
         }
         return null;
-
-
-
     }
 
     public static String getStringValue(String name){
@@ -286,8 +289,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         try{
             result = Integer.parseInt(prefValue);
         }catch(NumberFormatException e){
-            logger.debug("Preference value of " + name + " is not a number");
-
+            logger.debug("Preference value of " + name + " is not an integer");
         }
 
         boolean override = getOverrideForPreference(name);
@@ -298,7 +300,7 @@ public class PreferencesUtil implements IPreferenceKeys {
             }
         }
         if (result == null){
-            IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+            IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
             if (pred != null){
                 if (pred.getDefaultValue() instanceof Integer){
                     result = (Integer)pred.getDefaultValue();
@@ -315,10 +317,8 @@ public class PreferencesUtil implements IPreferenceKeys {
             if (result == null){
                 result = 0;
             }
-
         }
         return result;
-
     }
 
     public static boolean getBooleanValue(String name) {
@@ -328,7 +328,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             return result;
         }
-
     }
 
     public static Boolean getBooleanValue(String name, boolean local) {
@@ -354,7 +353,7 @@ public class PreferencesUtil implements IPreferenceKeys {
                 return Boolean.valueOf(pref.getValue());
             }
             //no override but default value
-            IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+            IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
             if (pred != null){
                 if (pred.getDefaultValue() instanceof Boolean){
                     return (Boolean)pred.getDefaultValue();
@@ -367,11 +366,8 @@ public class PreferencesUtil implements IPreferenceKeys {
             // no connection to db, use local preference
             return getPreferenceStore().getBoolean(name);
         }
-
     }
 
-
-
     public static float getFloatValue(String name, boolean local) {
         CdmPreference pref = getDBPreferenceValue(name);
         String prefValue = null;
@@ -384,17 +380,17 @@ public class PreferencesUtil implements IPreferenceKeys {
                 result = Float.parseFloat(prefValue);
             }
         }catch(NumberFormatException e){
-            logger.debug("Preference value of " + name + " is not a number");
+            logger.debug("Preference value of " + name + " is not a float");
         }
 
         boolean override = getOverrideForPreference(name);
 
-        if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
+        if (local || pref == null || (pref.isAllowOverride() && override)){
             String dbSpecific = prefKey(name);
             if (getPreferenceStore().contains(dbSpecific)){
                 result = getPreferenceStore().getFloat(dbSpecific);
             }else{
-                IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+                IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
                 if (pred != null){
                     if (pred.getDefaultValue() instanceof Float){
                         return (float)pred.getDefaultValue();
@@ -406,11 +402,8 @@ public class PreferencesUtil implements IPreferenceKeys {
             }
         }
         return result;
-
     }
 
-
-
     public static CdmPreference setPreferredNomenclaturalCode(
             String preferenceValue, boolean local) {
         if (local){
@@ -448,9 +441,6 @@ public class PreferencesUtil implements IPreferenceKeys {
             }
         }
         return null;
-
-
-
     }
 
     public static void setPreferredNomenclaturalCode(
@@ -473,28 +463,12 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             controller.getPreferenceService().set(preference);
         }
-
     }
 
     public static NomenclaturalCode getPreferredNomenclaturalCode() {
 
-        CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
-
-
-        String preferredCode;
-        if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){
-            preferredCode = getStringValue(
-                    PreferencePredicate.NomenclaturalCode.getKey(), true);
-
-        }else{
-            preferredCode = pref.getValue();
-        }
-        if (StringUtils.isBlank(preferredCode)){
-            preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue());
-        }
-
-        return getPreferredNomenclaturalCode(preferredCode);
-
+        String nomString = getStringValue(PreferencePredicate.NomenclaturalCode.getKey());
+        return getPreferredNomenclaturalCode(nomString);
     }
 
     public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
@@ -527,7 +501,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         return result;
     }
 
-    public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
+    public static CdmPreference getPreferenceFromDB(IPreferencePredicate<?> predicate){
         ICdmRepository controller;
         CdmPreference pref = null;
 
@@ -542,10 +516,9 @@ public class PreferencesUtil implements IPreferenceKeys {
         }
 
         return pref;
-
     }
 
-    public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate predicate){
+    public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate<?> predicate){
         ICdmRepository controller;
         List<CdmPreference> prefs = null;
 
@@ -578,9 +551,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         }catch(Exception e){
             e.printStackTrace();
         }
-
-
-
     }
 
     public static CdmPreference getPreferenceFromDB(PrefKey key){
@@ -615,7 +585,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         }catch(Exception e){
             e.printStackTrace();
         }
-
     }
 
     public static String getPreferredDefaultLangugae(){
@@ -747,7 +716,7 @@ public class PreferencesUtil implements IPreferenceKeys {
      * @param cdmBase
      * @return
      */
-    public static String getPreferenceKey(ISimpleTerm simpleTerm) {
+    public static String getPreferenceKey(ISimpleTerm<?> simpleTerm) {
         simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
         String key = simpleTerm.getClass().getName().concat(".")
                 .concat(simpleTerm.getUuid().toString());
@@ -758,13 +727,8 @@ public class PreferencesUtil implements IPreferenceKeys {
         return key;
     }
 
-
-
     /**
      * Construct a unique key using the CdmBase object's uuid
-     *
-     * @param cdmBase
-     * @return
      */
     public static String getPreferenceKey(IDefinedTerm definedTerm) {
         definedTerm = HibernateProxyHelper.deproxy(definedTerm);
@@ -793,6 +757,10 @@ public class PreferencesUtil implements IPreferenceKeys {
                 IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_NAMES): true);
         configurator.setDoTaxaByCommonNames(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES)? PreferencesUtil.getPreferenceStore().getBoolean(
                 IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES): true);
+        configurator.setDoIncludeAuthors(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS)? PreferencesUtil.getPreferenceStore().getBoolean(
+                IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS): false);
+        configurator.setIncludeUnpublished(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_UNPUBLISHED)? PreferencesUtil.getPreferenceStore().getBoolean(
+                IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_UNPUBLISHED): true);
         //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
 
         return configurator;
@@ -812,7 +780,8 @@ public class PreferencesUtil implements IPreferenceKeys {
         configurator.setDoSynonyms(true);
         configurator.setDoNamesWithoutTaxa(true);
         configurator.setDoTaxaByCommonNames(true);
-
+        configurator.setIncludeUnpublished(true);
+        configurator.setDoIncludeAuthors(false);
         configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
                 "name", "name.$", "relationsFromThisTaxon.$"));
 
@@ -850,6 +819,10 @@ public class PreferencesUtil implements IPreferenceKeys {
                 configurator.isDoNamesWithoutTaxa());
         getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
                 configurator.isDoTaxaByCommonNames());
+        getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS,
+                configurator.isDoIncludeAuthors());
+        getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_UNPUBLISHED,
+                configurator.isIncludeUnpublished());
     }
 
     public static void firePreferencesChanged(Class clazz) {
@@ -860,11 +833,9 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     public static String createPreferenceString(String property){
        return prefKey(property);
-
     }
     public static String createOverridePreferenceString(String property){
            return prefOverrideKey(property);
-
     }
 
     public static boolean getOverrideForPreference(String preferenceString){
@@ -888,7 +859,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, true);
         getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_NAMES, true);
         getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, true);
-
+        getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS, false);
 
         //Name Details
        // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
@@ -919,7 +890,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey())), false);
         getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowModifier.getKey())), false);
         getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), false);
-
     }
 
     public static void checkNomenclaturalCode() {
@@ -927,10 +897,8 @@ public class PreferencesUtil implements IPreferenceKeys {
         if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
             PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
         }
-
-
-
     }
+
     public static void setNomenclaturalCodePreferences(){
         ICdmRepository controller;
         controller = CdmStore.getCurrentApplicationConfiguration();
@@ -951,7 +919,6 @@ public class PreferencesUtil implements IPreferenceKeys {
 
         setStringValue(PreferencePredicate.NomenclaturalCode.getKey(),
                 getPreferenceKey(preferredCode));
-
     }
 
     public static void checkDefaultLanguage(){
@@ -977,13 +944,13 @@ public class PreferencesUtil implements IPreferenceKeys {
         return false;
     }
 
-    public static TermTree getDefaultFeatureTreeForTextualDescription() {
+    public static TermTree<?> getDefaultFeatureTreeForTextualDescription() {
         String uuidString = getStringValue(
                 FEATURE_TREE_DEFAULT_TEXT, true);
         if (StringUtils.isBlank(uuidString)) {
             return null;
         }
-        TermTree tree = CdmStore.getService(
+        TermTree<?> tree = CdmStore.getService(
                 ITermTreeService.class).load(UUID.fromString(uuidString));
 
         if (tree == null || tree.getId() == 0) {
@@ -992,7 +959,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         return tree;
     }
 
-    public static TermTree getDefaultFeatureTreeForStructuredDescription() {
+    public static TermTree<?> getDefaultFeatureTreeForStructuredDescription() {
         String uuidString = getStringValue(
                 FEATURE_TREE_DEFAULT_STRUCTURE, true);
         return StringUtils.isBlank(uuidString) ? null : CdmStore.getService(
@@ -1014,7 +981,6 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     public static Language getGlobalLanguage() {
 
-
         String languageUuidString = getStringValue(
                 GLOBAL_LANGUAGE_UUID, true);
 
@@ -1037,19 +1003,17 @@ public class PreferencesUtil implements IPreferenceKeys {
             setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
             CdmStore.setDefaultLanguage(language);
         }
-
     }
 
     public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
         List<MarkerType> markerTypes = CdmStore.getTermManager()
                 .getPreferredTerms(MarkerType.class);
 
-        Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
+        Map<MarkerType, Boolean> result = new HashMap<>();
 
         for (MarkerType markerType : markerTypes) {
             String name = getMarkerTypeEditingPreferenceKey(markerType);
             Boolean value = getBooleanValue(name);
-
             result.put(markerType, value);
         }
 
@@ -1063,7 +1027,6 @@ public class PreferencesUtil implements IPreferenceKeys {
             setBooleanValue(name,
                     markerTypeEditingMap.get(markerType));
         }
-
     }
 
     private static String getMarkerTypeEditingPreferenceKey(
@@ -1168,8 +1131,6 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     /**
      * Retrieves a list of previously saved P2 repositories
-     *
-     * @return
      */
     public static List<MetadataRepositoryElement> getP2Repositories() {
         List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
@@ -1189,7 +1150,7 @@ public class PreferencesUtil implements IPreferenceKeys {
                         continue;
                     }
                     boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
-                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
+                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri.getJavaUri(), true);
                     mre.setNickname(nickname);
                     mre.setEnabled(enabled);
                     p2Repos.add(mre);
@@ -1223,45 +1184,58 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key);
         }
-
     }
 
     public static NavigatorOrderEnum getSortNodes() {
         return NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
-
     }
-
+    
     public static boolean isNodesSortedNaturally() {
         NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
         return value.equals(NavigatorOrderEnum.NaturalOrder);
-
     }
 
     public static boolean isNodesSortedByName() {
         NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
         return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
-
     }
 
     public static boolean isNodesSortedByNameAndRank() {
         NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
         return value.equals(NavigatorOrderEnum.RankAndNameOrder);
-
     }
+    
+    public static Comparator<TaxonNodeDto> getNodeComparator() {
+               Comparator<TaxonNodeDto> comparator;
+        NavigatorOrderEnum orderValue = NavigatorOrderEnum.RankAndNameOrder;
+               try{
+                   orderValue = PreferencesUtil.getSortNodes();
+               }catch(IllegalArgumentException e){
+
+               }
+
+               if (orderValue.equals(NavigatorOrderEnum.NaturalOrder)){
+                       comparator = new TaxonNodeDtoNaturalComparator();
+               } else if (orderValue.equals(NavigatorOrderEnum.AlphabeticalOrder)){
+                       comparator = new TaxonNodeDtoByNameComparator();
+               }else {
+                       comparator = new TaxonNodeDtoByRankAndNameComparator();
+               }
+               return comparator;
+       }
 
     public static boolean isStoreNavigatorState() {
         return getBooleanValue(RESTORE_NAVIGATOR_STATE);
-
     }
 
     public static void setStoreNavigatorState(boolean selection) {
         setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
-
     }
 
     public static boolean isShowUpWidgetIsDisposedMessages() {
        return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
     }
+
     public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
         setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
     }
@@ -1281,7 +1255,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             return false;
         }
-     }
+    }
     public static boolean isShowSymbol2InChecklistEditor() {
         String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
         if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
@@ -1289,7 +1263,8 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             return false;
         }
-     }
+    }
+
     public static void setAreaDisplayInChecklistEditor(String selection) {
         setStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
     }
@@ -1321,14 +1296,15 @@ public class PreferencesUtil implements IPreferenceKeys {
         }
        return result;
     }
+
     public static void setDisplayStatusInChecklistEditor(String selection) {
         setStringValue(PreferencePredicate.DisplayOfStatus.getKey(), selection);
-
     }
 
     public static boolean isShowRankInChecklistEditor() {
         return getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey());
     }
+
     public static void setShowRankInChecklistEditor(boolean selection) {
        setBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
     }
@@ -1408,8 +1384,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         else{
             setStringValue(PreferencePredicate.NameDetailsView.getKey(), config.toString());
         }
-
-
     }
 
     private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
@@ -1418,7 +1392,45 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             return true;
         }
+    }
+
+    public static void extractSecundumForSubtreeConfiguratorFromPreferenceString(SecundumForSubtreeConfigurator config,
+            String configString) {
+        if(configString != null){
+             String[] configArray = configString.split(";");
 
+             for (String configItem: configArray){
+                 String[] keyValue = configItem.split(":");
+                 String keyString = keyValue[0];
+                 String valueString = null;
+                 if (keyValue.length>1){
+                     valueString = keyValue[1];
+                     if (keyValue.length>2){
+
+                         for (int index = 2; index< keyValue.length; index++){
+                             valueString += ":"+ keyValue[index];
+                         }
+                     }
+                 }
+                 if (keyString.equals("includeAcceptedTaxa")){
+                     config.setIncludeAcceptedTaxa(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("includeSynonyms")){
+                     config.setIncludeSynonyms(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("includeSharedTaxa")){
+                     config.setIncludeSharedTaxa(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("includeProParteSynonyms")){
+                     config.setIncludeProParteSynonyms(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("includeMisapplications")){
+                     config.setIncludeMisapplications(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("overwriteExisting")){
+                     config.setOverwriteExisting(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("emptySecundumDetail")){
+                     config.setEmptySecundumDetail(Boolean.valueOf(valueString));
+                 }else{
+                     logger.debug("This key of the set secundum configurator needs to be added to the transformer: " + keyString);
+                 }
+             }
+         }
     }
 
     public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
@@ -1495,23 +1507,31 @@ public class PreferencesUtil implements IPreferenceKeys {
                      config.setRemoveCountryFromLocalityText(Boolean.valueOf(valueString));
                  }else if (keyString.equals("getSiblings")){
                      config.setGetSiblings(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("classificationUUID")){
+                     if (valueString != null){
+                         config.setClassificationUuid(UUID.fromString(valueString));
+                     }
+                 }else if (keyString.equals("classificationName")){
+                     config.setClassificationName(valueString);
                  }else if (keyString.equals("dnaSource")){
                      try{
-                         config.setDnaSoure(URI.create(valueString));
+                         if (StringUtils.isNotBlank(valueString)){
+                             config.setDnaSoure(URI.create(valueString));
+                         }
                      }catch(Exception e){
                          config.setDnaSoure(null);
                      }
                  }else{
                      logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
                  }
-
-
              }
          }
     }
+
     public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
         return getLocalAbcdImportConfigurator(true);
     }
+
     public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(boolean skipCheckOverride){
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
        CdmPreference pref = CdmPreferenceCache.instance().get(PreferencePredicate.AbcdImportConfig.getKey());
@@ -1552,7 +1572,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
         return config;
 
-     }
+    }
 
     public static void updateAbcdImportConfigurationPreference() {
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
@@ -1568,11 +1588,9 @@ public class PreferencesUtil implements IPreferenceKeys {
     public static void resetToDBPreferenceAbcdCOnfigurator(){
         Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference();
         setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), config.toString());
-
     }
 
     public static boolean isSortTaxaByRankAndName() {
-
         return getBooleanValue(PreferencePredicate.SortTaxaByRankAndName.getKey());
     }
 
@@ -1588,19 +1606,18 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) {
         setStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder);
-
     }
 
     public static void setLastSelectedReference(
             List<String> lastSelectedReferences) {
 
-        setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
+        setStringValue(IPreferenceKeys.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
     }
 
     public static List<String> getLastSelectedReferences() {
 
         //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
-        String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, true);
+        String lastSelected = getStringValue(IPreferenceKeys.LAST_SELECTED_REFERENCES, true);
         List<String> result = new ArrayList<>();
         if (!StringUtils.isBlank(lastSelected)){
             Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
@@ -1612,7 +1629,6 @@ public class PreferencesUtil implements IPreferenceKeys {
             String saveCheckedElements, String saveGrayedElements, boolean local) {
         if (local){
             setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
-
         }
         else{
             CdmPreference preference = null;
@@ -1637,7 +1653,6 @@ public class PreferencesUtil implements IPreferenceKeys {
 
             }
         }
-
     }
 
     public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
@@ -1647,7 +1662,6 @@ public class PreferencesUtil implements IPreferenceKeys {
             setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride);
         }
         else{
-            ICdmRepository controller;
             CdmPreference preference = null;
 
             if (saveCheckedElements == null){
@@ -1668,7 +1682,6 @@ public class PreferencesUtil implements IPreferenceKeys {
                 setPreferenceToDB(preference);
                 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
                         saveCheckedElements);
-
             }
         }
     }
@@ -1687,7 +1700,6 @@ public class PreferencesUtil implements IPreferenceKeys {
             } else{
                 return preference.getValue();
             }
-
         }
     }
 
@@ -1705,7 +1717,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
     public static List<UUID> createUuidList(String prefValue) {
         String[] stringArray = prefValue.split(";");
-        List<UUID> uuidList = new ArrayList();
+        List<UUID> uuidList = new ArrayList<>();
         for (String uuid: stringArray){
             if (!StringUtils.isBlank(uuid)){
                 uuidList.add(UUID.fromString(uuid));
@@ -1715,55 +1727,36 @@ public class PreferencesUtil implements IPreferenceKeys {
     }
 
     public static boolean getFilterCommonNameReferences(){
-        Boolean result = getBooleanValue(PreferencePredicate.CommonNameReferencesWithMarker.getKey());
-        if (result == null){
-            return false;
-        }
-        return result;
+        return getBooleanValue(PreferencePredicate.CommonNameReferencesWithMarker.getKey());
     }
 
     public static void updateDBPreferences() {
 
-
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
         cache.getAllTaxEditorDBPreferences();
 
-        //ABCD Configurator
-
-        //updateAbcdImportConfigurationPreference();
-
         //Name Details
         NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
-        //    if (config != null ){
-        //        if (!getBooleanValue(OVERRIDE_NAME_DETAILS) ||  !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
-        //            setPreferredNameDetailsConfiguration(config, false);
-        //        }
-        //    }
 
     }
 
     public static void setPreferencesToDB(List<CdmPreference> preferences) {
 
         ICdmRepository controller;
-        //try{
-            if(CdmStore.isActive()){
-                controller = CdmStore.getCurrentApplicationConfiguration();
-                for (CdmPreference preference: preferences){
-                    if (preference.getValue() == null && preference.isAllowOverride()){
-                        controller.getPreferenceService().remove(preference.getKey());
-
-                    }else{
-                        controller.getPreferenceService().set(preference);
+        if(CdmStore.isActive()){
+            controller = CdmStore.getCurrentApplicationConfiguration();
+            for (CdmPreference preference: preferences){
+                if (preference.getValue() == null && preference.isAllowOverride()){
+                    controller.getPreferenceService().remove(preference.getKey());
 
-                    }
+                }else{
+                    controller.getPreferenceService().set(preference);
 
                 }
-                CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
 
             }
-        /*}catch(Exception e){
-            e.printStackTrace();
-        }*/
+            CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
+        }
     }
 
     /**
@@ -1778,20 +1771,19 @@ public class PreferencesUtil implements IPreferenceKeys {
     /**
      *
      */
-    public static TermTree getPreferredFeatureTreeForNameDescription(boolean createNew) {
+    public static TermTree<?> getPreferredFeatureTreeForNameDescription(boolean createNew) {
         if(preferredNameFeatureTree != null && !createNew){
             return preferredNameFeatureTree;
         }
         createPreferredFeatureTreeForNameDescription();
         return preferredNameFeatureTree;
-
     }
 
     public static void createPreferredFeatureTreeForNameDescription() {
 
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
         CdmPreference pref = cache.get(PreferencePredicate.NameFeatures.getKey());
-        List<Feature> terms = new ArrayList();
+        List<Feature> terms = new ArrayList<>();
         boolean override = PreferencesUtil.getOverrideForPreference(PreferencePredicate.NameFeatures.getKey());
 
         List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.NameFeatures.getKey(), false);
@@ -1799,12 +1791,8 @@ public class PreferencesUtil implements IPreferenceKeys {
             terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
         }
 
-
-
-
        if (terms.isEmpty()){
            terms.addAll(TermStore.getTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()), null));
-
         }
         terms.remove(Feature.PROTOLOGUE());
         if (terms.isEmpty()){
@@ -1812,13 +1800,8 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             preferredNameFeatureTree = TermTree.NewInstance(terms);
         }
-
-
     }
 
-    /**
-     * @param prefsToDelete
-     */
     public static void removeFromDB(List<CdmPreference> prefsToDelete) {
         ICdmRepository controller;
         //try{
@@ -1829,10 +1812,8 @@ public class PreferencesUtil implements IPreferenceKeys {
                 }
                 CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
             }
-
     }
 
-
     public static void removeFromDB(CdmPreference prefToDelete) {
         ICdmRepository controller;
 
@@ -1842,18 +1823,14 @@ public class PreferencesUtil implements IPreferenceKeys {
 
             CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
         }
-
     }
-    /**
-     * @return
-     */
+
     public static TermTree<?> getPreferredFeatureTreeForTaxonDescription(boolean createNew) {
         if(preferredTaxonFeatureTree != null && !createNew){
             return preferredTaxonFeatureTree;
         }
         createPreferredFeatureTreeForTaxonDescription();
         return preferredTaxonFeatureTree;
-
     }
 
     public static void createPreferredFeatureTreeForTaxonDescription() {
@@ -1879,18 +1856,77 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             preferredTaxonFeatureTree = TermTree.NewInstance(terms);
         }
+    }
 
+    public static void setLastSelectedBiocaseProvider(String lastAccessPoint) {
+        setStringValue(LAST_USED_BIOCASE_PROVIDER, lastAccessPoint);
+    }
 
+    /**
+     * @return
+     */
+    public static boolean getLocalActive() {
+        // TODO: this needs to be adapted!!!
+        return true;
     }
 
     /**
-     * @param lastAccessPoint
+     * @return
      */
-    public static void setLastSelectedBiocaseProvider(String lastAccessPoint) {
-        setStringValue(LAST_USED_BIOCASE_PROVIDER, lastAccessPoint);
+    public static boolean showGfbioMetaData() {
+        //TODO: needs to be adapted!!!
+        return false;
+    }
+
+    public static SecReferenceHandlingEnum getSecReferenceHandlingPreference(){
+
+        String defaultBehaviour = getStringValue(PreferencePredicate.DefaultBehaviourForSecundum.getKey());
+        SecReferenceHandlingEnum handling = null;
+        try{
+            handling = SecReferenceHandlingEnum.valueOf(defaultBehaviour);
+        }catch(IllegalArgumentException e){
+            handling = (SecReferenceHandlingEnum)PreferencePredicate.DefaultBehaviourForSecundum.getDefaultValue();
+        }
+        return handling;
+
+    }
+
+    public static SecReferenceHandlingSwapEnum getSecReferenceHandlingSwapPreference(){
+        String defaultBehaviour = getStringValue(PreferencePredicate.DefaultBehaviourForSecundumWhenSwap.getKey());
+        SecReferenceHandlingSwapEnum handling = null;
+        try{
+            handling = SecReferenceHandlingSwapEnum.valueOf(defaultBehaviour);
+        }catch (IllegalArgumentException e){
+            handling = (SecReferenceHandlingSwapEnum)PreferencePredicate.DefaultBehaviourForSecundumWhenSwap.getDefaultValue();
+        }
+        return handling;
+
     }
 
+    public static EnabledComputedDescription getComputedDesciptionHandlingPreference(){
+        String defaultBehaviour= getStringValue(PreferencePredicate.EnableComputedDescription.getKey());
+        EnabledComputedDescription computedDescriptionsEnabled = (EnabledComputedDescription)PreferencePredicate.EnableComputedDescription.getDefaultValue();
+        if (StringUtils.isNotBlank(defaultBehaviour)){
+            try{
+                computedDescriptionsEnabled = EnabledComputedDescription.byKey(defaultBehaviour);
+            }catch(IllegalArgumentException e){
+                //do nothing, keep default value;
+            }
+        }
+        return computedDescriptionsEnabled;
 
+    }
 
+    public static boolean isComputedDesciptionHandlingDisabled(){
+        String defaultBehaviour= getStringValue(PreferencePredicate.EnableComputedDescription.getKey());
+        EnabledComputedDescription computedDescriptionsEnabled = null;
+        try{
+            computedDescriptionsEnabled = EnabledComputedDescription.byKey(defaultBehaviour);
+        }catch (IllegalArgumentException e){
+            computedDescriptionsEnabled = (EnabledComputedDescription)PreferencePredicate.EnableComputedDescription.getDefaultValue();
+        }
+        return computedDescriptionsEnabled.equals(EnabledComputedDescription.Disabled);
+
+    }
 
 }