ref #10398: make it configurable how the specimen/taxon rel should be
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / PreferencesUtil.java
index de23ec49eacc7d09c1c7f9edd57a26d0cfdaf33d..194a5edc4ee897af88681a4f4a1a7e4c4265ba37 100644 (file)
@@ -6,7 +6,6 @@
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
-
 package eu.etaxonomy.taxeditor.preference;
 
 import java.io.File;
@@ -18,6 +17,7 @@ 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,22 +27,19 @@ import java.util.StringTokenizer;
 import java.util.UUID;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.eclipse.core.runtime.preferences.ConfigurationScope;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
 import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.window.Window;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.application.ICdmRepository;
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
-import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.api.service.ITermTreeService;
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
 import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
@@ -50,58 +47,60 @@ 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.facade.DerivedUnitFacadeConfigurator;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
-import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
 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.DistributionDescription;
 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;
 import eu.etaxonomy.cdm.model.term.IDefinedTerm;
 import eu.etaxonomy.cdm.model.term.ISimpleTerm;
-import eu.etaxonomy.cdm.model.term.TermBase;
 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;
 import eu.etaxonomy.cdm.strategy.match.MatchException;
 import eu.etaxonomy.cdm.strategy.match.MatchMode;
 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.ICdmRemoteSource;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.TermStore;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
