Merge branch 'release/5.8.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / SpecimenOrObservationPreferences.java
index e7fa8a7770b9c4adebdf675dfee77e5799b0dcf4..950a37c33dbf9d5ba415a1822b99ea4268478ca7 100644 (file)
@@ -11,14 +11,18 @@ package eu.etaxonomy.taxeditor.preference;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
 
 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.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -28,39 +32,44 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @date 13.02.2014
  *
  */
-public class SpecimenOrObservationPreferences extends CdmPreferencePage {
+public class SpecimenOrObservationPreferences extends CdmPreferencePage implements SelectionListener{
 
     private static final String LOCAL_SETTINGS_NOT_ALLOWED = Messages.SpecimenOrObservationPreferences_0;
     private static final String DESCRIPTION = Messages.SpecimenOrObservationPreferences_1;
 
-    protected boolean isShowSpecimenRelatedIssues;
+    protected Boolean isShowSpecimenRelatedIssues;
     protected boolean allowOverrideShowSpecimenRelatedIssues;
     protected boolean overrideShowSpecimenRelatedIssues;
-    protected boolean isShowCollectingAreaInGeneralSection;
+    protected Boolean isShowCollectingAreaInGeneralSection;
     protected boolean allowOverrideShowCollectingAreaInGeneralSection;
     protected boolean overrideShowCollectionAreaInGeneralSection;
-    protected boolean isDeterminationOnlyForFieldUnits;
+    protected Boolean isDeterminationOnlyForFieldUnits;
     protected boolean allowOverrideDeterminationOnlyForFieldUnits;
     protected boolean overrideDeterminationOnlyForFieldUnits;
-    protected boolean isShowTaxonAssociation;
+    protected Boolean isShowTaxonAssociation;
     protected boolean allowOverrideShowTaxonAssociation;
     protected boolean overrideShowTaxonAssociation;
-    protected boolean isShowLifeForm;
+    protected Boolean isShowLifeForm;
     protected boolean allowOverrideShowLifeForm;
     protected boolean overrideShowLifeForm;
     Composite composite;
 
-    protected Button showSpecimenButton;
+    protected Combo showSpecimenButton;
     protected Button allowOverrideIsShowSpecimenRelatedIssuesButton;
-    protected Button showCollectingAreaInGeneralSectionButton;
+    protected Combo showCollectingAreaInGeneralSectionButton;
     protected Button allowOverrideShowCollectingAreaButton;
-    protected Button determinationOnlyForFieldUnitsButton;
+    protected Combo determinationOnlyForFieldUnitsButton;
     protected Button allowOverridesDeterminationOnlyForFieldUnitsButton;
-    protected Button showTaxonAssociationButton;
+    protected Combo showTaxonAssociationButton;
     protected Button allowOverrideIsShowTaxonAssociationButton;
     protected Button allowOverrideShowLifeFormButton;
-    protected Button showLifeFormButton;
+    protected Combo showLifeFormButton;
 
+    CdmPreference showSpecimenPref;
+    CdmPreference showCollectingAreaInGeneralSection;
+    CdmPreference showDeterminationOnlyForFieldUnits;
+    CdmPreference showTaxonAssociation;
+    CdmPreference showLifeForm;
 
     @Override
     public void init() {
@@ -83,48 +92,53 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
         boolean isEditingAllowed = true;
         if(!isAdminPreference){
             CdmPreferenceCache cache = CdmPreferenceCache.instance();
-            CdmPreference showSpecimenPref = cache.get(PreferencePredicate.ShowSpecimen.getKey());
+
             if (showSpecimenPref != null){
                 if (!showSpecimenPref.isAllowOverride() ){
-                    Label label = new Label(parent, SWT.NONE);
-                    label.setText(LOCAL_SETTINGS_NOT_ALLOWED);
+
                     isEditingAllowed = false;
 
                 }
             }
         }
-
-        Label label = new Label(parent, SWT.NONE);
-        label.setText(DESCRIPTION);
+        if (isEditingAllowed){
+            Label label = new Label(parent, SWT.NONE);
+            label.setText(DESCRIPTION);
+        }else{
+            Label label = new Label(parent, SWT.NONE);
+            label.setText(LOCAL_SETTINGS_NOT_ALLOWED);
+            this.noDefaultAndApplyButton();
+            return parent;
+        }
         Composite titleComp = createComposite(parent);
         GridData gridData = createTextGridData();
 
         Label separator= new Label(titleComp, SWT.HORIZONTAL | SWT.SEPARATOR);
         separator.setLayoutData(gridData);
         separator.setVisible(false);
-        showSpecimenButton = new Button(titleComp, SWT.CHECK);
-
-        showSpecimenButton.setText(Messages.DatabasePreferncesPage_Show_Specimen);
-
-        showSpecimenButton.setSelection(isShowSpecimenRelatedIssues);
-        showSpecimenButton.addSelectionListener(new SelectionAdapter(){
-             @Override
-             public void widgetSelected(SelectionEvent e) {
-                 setApply(true);
-                 isShowSpecimenRelatedIssues = showSpecimenButton.getSelection();
-//                 if(isShowSpecimenRelatedIssues){
-//                     //composite.setVisible(true);
-//                     composite.setEnabled(true);
-//                 }else{
-//                     //composite.setVisible(false);
-//                     composite.setEnabled(false);
-//                 }
-              }
-         });
-        allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
-
+        showSpecimenButton = createBooleanCombo(titleComp, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowSpecimen, Messages.DatabasePreferncesPage_Show_Specimen, isAdminPreference);
+
+        showSpecimenButton.addSelectionListener(this);
+        int index = 0;
+        for (String itemLabel : showSpecimenButton.getItems()) {
+            if (isShowSpecimenRelatedIssues == null && itemLabel.equals(Messages.Preference_Use_Default)) {
+                showSpecimenButton.select(index);
+                break;
+            }
+            if (isShowSpecimenRelatedIssues != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowSpecimenRelatedIssues){
+                showSpecimenButton.select(index);
+                break;
+            }
+            if (isShowSpecimenRelatedIssues != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowSpecimenRelatedIssues){
+                showSpecimenButton.select(index);
+                break;
+            }
+            index++;
+        }
+        showSpecimenButton.setEnabled(isEditingAllowed);
 
         if (isAdminPreference){
+            allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
             allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
             allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -133,20 +147,8 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
                     allowOverrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
                 }
             });
-        }else{
-            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(overrideShowSpecimenRelatedIssues);
-            allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    setApply(true);
-                    overrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
-                }
-            });
-            if (!allowOverrideShowSpecimenRelatedIssues){
-                showSpecimenButton.setEnabled(false);
-                allowOverrideIsShowSpecimenRelatedIssuesButton.setEnabled(false);
-            }
         }
