ref #7810 Fix creation of local specimen preferences
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / SpecimenAdminPreferences.java
index 3906f843209e39cfb59fc0af3cdf26b55bd1b291..1304e5fb203af27387ee478a6bbabf49dd806168 100755 (executable)
@@ -25,6 +25,7 @@ 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.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -46,6 +47,7 @@ public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4Ad
     boolean isShowLifeForm;
     boolean isUseLocalPreference;
     Composite composite;
+    CdmPreference isShowSpecimenPref = null;
 
     @Override
     protected Control createContents(Composite parent) {
@@ -142,7 +144,7 @@ public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4Ad
              @Override
              public void widgetSelected(SelectionEvent e) {
                  isUseLocalPreference = useLocalPreference.getSelection();
-
+                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SPECIMEN_ALLOW_OVERRIDE, isUseLocalPreference);
               }
          });
         return composite;
@@ -163,34 +165,35 @@ public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4Ad
         ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
         if (controller != null){
             IPreferenceService service = controller.getPreferenceService();
-            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewEditorInstance(), PreferencePredicate.ShowSpecimen);
-            CdmPreference isShowSpecimenPref = service.find(key);
+            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
+            isShowSpecimenPref = service.find(key);
             if (isShowSpecimenPref != null){
                 this.isShowSpecimenRelatedIssues = Boolean.valueOf(isShowSpecimenPref.getValue());
             }else{
+                isShowSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(true));
                 this.isShowSpecimenRelatedIssues = true;
             }
 
 
-            key = CdmPreference.NewKey(PreferenceSubject.NewEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
+            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
             CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
             if (isShowCollectingAreaInGeneralSectionPref != null){
                 this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
             }
 
-            key = CdmPreference.NewKey(PreferenceSubject.NewEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
+            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
             CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
             if (isDeterminationOnlyForFieldUnitsPref != null){
                 this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
             }
-            key = CdmPreference.NewKey(PreferenceSubject.NewEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
+            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
             CdmPreference isShowTaxonAssociationPref = service.find(key);
             if (isShowTaxonAssociationPref != null){
                 this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
-                isUseLocalPreference = isShowTaxonAssociationPref.isAllowOverride();
+               // isUseLocalPreference = isShowTaxonAssociationPref.isAllowOverride();
             }
 
-            key = CdmPreference.NewKey(PreferenceSubject.NewEditorInstance(), PreferencePredicate.ShowLifeForm);
+            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
             CdmPreference isShowLifeFormPref = service.find(key);
             if (isShowLifeFormPref != null){
                 this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
@@ -204,26 +207,29 @@ public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4Ad
 
     @Override
      public boolean performOk() {
+        if (isShowSpecimenPref == null){
+            return true;
+        }
         ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
         if (controller != null){
             IPreferenceService service = controller.getPreferenceService();
 
-            CdmPreference pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
+            CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
             pref.setAllowOverride(isUseLocalPreference);
             service.set(pref);
-            pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
+            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
             pref.setAllowOverride(isUseLocalPreference);
             service.set(pref);
 
-            pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
+            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
             pref.setAllowOverride(isUseLocalPreference);
             service.set(pref);
 
-            pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
+            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
             pref.setAllowOverride(isUseLocalPreference);
             service.set(pref);
 
-            pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
+            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
             pref.setAllowOverride(isUseLocalPreference);
             service.set(pref);
             PreferencesUtil.updateDBPreferences();