Merge branch 'release/5.8.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / CommonNameNamedAreaSelectionDialog.java
index e6d87905a40fad223a73c1926945853d48bd73ef..5a0fb678bdb318f4eac8ca5f217aabb980cf825f 100755 (executable)
@@ -16,11 +16,13 @@ import org.apache.commons.lang.StringUtils;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.term.TermType;
-import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -48,7 +50,7 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
     }
 
     private static UUID[] createVocabularyUuidList() {
-        String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.CommonNameAreaVocabularies.getKey());
+        String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.CommonNameAreaVocabularies.getKey(), false);
         if (StringUtils.isBlank(preselectedVocString)){
             return null;
         }
@@ -72,17 +74,23 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
 
         UUID[] preselectedVocabularyUuids = createVocabularyUuidList();
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
-        CdmPreference pref = cache.get(PreferencePredicate.CommonNameAreaVocabularies.getKey());
+        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.CommonNameAreaVocabularies);
+        CdmPreference pref = cache.findBestMatching(key);
+        if (preselectedVocabularyUuids != null){
+            for(int i=0;i<preselectedVocabularyUuids.length;i++){
+                TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
+                vocabularies.add(preselectedVocabulary);
+            }
+        }
         if ((pref != null && !pref.isAllowOverride()) && preselectedVocabularyUuids!=null) {
-                for(int i=0;i<preselectedVocabularyUuids.length;i++){
-                    TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
-                    vocabularies.add(preselectedVocabulary);
-                }
+             return vocabularies;
         }else{
-            vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
+            selectedVocabularies = vocabularies;
+
+            return CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
         }
 
-        return vocabularies;
+
     }
 
     /**
@@ -104,4 +112,6 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
                 "Choose an area", false, namedArea, preferenceId);
         return getSelectionFromDialog(dialog);
     }
+
+
 }