+
         composite = createComposite(parent);
         //composite.setEnabled(isShowSpecimenRelatedIssues);
         gridData = createTextGridData();
@@ -154,21 +156,27 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
         separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
         separator.setLayoutData(gridData);
 
-        showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
-
-        showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
+        showCollectingAreaInGeneralSectionButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowCollectingAreasInGeneralSection, Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section, isAdminPreference);
 
-        showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
-        showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
-             @Override
-             public void widgetSelected(SelectionEvent e) {
-                 setApply(true);
-                 isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
-
-              }
-         });
-        allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
+        showCollectingAreaInGeneralSectionButton.addSelectionListener(this);
+        index = 0;
+        for (String itemLabel : showCollectingAreaInGeneralSectionButton.getItems()) {
+            if (isShowCollectingAreaInGeneralSection == null && itemLabel.equals(Messages.Preference_Use_Default)) {
+                showCollectingAreaInGeneralSectionButton.select(index);
+                break;
+            }
+            if (isShowCollectingAreaInGeneralSection != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowCollectingAreaInGeneralSection){
+                showCollectingAreaInGeneralSectionButton.select(index);
+                break;
+            }
+            if (isShowCollectingAreaInGeneralSection != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowCollectingAreaInGeneralSection){
+                showCollectingAreaInGeneralSectionButton.select(index);
+                break;
+            }
+            index++;
+        }
         if (isAdminPreference){
+            allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
             allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
             allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -177,34 +185,37 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
                     allowOverrideShowCollectingAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
                 }
             });