-import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
 
 /**
- * <p>
- * PreferencesUtil class.
- * </p>
- *
  * @author p.ciardelli
  * @author n.hoffmann
  * @created 05.12.2008
  */
 public class PreferencesUtil implements IPreferenceKeys {
+
+    private final static Logger logger = LogManager.getLogger(PreferencesUtil.class);
+
     private final static String EDITOR_PREFERENCES_NODE = "eu.etaxonomy.taxeditor";
 
     public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
-
+    public static final String UPDATE_NAVIGATOR = "update_navigator";
     public static final String P2_REPOSITORIES_DELIM = ",";
     public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
     public static final String SUBJECT_DELIM = "/";
@@ -111,9 +110,6 @@ public class PreferencesUtil implements IPreferenceKeys {
     private static TermTree<Feature> preferredTaxonFeatureTree;
 
 
-
-    private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
-
     public static IPreferenceStore getPreferenceStore() {
        return TaxeditorStorePlugin.getDefault().getPreferenceStore();
     }
@@ -589,6 +585,27 @@ public class PreferencesUtil implements IPreferenceKeys {
         return null;
     }
 
+    public static Language getPreferredDefaultLanguage(){
+        
+        String prop = System.getProperty("osgi.nl");
+        if (prop.startsWith("de")) {
+            return Language.GERMAN();
+        }else {
+            return Language.ENGLISH();
+        }
+//        String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR, true);
+//        if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
+//            if (preferredLanguage.equals(Language.uuidEnglish.toString())) {
+//             return Language.ENGLISH();
+//            }else if (preferredLanguage.equals(Language.uuidGerman.toString())) {
+//             return Language.GERMAN();
+//            }else {
+//             return Language.ENGLISH();
+//            }
+//        }
+//        return Language.getDefaultLanguage();
+    }
+
     public static boolean isShowMediaPreview(){
         boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW, true);
         return isShowMediaPreview;
@@ -676,45 +693,14 @@ public class PreferencesUtil implements IPreferenceKeys {
         return pattern;
     }
 
-    public static <T extends TermBase> void addTermToPreferredTerms(T term) {
-
-        // VocabularyEnum vocabulary =
-        // VocabularyEnum.getVocabularyEnum(term.getClass());
-        //
-        // getPreferenceStore().setValue(getPreferenceKey(term),
-        // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
-        //
-        // firePreferencesChanged(term.getClass());
-    }
-
-    /**
-     * Construct a unique key using the CdmBase object's uuid
-     *
-     * @param cdmBase
-     * @return
-     */
-    private static String getPreferenceKey(ICdmBase cdmBase) {
-        cdmBase = HibernateProxyHelper.deproxy(cdmBase);
-
-        String key = cdmBase.getClass().getName().concat(".")
-                .concat(cdmBase.getUuid().toString());
-        if (key.contains("javassist")) {
-            MessagingUtils.info("proxy");
-        }
-        return key;
-    }
-
     /**
      * Construct a unique key using the CdmBase object's uuid
-     *
-     * @param cdmBase
-     * @return
      */
     public static String getPreferenceKey(ISimpleTerm<?> simpleTerm) {
         simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
         String key = simpleTerm.getClass().getName().concat(".")
                 .concat(simpleTerm.getUuid().toString());
-        if (key.contains("javassist")) {
+        if (key.contains("javassist")) { //Note by AM (2022-06): javassist is not used anymore, instead hibernate uses bytebuddy which is not contained in class names so this logging will not work anymore
             MessagingUtils.warn(PreferencesUtil.class,
                     "Trying to persist a preference based on a proxy class.");
         }
@@ -728,7 +714,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         definedTerm = HibernateProxyHelper.deproxy(definedTerm);
         String key = definedTerm.getClass().getName().concat(".")
                 .concat(definedTerm.getUuid().toString());
-        if (key.contains("javassist")) {
+        if (key.contains("javassist")) { //Note by AM (2022-06): javassist is not used anymore, instead hibernate uses bytebuddy which is not contained in class names so this logging will not work anymore
             MessagingUtils.warn(PreferencesUtil.class,
                     "Trying to persist a preference based on a proxy class.");
         }
@@ -824,6 +810,11 @@ public class PreferencesUtil implements IPreferenceKeys {
                 null, clazz);
     }
 
+    public static void firePreferencesChangedForNavigator() {
+        getPreferenceStore().firePropertyChangeEvent(UPDATE_NAVIGATOR,
+                null, null);
+    }
+
 
     public static String createPreferenceString(String property){
        return prefKey(property);
@@ -915,18 +906,18 @@ public class PreferencesUtil implements IPreferenceKeys {
                 getPreferenceKey(preferredCode));
     }
 
-    public static void checkDefaultLanguage(){
-        if(PreferencesUtil.getPreferredDefaultLangugae() == null){
-           Shell shell = AbstractUtility.getShell();
-           int open = new DefaultLanguageDialog(shell).open();
-           if(open == Window.OK){
-               PlatformUI.getWorkbench().restart();
-           }
-        }else{
-            //TODO:In case of a reinstall, the config.ini will be overwritten
-            //     here you create config.ini with the stored key from preferences
-        }
-    }
+//    public static void checkDefaultLanguage(){
+//        if(PreferencesUtil.getPreferredDefaultLangugae() == null){
+//           Shell shell = AbstractUtility.getShell();
+//           int open = new DefaultLanguageDialog(shell).open();
+//           if(open == Window.OK){
+//               PlatformUI.getWorkbench().restart();
+//           }
+//        }else{
+//            //TODO:In case of a reinstall, the config.ini will be overwritten
+//            //     here you create config.ini with the stored key from preferences
+//        }
+//    }
 
     public static String getMapServiceAccessPoint() {
         return getStringValue(PreferencePredicate.EditMapServiceAccessPoint.getKey());
@@ -976,26 +967,35 @@ public class PreferencesUtil implements IPreferenceKeys {
     public static Language getGlobalLanguage() {
 
         String languageUuidString = getStringValue(
-                GLOBAL_LANGUAGE_UUID, true);
+                PreferencePredicate.TermLanguage.getKey(), true);
 
-        if(!CdmStore.isActive()) {
-            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
-            return null;
-        }
+        CdmPreference dbPref = getDBPreferenceValue(PreferencePredicate.TermLanguage.getKey());
 
-        if (CdmUtils.isBlank(languageUuidString)) {
-            return Language.getDefaultLanguage();
+        if (dbPref == null || (dbPref != null && dbPref.isAllowOverride() && getOverrideForPreference(PreferencePredicate.TermLanguage.getKey()))) {
+            if (CdmUtils.isBlank(languageUuidString)) {
+                return Language.getDefaultLanguage();
+            }else {
+                return Language.getLanguageFromUuid(UUID.fromString(languageUuidString));
+            }
+        }else {
+            languageUuidString = dbPref.getValue();
         }
-
         UUID languageUuid = UUID.fromString(languageUuidString);
-        return (Language) CdmStore.getService(ITermService.class).load(
-                languageUuid);
+        Language language = (Language)CdmApplicationState.getTermProxy().load(languageUuid);
+        if (language != null){
+            return language;
+        }else{
+            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
+            return null;
+        }
     }
 
     public static void setGlobalLanguage(Language language) {
         if(language != null) {
-            setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
+            setStringValue(PreferencePredicate.TermLanguage.getKey(),language.getUuid().toString());
             CdmStore.setDefaultLanguage(language);
+        }else {
+            CdmStore.setDefaultLanguage(Language.getDefaultLanguage());
         }
     }
 
@@ -1050,26 +1050,29 @@ public class PreferencesUtil implements IPreferenceKeys {
      * @param setLanguage 0 is for german and 1 for english.
      * @throws IOException
      */
-    public void writePropertyToConfigFile(int setLanguage) throws IOException {
+    public static void writePropertyToConfigFile(int setLanguage) throws IOException {
         File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
         //give warning to user if the directory has no write access
         if(file == null){
             throw new IOException();
         }
-        Properties properties = load(file.getAbsolutePath()+"/config.ini");
+        Properties properties;
+        properties = load(file.getAbsolutePath()+"/config.ini");
         switch(setLanguage){
         case 0:
             properties.setProperty("osgi.nl", "de");
-            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
+            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, Language.uuidGerman.toString());
             break;
         case 1:
             properties.setProperty("osgi.nl", "en");
-            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
+            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, Language.uuidEnglish.toString());
             break;
         default:
             break;
         }
         save(file+"/config.ini", properties);
+        
+        
     }
 
     /**
@@ -1079,7 +1082,7 @@ public class PreferencesUtil implements IPreferenceKeys {
      * @return
      * @throws IOException
      */
-    private Properties load(String filename) throws IOException {
+    private static Properties load(String filename) throws IOException {
         FileInputStream in = new FileInputStream(filename);
         Properties prop = new Properties();
         prop.load(in);
@@ -1094,7 +1097,7 @@ public class PreferencesUtil implements IPreferenceKeys {
      * @param properties
      * @throws IOException
      */
-    private void save(String filename, Properties properties) throws IOException{
+    private static void save(String filename, Properties properties) throws IOException{
         FileOutputStream fos =  new FileOutputStream(filename);
         properties.store(fos, "");
         fos.close();
@@ -1199,6 +1202,25 @@ public class PreferencesUtil implements IPreferenceKeys {
         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);
     }
@@ -1244,12 +1266,19 @@ public class PreferencesUtil implements IPreferenceKeys {
         setStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
     }
 
-    public static void setOwnDescriptionForChecklistEditor(boolean selection) {
-        setBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
+    public static void setDescriptionForChecklistEditor(DistributionDescription selection) {
+        setStringValue(PreferencePredicate.DescriptionForDistributionEditor.getKey(), selection.getKey());
     }
 
-    public static boolean isOwnDescriptionForChecklistEditor() {
-        return getBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
+    public static DistributionDescription getDescriptionForChecklistEditor() {
+        String str =  getStringValue(PreferencePredicate.DescriptionForDistributionEditor.getKey());
+        DistributionDescription result = null;
+        try {
+            result = DistributionDescription.byKey(str);
+        }catch(IllegalArgumentException e) {
+            result = (DistributionDescription)PreferencePredicate.DescriptionForDistributionEditor.getDefaultValue();
+        }
+        return result;
     }
 
     public static TermDisplayEnum displayAreaInChecklistEditor() {
@@ -1448,8 +1477,10 @@ public class PreferencesUtil implements IPreferenceKeys {
                  }
                  if (keyString.equals("ignoreImportOfExistingSpecimen")){
                      config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
-                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
-                     config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("addIndividualsAssociations")){
+                     config.setAddIndividualsAssociations(Boolean.valueOf(valueString));
+                 }else if (keyString.equals("addDeterminations")){
+                     config.setAddDeterminations(Boolean.valueOf(valueString));
                  }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
                      config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
                  }else if (keyString.equals("ignoreAuthorship")){
@@ -1533,20 +1564,19 @@ public class PreferencesUtil implements IPreferenceKeys {
     public static Abcd206ImportConfigurator getLastUsedAbcdImportConfigurator(){
         Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
 
-       String configString = PreferencesUtil.getStringValue(IPreferenceKeys.LAST_USED_ABCD_CONFIG, true);
-       if (configString != null){
-           extractAbcdConfiguratorFromPreferenceString(config, configString);
-           if (config != null){
-               if (config.getNomenclaturalCode() == null){
-                   config.setNomenclaturalCode(getPreferredNomenclaturalCode());
-               }
-           }
-       }else{
-           config = PreferencesUtil.getLocalAbcdImportConfigurator(false);
-       }
+        String configString = PreferencesUtil.getStringValue(IPreferenceKeys.LAST_USED_ABCD_CONFIG, true);
+        if (configString != null){
+            extractAbcdConfiguratorFromPreferenceString(config, configString);
+            if (config != null){
+                if (config.getNomenclaturalCode() == null){
+                    config.setNomenclaturalCode(getPreferredNomenclaturalCode());
+                }
+            }
+        }else{
+            config = PreferencesUtil.getLocalAbcdImportConfigurator(false);
+        }
 
         return config;
-
     }
 
     public static void updateAbcdImportConfigurationPreference() {
@@ -1556,7 +1586,6 @@ public class PreferencesUtil implements IPreferenceKeys {
 
         if (!getBooleanValue(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
             resetToDBPreferenceAbcdCOnfigurator();
-
         }
     }
 
@@ -1618,14 +1647,12 @@ public class PreferencesUtil implements IPreferenceKeys {
                             saveCheckedElements);
                     preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
                     setPreferenceToDB(preference);
-
                 }
             } else{
                 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
                 setPreferenceToDB(preference);
                 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
                         saveCheckedElements);
-
             }
         }
     }
@@ -1702,11 +1729,7 @@ 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() {
@@ -1716,7 +1739,6 @@ public class PreferencesUtil implements IPreferenceKeys {
 
         //Name Details
         NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
-
     }
 
     public static void setPreferencesToDB(List<CdmPreference> preferences) {
@@ -1727,12 +1749,9 @@ public class PreferencesUtil implements IPreferenceKeys {
             for (CdmPreference preference: preferences){
                 if (preference.getValue() == null && preference.isAllowOverride()){
                     controller.getPreferenceService().remove(preference.getKey());
-
                 }else{
                     controller.getPreferenceService().set(preference);
-
                 }
-
             }
             CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
         }
@@ -1747,10 +1766,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         return getPreferenceStore().contains(prefKey(prefKey));
     }
 
-    /**
-     *
-     */
-    public static TermTree<?> getPreferredFeatureTreeForNameDescription(boolean createNew) {
+    public static TermTree<Feature> getPreferredFeatureTreeForNameDescription(boolean createNew) {
         if(preferredNameFeatureTree != null && !createNew){
             return preferredNameFeatureTree;
         }
@@ -1777,7 +1793,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         if (terms.isEmpty()){
             preferredNameFeatureTree = TermEditorInput.getDefaultNameFeatureTree();
         }else{
-            preferredNameFeatureTree = TermTree.NewInstance(terms);
+            preferredNameFeatureTree = TermTree.NewFeatureInstance(terms);
         }
     }
 
@@ -1833,7 +1849,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         if (terms.isEmpty()){
             preferredTaxonFeatureTree = TermEditorInput.getDefaultFeatureTree();
         }else{
-            preferredTaxonFeatureTree = TermTree.NewInstance(terms);
+            preferredTaxonFeatureTree = TermTree.NewFeatureInstance(terms);
         }
     }
 
@@ -1858,8 +1874,26 @@ public class PreferencesUtil implements IPreferenceKeys {
     }
 
     public static SecReferenceHandlingEnum getSecReferenceHandlingPreference(){
+
         String defaultBehaviour = getStringValue(PreferencePredicate.DefaultBehaviourForSecundum.getKey());
-        SecReferenceHandlingEnum handling = SecReferenceHandlingEnum.valueOf(defaultBehaviour);
+        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;
 
     }