ref #5971: new main menu admin with cdm preference nomenclatural code and insert...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / PreferencesUtil.java
index 44662fe1699dc645538aed240925776d70aa96df..c17c9e4afcbdc494683a6733b858e824deed706d 100644 (file)
@@ -107,7 +107,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
         *            object.
         */
-       public static NomenclaturalCode setPreferredNomenclaturalCode(
+       public static CdmPreference setPreferredNomenclaturalCode(
                        NomenclaturalCode preferredCode, boolean local) {
            if (local){
                getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
@@ -129,7 +129,11 @@ public class PreferencesUtil implements IPreferenceKeys {
                                int index = StringUtils.lastIndexOf(preference.getValue(), ".");
                                UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
                                preferredCode = NomenclaturalCode.getByUuid(uuid);
-                               return preferredCode;
+
+                               getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY,
+                           getPreferenceKey(preferredCode));
+                               getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
+                               return preference;
                        }
                } else{
                        preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
@@ -137,7 +141,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
                }
            }
-        return preferredCode;
+        return null;
 
 
 
@@ -486,28 +490,36 @@ public class PreferencesUtil implements IPreferenceKeys {
 
                if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
                        PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP, true);
-                       /*
-
-                       StoreUtil.info("No nomencatural code set.");
-
-                       Shell shell = StoreUtil.getShell();
-
-                Query user re: preferred nom. code
-                       Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
-                       dialog.open();
-
-                       // Short message confirming user's choice
-                       NomenclaturalCode code = PreferencesUtil
-                                       .getPreferredNomenclaturalCode();
-                       MessageDialog
-                                       .openInformation(
-                                                       shell,
-                                                       "Nomenclatural code set",
-                                                       "The following has been set as your preferred nomenclatural code:\n\n\t"
-                                                                       + NomenclaturalCodeHelper
-                                                                                       .getDescription(code)
-                                                                       + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
                }
+
+
+
+       }
+       public static void setNomenclaturalCodePreferences(){
+       ICdmApplicationConfiguration controller;
+        controller = CdmStore.getCurrentApplicationConfiguration();
+        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+        CdmPreference preference = null;
+        if (controller == null){
+            return ;
+        }
+        preference = controller.getPreferenceService().find(key);
+        if (preference == null){
+            return;
+        }
+        getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
+
+        int index = StringUtils.lastIndexOf(preference.getValue(), ".");
+        UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
+        NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
+
+        getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY,
+                getPreferenceKey(preferredCode));
+
+        if (!preference.isAllowOverride()){
+            getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
+                    getPreferenceKey(preferredCode));
+        }
        }
 
        public static void checkDefaultLanguage(){