-        }else{
-            allowOverrideShowCollectingAreaButton.setSelection(overrideShowCollectionAreaInGeneralSection);
-            allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    setApply(true);
-                    overrideShowCollectionAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
-                }
-            });
-            if (!allowOverrideShowCollectingAreaInGeneralSection){
-                showCollectingAreaInGeneralSectionButton.setEnabled(false);
-                allowOverrideShowCollectingAreaButton.setEnabled(false);
-            }
         }
+        if (showCollectingAreaInGeneralSection != null && !showCollectingAreaInGeneralSection.isAllowOverride() ){
+               isEditingAllowed = false;
+        }
+        showCollectingAreaInGeneralSectionButton.setEnabled(isEditingAllowed);
+        determinationOnlyForFieldUnitsButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.DeterminationOnlyForFieldUnits, Messages.DatabasePreferncesPage_Determination_only_for_field_unnits, isAdminPreference);
 
-        determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
-        determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
-        determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
-        determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
-             @Override
-             public void widgetSelected(SelectionEvent e) {
-                 setApply(true);
-                 isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
-             }
-         });
 
-        allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
+        determinationOnlyForFieldUnitsButton.addSelectionListener(this);
+        index = 0;
+        for (String itemLabel : determinationOnlyForFieldUnitsButton.getItems()) {
+            if (isDeterminationOnlyForFieldUnits == null && itemLabel.equals(Messages.Preference_Use_Default)) {
+                determinationOnlyForFieldUnitsButton.select(index);
+                break;
+            }
+            if (isDeterminationOnlyForFieldUnits != null && itemLabel.equals(Messages.GeneralPreference_yes) && isDeterminationOnlyForFieldUnits){
+                determinationOnlyForFieldUnitsButton.select(index);
+                break;
+            }
+            if (isDeterminationOnlyForFieldUnits != null && itemLabel.equals(Messages.GeneralPreference_no) && !isDeterminationOnlyForFieldUnits){
+                determinationOnlyForFieldUnitsButton.select(index);
+                break;
+            }
+            index++;
+        }
+        if (showDeterminationOnlyForFieldUnits != null && !showDeterminationOnlyForFieldUnits.isAllowOverride() ){
+            isEditingAllowed = false;
+        }
+        determinationOnlyForFieldUnitsButton.setEnabled(isEditingAllowed);
         if (isAdminPreference){
+            allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
             allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
             allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -213,36 +224,34 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
                     allowOverrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
                 }
             });
-        }else{
-            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(overrideDeterminationOnlyForFieldUnits);
-            allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    setApply(true);
-                    overrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
-                }
-            });
-            if (!allowOverrideDeterminationOnlyForFieldUnits){
-                determinationOnlyForFieldUnitsButton.setEnabled(false);
-                allowOverridesDeterminationOnlyForFieldUnitsButton.setEnabled(false);
-            }
         }
 
-        showTaxonAssociationButton = new Button(composite, SWT.CHECK);
-
-        showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
+        showTaxonAssociationButton =createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowTaxonAssociations, Messages.DatabasePreferncesPage_Taxon_Associations, isAdminPreference);
 
-        showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
-        showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
-             @Override
-             public void widgetSelected(SelectionEvent e) {
-                 setApply(true);
-                 isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
 
-              }
-         });
-        allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
+        showTaxonAssociationButton.addSelectionListener(this);
+        index = 0;
+        for (String itemLabel : showTaxonAssociationButton.getItems()) {
+            if (isShowTaxonAssociation == null && itemLabel.equals(Messages.Preference_Use_Default)) {
+                showTaxonAssociationButton.select(index);
+                break;
+            }
+            if (isShowTaxonAssociation != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowTaxonAssociation){
+                showTaxonAssociationButton.select(index);
+                break;
+            }
+            if (isShowTaxonAssociation != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowTaxonAssociation){
+                showTaxonAssociationButton.select(index);
+                break;
+            }
+            index++;
+        }
+        if (showTaxonAssociation != null && !showTaxonAssociation.isAllowOverride() ){
+            isEditingAllowed = false;
+        }
+        showTaxonAssociationButton.setEnabled(isEditingAllowed);
         if (isAdminPreference){
+            allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
             allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
             allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -251,35 +260,33 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
                     allowOverrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
                 }
             });
