commit b74a2730b3ce8c7215357058adf0a6d31ad55fc6
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Jun 27 13:47:37 2019 +0200

    ref #7920: fix delete of preferences

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 fed0283bb..6f06d07b1 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
@@ -675,7 +675,7 @@ public class ChecklistEditorGeneralPreference extends CdmPreferencePage implemen
             }else{
                 isEditorActivated = PreferencesUtil.getBooleanValue(PreferencePredicate.DistributionEditorActivated.getKey(), true);
             }
-            //distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ?  PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
+            distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ?  PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
         }
 
         prefAreaVoc = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
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 f6c9db49c..7cf619fd4 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
@@ -581,7 +581,11 @@ public class PreferencesUtil implements IPreferenceKeys {
         try{
             if(CdmStore.isActive()){
                 controller = CdmStore.getCurrentApplicationConfiguration();
-                controller.getPreferenceService().set(preference);
+                if (preference.getValue() == null && preference.isAllowOverride()){
+                    controller.getPreferenceService().remove(preference.getKey());
+                }else{
+                    controller.getPreferenceService().set(preference);
+                }
                 CdmPreferenceCache.instance().put(preference);
             }
         }catch(Exception e){
@@ -1711,7 +1715,11 @@ public class PreferencesUtil implements IPreferenceKeys {
             if(CdmStore.isActive()){
                 controller = CdmStore.getCurrentApplicationConfiguration();
                 for (CdmPreference preference: preferences){
-                    controller.getPreferenceService().set(preference);
+                    if (preference.getValue() == null && preference.isAllowOverride()){
+                        controller.getPreferenceService().remove(preference.getKey());
+                    }else{
+                        controller.getPreferenceService().set(preference);
+                    }
                     CdmPreferenceCache.instance().put(preference);
                 }
             }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractTermSelectionWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractTermSelectionWizardPage.java
index 37e78a049..4ee35e65d 100755
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractTermSelectionWizardPage.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractTermSelectionWizardPage.java
@@ -128,7 +128,7 @@ public abstract class AbstractTermSelectionWizardPage extends WizardPage {
             }
         }
         if (listValue.isEmpty()){
-            List<DefinedTermBase> terms = CdmStore.getTermManager().getPreferredTerms(type);
+            List<DefinedTermBase> terms = CdmStore.getTermManager().getAllTerms(type, null);
             for (DefinedTermBase term: terms){
                 termlist.add(TermDto.fromTerm(term, true));
             }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusPage.java
index 0df394f3c..f8695b9ec 100755
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusPage.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusPage.java
@@ -52,6 +52,7 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
 public class AvailableDistributionPerAreaStatusPage extends AvailableDistributionStatusPage implements IPropertyChangeListener{
 
     List<CdmPreference> perAreaPreferences = new ArrayList();
+    List<CdmPreference> perAreaPreferencesDeleteList = new ArrayList();
     List<TermVocabularyDto> vocs;
     NamedArea actualArea;
     CdmPreference actualPref;
@@ -155,7 +156,6 @@ public class AvailableDistributionPerAreaStatusPage extends AvailableDistributio
             @Override
             public void widgetSelected(SelectionEvent e) {
 
-
                 PrefKey key = newAreaSpecificStatusPreference();
                 actualPref = PreferenceResolver.resolve(perAreaPreferences, key);
                 actualPref = CdmPreference.NewInstance(key, null);
@@ -163,7 +163,9 @@ public class AvailableDistributionPerAreaStatusPage extends AvailableDistributio
                 perAreaPreferences.add(actualPref);
                 status.setText("Preference for area " + actualArea.getLabel() + " removed.");
                 status.setVisible(true);
+
                 actualArea = null;
+
                 areaText.setText("");
                 rememberCheckedValues(getCheckedValuesFromPreferences());
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusWizard.java
index 9df20cc96..0e2c68d50 100755
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusWizard.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusWizard.java
@@ -39,6 +39,7 @@ public class AvailableDistributionPerAreaStatusWizard extends Wizard implements
         // TODO if preferenceStore has elements checked load elements in wizard
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
         prefs = new ArrayList<>();
+        cache.getAllTaxEditorDBPreferences();
         List<CdmPreference> distrPrefs = cache.getAllForPredicate(PreferencePredicate.AvailableDistributionStatus.getKey());
         if (distrPrefs != null){
             prefs.addAll(distrPrefs);
@@ -91,6 +92,7 @@ public class AvailableDistributionPerAreaStatusWizard extends Wizard implements
         aPage.refreshActualPrefernce();
         PreferencesUtil.setPreferencesToDB(aPage.perAreaPreferences);
         PreferencesUtil.setPreferenceToDB(aPage.pref);
+
        // PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.AvailableDistributionStatus.getKey()), aPage.override);
         PreferencesUtil.firePreferencesChanged(this.getClass());
         return true;
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/TermManager.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/TermManager.java
index b88f63d12..ea0a9a24f 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/TermManager.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/TermManager.java
@@ -56,7 +56,7 @@ public class TermManager {
 	 */
 	public <T extends DefinedTermBase> List<T> getPreferredTerms(TermType termType){
 	    List terms = cachedTermMap.get(termType);
-	    if(terms==null){
+	    if(terms==null || terms.isEmpty()){
 	        terms = getFilteredTerms(TermStore.<T>getTerms(termType, null));
 	        cachedTermMap.put(termType, terms);
 	    }