-        }else{
-            allowOverrideIsShowTaxonAssociationButton.setSelection(overrideShowTaxonAssociation);
-            allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    setApply(true);
-                    overrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
-                }
-            });
-            if (!allowOverrideShowTaxonAssociation){
-                showTaxonAssociationButton.setEnabled(false);
-                allowOverrideIsShowTaxonAssociationButton.setEnabled(false);
-            }
         }
 
-        showLifeFormButton = new Button(composite, SWT.CHECK);
-        showLifeFormButton.setText(Messages.DatabasePreferncesPage_Life_Form);
-        showLifeFormButton.setSelection(isShowLifeForm);
-        showLifeFormButton.addSelectionListener(new SelectionAdapter(){
-             @Override
-             public void widgetSelected(SelectionEvent e) {
-                 setApply(true);
-                 isShowLifeForm = showLifeFormButton.getSelection();
-
-              }
-         });
+        showLifeFormButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowLifeForm, Messages.DatabasePreferncesPage_Life_Form, isAdminPreference);
+        showLifeFormButton.addSelectionListener(this);
 
-        allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
+        index = 0;
+        for (String itemLabel: showLifeFormButton.getItems()) {
+            if (isShowLifeForm == null && itemLabel.equals(Messages.Preference_Use_Default)) {
+                showLifeFormButton.select(index);
+                break;
+            }
+            if (isShowLifeForm != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowLifeForm){
+                showLifeFormButton.select(index);
+                break;
+            }
+            if (isShowLifeForm != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowLifeForm){
+                showLifeFormButton.select(index);
+                break;
+            }
+            index++;
+        }
+        if (showLifeForm != null && !showLifeForm.isAllowOverride() ){
+            isEditingAllowed = false;
+        }
+        showLifeFormButton.setEnabled(isEditingAllowed);
         if (isAdminPreference){
+            allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
             allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
             allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -288,28 +295,12 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
                     allowOverrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
                 }
             });
-        }else{
-            allowOverrideShowLifeFormButton.setSelection(overrideShowLifeForm);
-            //showLifeFormButton.setEnabled(overrideShowLifeForm);
-            allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    setApply(true);
-                    overrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
-                    //showLifeFormButton.setEnabled(overrideShowLifeForm);
-                }
-            });
-            if (!allowOverrideShowLifeForm){
-                showLifeFormButton.setEnabled(false);
-                allowOverrideShowLifeFormButton.setEnabled(false);
-            }
         }
 
         if (!isEditingAllowed){
             PreferencesUtil.recursiveSetEnabled(composite, false);
         }
-       // composite.setVisible(isShowSpecimenRelatedIssues);
-       // composite.setEnabled(isShowSpecimenRelatedIssues);
+
         return composite;
     }
 
@@ -321,53 +312,197 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
     protected void getValues() {
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
 
-        isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey());
 
-        allowOverrideShowSpecimenRelatedIssues = cache.get(PreferencePredicate.ShowSpecimen.getKey())!= null ? cache.get(PreferencePredicate.ShowSpecimen.getKey()).isAllowOverride():true;
+        overrideShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true) != null? PreferencesUtil.getBooleanValue(
+                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true): false;
+
+        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
+        showSpecimenPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSpecimen);
+
+
+        if (showSpecimenPref != null) {
+            if (showSpecimenPref.isAllowOverride() ) {
+                if (overrideShowSpecimenRelatedIssues){
+                    isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), true);
+                }
+            } else {
+                isShowSpecimenRelatedIssues = Boolean.valueOf(showSpecimenPref.getValue());
+            }
+
+        } else {
+            if(!overrideShowSpecimenRelatedIssues){
+                isShowSpecimenRelatedIssues = null;
+            }else{
+                isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), true);
+            }
+            showSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, PreferencePredicate.ShowSpecimen.getDefaultValue() != null ?  PreferencePredicate.ShowSpecimen.getDefaultValue().toString(): null);
+        }
+
+
+
+
+        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
+        showCollectingAreaInGeneralSection = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
+        overrideShowCollectionAreaInGeneralSection = PreferencesUtil.getBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true) != null? PreferencesUtil.getBooleanValue(
+                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true): false;
+        allowOverrideShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSection != null ? showCollectingAreaInGeneralSection.isAllowOverride():true;
+        if (showCollectingAreaInGeneralSection != null) {
+            if (showCollectingAreaInGeneralSection.isAllowOverride() ) {
+                if (overrideShowCollectionAreaInGeneralSection){
+                    isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
+                }
+
+            } else {
+                isShowCollectingAreaInGeneralSection = Boolean.valueOf(showCollectingAreaInGeneralSection.getValue());
+
+            }
+
+        } else {
+            if(!overrideShowCollectionAreaInGeneralSection){
+                isShowCollectingAreaInGeneralSection = null;
+            }else{
+                isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
+            }
+            showCollectingAreaInGeneralSection = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue() != null ?  PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue().toString(): null);
+        }
+
+
+        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
+        showDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
+        overrideDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true) != null? PreferencesUtil.getBooleanValue(
+                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true): false;
+        if (showDeterminationOnlyForFieldUnits != null) {
+            if (showDeterminationOnlyForFieldUnits.isAllowOverride() ) {
+                if (overrideDeterminationOnlyForFieldUnits){
+                    isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
+                }
+
+            } else {
+                isDeterminationOnlyForFieldUnits = Boolean.valueOf(showDeterminationOnlyForFieldUnits.getValue());
+
+            }
+
+        } else {
+            if(!overrideDeterminationOnlyForFieldUnits){
+                isDeterminationOnlyForFieldUnits = null;
+            }else{
+                isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), true);
+            }
+            showDeterminationOnlyForFieldUnits = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue() != null ?  PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue().toString(): null);
+        }
+
+        allowOverrideDeterminationOnlyForFieldUnits = showDeterminationOnlyForFieldUnits != null ? showDeterminationOnlyForFieldUnits.isAllowOverride():true;
+
+
+        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
+        showTaxonAssociation = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
+        overrideShowTaxonAssociation =  PreferencesUtil.getBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true) != null? PreferencesUtil.getBooleanValue(
+                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true): false;
+        if (showTaxonAssociation != null) {
+            if (showTaxonAssociation.isAllowOverride() ) {
+                if (overrideShowTaxonAssociation){
+                    isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
+                }
+
+            } else {
+                isShowTaxonAssociation = Boolean.valueOf(showTaxonAssociation.getValue());
+
+            }
+
+        } else {
+            if(!overrideShowTaxonAssociation){
+                isShowTaxonAssociation = null;
+            }else{
+                isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey(), true);
+            }
+            showTaxonAssociation = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, PreferencePredicate.ShowTaxonAssociations.getDefaultValue() != null ?  PreferencePredicate.ShowTaxonAssociations.getDefaultValue().toString(): null);
+        }
+
+        allowOverrideShowTaxonAssociation = showTaxonAssociation != null ? showTaxonAssociation.isAllowOverride():true;
 
-        overrideShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowSpecimen.getKey()));
 
-        isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
-        allowOverrideShowCollectingAreaInGeneralSection = cache.get(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey())!= null ? cache.get(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()).isAllowOverride():true;
-        overrideShowCollectionAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()));
+        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
+        showLifeForm = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
+        overrideShowLifeForm =  PreferencesUtil.getBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true) != null? PreferencesUtil.getBooleanValue(
+                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true): false;
+        if (showLifeForm != null) {
+            if (showLifeForm.isAllowOverride() ) {
+                if (overrideShowLifeForm){
+                    isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
+                }
+
+            } else {
+                isShowLifeForm = Boolean.valueOf(showLifeForm.getValue());
 
-        isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
-        allowOverrideDeterminationOnlyForFieldUnits = cache.get(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey())!= null ? cache.get(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()).isAllowOverride():true;
-        overrideDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()));
+            }
 
-        isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
-        allowOverrideShowTaxonAssociation = cache.get(PreferencePredicate.ShowTaxonAssociations.getKey())!= null ? cache.get(PreferencePredicate.ShowTaxonAssociations.getKey()).isAllowOverride():true;
-        overrideShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowTaxonAssociations.getKey()));
+        } else {
+            if(!overrideShowLifeForm){
+                isShowLifeForm = null;
+            }else{
+                isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey(), true);
+            }
+            showLifeForm = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, PreferencePredicate.ShowLifeForm.getDefaultValue() != null ?  PreferencePredicate.ShowLifeForm.getDefaultValue().toString(): null);
+        }
 
-        isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
-        allowOverrideShowLifeForm = cache.get(PreferencePredicate.ShowLifeForm.getKey())!= null ? cache.get(PreferencePredicate.ShowLifeForm.getKey()).isAllowOverride():true;
-        overrideShowLifeForm = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowLifeForm.getKey()));
+        allowOverrideShowLifeForm = showLifeForm != null ? showLifeForm.isAllowOverride():true;
 
 
     }
 
     @Override
     public boolean performOk() {
-        if (allowOverrideShowSpecimenRelatedIssues){
-            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowSpecimen.getKey()), overrideShowSpecimenRelatedIssues);
+
+        boolean override = false;
+        if (isShowSpecimenRelatedIssues != null ) {
+            override = true;
+            PreferencesUtil.setStringValue(PreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues.toString());
         }
-        if (allowOverrideShowCollectingAreaInGeneralSection){
-            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), overrideShowCollectionAreaInGeneralSection);
+        PreferencesUtil.setBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()),
+                override);
+
+        override = false;
+        if (isShowCollectingAreaInGeneralSection != null ) {
+            override = true;
+            PreferencesUtil.setStringValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection.toString());
         }
-        if (allowOverrideDeterminationOnlyForFieldUnits){
-            PreferencesUtil.setBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), overrideDeterminationOnlyForFieldUnits);
+        PreferencesUtil.setBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()),
+                override);
+
+        override = false;
+        if (isDeterminationOnlyForFieldUnits != null ) {
+            override = true;
+            PreferencesUtil.setStringValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits.toString());
         }
-        if (allowOverrideShowTaxonAssociation){
-            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowTaxonAssociations.getKey()), overrideShowTaxonAssociation);
+        PreferencesUtil.setBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()),
+                override);
+
+        override = false;
+        if (isShowTaxonAssociation != null ) {
+            override = true;
+            PreferencesUtil.setStringValue(PreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation.toString());
         }
-        if (allowOverrideShowLifeForm){
-            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowLifeForm.getKey()), overrideShowLifeForm);
+        PreferencesUtil.setBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()),
+                override);
+
+        override = false;
+        if (isShowLifeForm != null ) {
+            override = true;
+            PreferencesUtil.setStringValue(PreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm.toString());
         }
+        PreferencesUtil.setBooleanValue(
+                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()),
+                override);
+
         return true;
     }
 
@@ -376,37 +511,166 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
     @Override
     protected void performDefaults() {
         isShowSpecimenRelatedIssues = (Boolean)PreferencePredicate.ShowSpecimen.getDefaultValue();
-        showSpecimenButton.setSelection(isShowSpecimenRelatedIssues);
-
-        allowOverrideShowSpecimenRelatedIssues = true;
-        allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
-
+        if (isShowSpecimenRelatedIssues){
+            showSpecimenButton.select(0);
+        }else{
+            showSpecimenButton.select(1);
+        }
+        if (allowOverrideIsShowSpecimenRelatedIssuesButton != null){
+            allowOverrideShowSpecimenRelatedIssues = true;
+            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
+        }
         isShowCollectingAreaInGeneralSection = (Boolean)PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
-        showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
-
-        allowOverrideShowCollectingAreaInGeneralSection = true;
-        allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
-
+        if (isShowCollectingAreaInGeneralSection){
+            showCollectingAreaInGeneralSectionButton.select(0);
+        }else{
+            showCollectingAreaInGeneralSectionButton.select(1);
+        }
+        if (allowOverrideShowCollectingAreaButton != null){
+            allowOverrideShowCollectingAreaInGeneralSection = true;
+            allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
+        }
         isDeterminationOnlyForFieldUnits = (Boolean) PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue();
-        determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
-
-        allowOverrideDeterminationOnlyForFieldUnits = true;
-        allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
+        if (isDeterminationOnlyForFieldUnits){
+            determinationOnlyForFieldUnitsButton.select(0);
+        }else{
+            determinationOnlyForFieldUnitsButton.select(1);
+        }
+        if (allowOverridesDeterminationOnlyForFieldUnitsButton != null){
+            allowOverrideDeterminationOnlyForFieldUnits = true;
+            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
+        }
 
         isShowTaxonAssociation = (Boolean) PreferencePredicate.ShowTaxonAssociations.getDefaultValue();
-        showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
+        if (isShowTaxonAssociation){
+            showTaxonAssociationButton.select(0);
+        }else{
+            showTaxonAssociationButton.select(1);
+        }
+        if (allowOverrideIsShowTaxonAssociationButton != null){
+            allowOverrideShowTaxonAssociation = true;
+            allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
+        }
 
-        allowOverrideShowTaxonAssociation = true;
-        allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
 
         isShowLifeForm = (Boolean) PreferencePredicate.ShowLifeForm.getDefaultValue();
-        showLifeFormButton.setSelection(isShowLifeForm);
 
-        allowOverrideShowLifeForm = true;
-        allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
+        if (isShowLifeForm){
+            showLifeFormButton.select(0);
+        }else{
+            showLifeFormButton.select(1);
+        }
+        if (allowOverrideShowLifeFormButton != null){
+            allowOverrideShowLifeForm = true;
+            allowOverrideShowLifeFormButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
+        }
+
 
         super.performDefaults();
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void widgetSelected(SelectionEvent e) {
+       setApply(true);
+       if (e.getSource().equals(this.showSpecimenButton)) {
+           String text = showSpecimenButton.getText();
+           if(text.equals(Messages.Preference_Use_Default)){
+               isShowSpecimenRelatedIssues = null;
+               if (isAdminPreference){
+                   allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(true);
+               }
+               return;
+           }
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowSpecimenRelatedIssues = true;
+           }else{
+               isShowSpecimenRelatedIssues = false;
+           }
+       }
+
+       if (e.getSource().equals(this.showCollectingAreaInGeneralSectionButton)) {
+           String text = showCollectingAreaInGeneralSectionButton.getText();
+           if(text.equals(Messages.Preference_Use_Default)){
+               isShowCollectingAreaInGeneralSection = null;
+               if (isAdminPreference){
+                   //showCollectingAreaInGeneralSection.setAllowOverride(true);
+                   allowOverrideShowCollectingAreaButton.setSelection(true);
+               }
+               return;
+           }
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowCollectingAreaInGeneralSection = true;
+           }else{
+               isShowCollectingAreaInGeneralSection = false;
+           }
+       }
+
+       if (e.getSource().equals(this.determinationOnlyForFieldUnitsButton)) {
+           String text = determinationOnlyForFieldUnitsButton.getText();
+           if(text.equals(Messages.Preference_Use_Default)){
+               isDeterminationOnlyForFieldUnits = null;
+               if (isAdminPreference){
+                   //showDeterminationOnlyForFieldUnits.setAllowOverride(true);
+                   allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(true);
+               }
+               return;
+           }
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isDeterminationOnlyForFieldUnits = true;
+           }else{
+               isDeterminationOnlyForFieldUnits = false;
+           }
+       }
+
+       if (e.getSource().equals(this.showTaxonAssociationButton)) {
+           String text = showTaxonAssociationButton.getText();
+           if(text.equals(Messages.Preference_Use_Default)){
+               isShowTaxonAssociation = null;
+               if (isAdminPreference){
+                   //showTaxonAssociation.setAllowOverride(true);
+                   allowOverrideIsShowTaxonAssociationButton.setSelection(true);
+               }
+               return;
+           }
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowTaxonAssociation = true;
+           }else{
+               isShowTaxonAssociation = false;
+           }
+       }
+
+       if (e.getSource().equals(this.showLifeFormButton)) {
+           String text = showLifeFormButton.getText();
+           if(text.equals(Messages.Preference_Use_Default)){
+               isShowLifeForm = null;
+               if (isAdminPreference){
+                   //showLifeForm.setAllowOverride(true);
+                   allowOverrideShowLifeFormButton.setSelection(true);
+               }
+               return;
+           }
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowLifeForm = true;
+           }else{
+               isShowLifeForm = false;
+           }
+       }
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void widgetDefaultSelected(SelectionEvent e) {
+        // TODO Auto-generated method stub
+
+    }
+
+
+
 
 }