ref #8045: check whether all db preferences are deleted from DB if value is default...
authorKatja Luther <k.luther@bgbm.org>
Tue, 14 May 2019 09:22:28 +0000 (11:22 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 14 May 2019 09:22:28 +0000 (11:22 +0200)
15 files changed:
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/AbcdImportPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/NameDetailsViewAdminConfiguration.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/NomenclaturalCodePreferences.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/PublishFlagPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/GeneralPreferencePage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/NameDetailsViewConfiguration.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PublishFlagLocalPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/SpecimenOrObservationPreferences.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/CdmPreferencePage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/NomenclaturalCodePreferences.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableVocabularyWizard.java

index d1897a775cb568285c5d169b52c35ad39300d305..4c8f5eb5fe36660c8e94acd73807a125945564fe 100755 (executable)
@@ -337,7 +337,10 @@ public class AbcdImportPreference extends CdmPreferencePage implements IE4AdminP
         }
         if (configurator != null){
             String configString = configurator.toString();
-
+            Abcd206ImportConfigurator defaultConfig = Abcd206ImportConfigurator.NewInstance(null,null);
+            if (configString.equals(defaultConfig.toString())){
+                configString = null;
+            }
             CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configString);
             pref.setAllowOverride(allowOverride);
 
index 10e986a3daa7473016eb8a6fb2af82549e2fca6a..38f6dda0f3005eef8c8db843505d219b2e67c448 100755 (executable)
@@ -56,7 +56,10 @@ public class NameDetailsViewAdminConfiguration extends NameDetailsViewConfigurat
         NameDetailsConfigurator config = createNameDetailsViewConfig();
         String value = config.toString();
 
-
+        if (config.isAllowOverride() && !config.isSimpleDetailsViewActivated()){
+            // is default, should delete from db
+            value = null;
+        }
         CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.NameDetailsView, value);
         pref.setAllowOverride(isAllowOverride);
         service.set(pref);
@@ -79,6 +82,8 @@ public class NameDetailsViewAdminConfiguration extends NameDetailsViewConfigurat
                 isAllowOverride = pref.isAllowOverride();
                 CdmPreferenceCache cache = CdmPreferenceCache.instance();
                 cache.put(pref);
+            }else {
+                isAllowOverride = true;
             }
 
 
index 22c22bed60179d968b60e9807917e94391e7d53e..b1066ffdc9a2d9754e161ed6d8a7b5913ae51fba 100755 (executable)
@@ -45,9 +45,9 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 public class NomenclaturalCodePreferences extends CdmPreferencePage implements IE4AdminPreferencePage{
 
-    String actualCode = null;
-    Map<String, String>  labelAndValues;
-    Map<String, Integer> keyAndIndex;
+    NomenclaturalCode actualCode = null;
+    Map<NomenclaturalCode, String>  labelAndValues;
+    Map<NomenclaturalCode, Integer> keyAndIndex;
     Combo nomenclaturalCode;
     Button allowOverrideButton;
     boolean allowOverride;
@@ -62,10 +62,10 @@ public class NomenclaturalCodePreferences extends CdmPreferencePage implements I
             PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
             CdmPreference pref = service.find(key);
             if (pref != null){
-                actualCode = pref.getValue();
+                actualCode = NomenclaturalCode.fromString(pref.getValue());
                 allowOverride = pref.isAllowOverride();
             }else{
-                actualCode = PreferencesUtil.getPreferenceKey(PreferencesUtil.getPreferredNomenclaturalCode());
+                actualCode = NomenclaturalCode.fromString(PreferencePredicate.NomenclaturalCode.getDefaultValue().toString());
                 allowOverride = true;
             }
 
@@ -85,7 +85,7 @@ public class NomenclaturalCodePreferences extends CdmPreferencePage implements I
         getLabelAndValues();
         keyAndIndex = new HashMap<>();
         Integer index = 0;
-        for (String key: labelAndValues.keySet()) {
+        for (NomenclaturalCode key: labelAndValues.keySet()) {
             nomenclaturalCode.add(labelAndValues.get(key));
             keyAndIndex.put(key, index);
             index++;
@@ -100,7 +100,7 @@ public class NomenclaturalCodePreferences extends CdmPreferencePage implements I
             public void widgetSelected(SelectionEvent evt) {
                 setApply(true);
                 String name = nomenclaturalCode.getText();
-                for (Entry<String, String> label:labelAndValues.entrySet()){
+                for (Entry<NomenclaturalCode, String> label:labelAndValues.entrySet()){
                     if (label.getValue().equals(name)){
                         actualCode = label.getKey();
                     }
@@ -125,12 +125,12 @@ public class NomenclaturalCodePreferences extends CdmPreferencePage implements I
        /**
         * @return
         */
-       private Map<String, String> getLabelAndValues() {
+       private Map<NomenclaturalCode, String> getLabelAndValues() {
                List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
                                .getSupportedCodes();
                labelAndValues = new HashMap<>();
                for (int i = 0; i < supportedCodes.size(); i++) {
-                       labelAndValues.put(PreferencesUtil.getPreferenceKey(supportedCodes.get(i)), NomenclaturalCodeHelper
+                       labelAndValues.put(supportedCodes.get(i), NomenclaturalCodeHelper
                     .getDescription(supportedCodes.get(i))) ;
 
                }
@@ -156,7 +156,7 @@ public class NomenclaturalCodePreferences extends CdmPreferencePage implements I
        @Override
         public boolean performOk() {
            if (actualCode != null){
-               CdmPreference pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.NomenclaturalCode, actualCode);
+               CdmPreference pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.NomenclaturalCode, actualCode.toString());
                pref.setAllowOverride(allowOverride);
                PreferencesUtil.setPreferredNomenclaturalCode(pref);
            }
@@ -165,7 +165,7 @@ public class NomenclaturalCodePreferences extends CdmPreferencePage implements I
 
        @Override
        protected void performDefaults() {
-           actualCode = PreferencePredicate.NomenclaturalCode.getDefaultValue().toString();
+           actualCode = (NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue();
            allowOverride = true;
            Integer index = keyAndIndex.get(actualCode);
         if(index!=null){
index 7eda2bcde11608f4366b5f05f3c614d3fcbc9acb..ea3591ebbd895a49b9bd993c9be296633ec92f09 100755 (executable)
@@ -13,6 +13,7 @@ import eu.etaxonomy.cdm.api.service.IPreferenceService;
 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
 import eu.etaxonomy.cdm.model.metadata.PublishEnum;
+import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.preference.PublishFlagLocalPreference;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -40,6 +41,7 @@ public class PublishFlagPreference extends PublishFlagLocalPreference implements
             return true;
         }
         String text = publishFlagBehaviour.getText();
+        text = text.replace(Messages.Preference_Use_Default, "");
         for (PublishEnum display: PublishEnum.values()){
             if (display.getLabel().equals(text)){
                 text = display.getKey();
index 0cf99f6023a03e482b72144da2087fcd5d600eb7..decfb36ed6015d4dd3a8028879dbf4277257d2bf 100644 (file)
@@ -628,6 +628,7 @@ public class Messages extends NLS {
     public static String TermOrder_natural;
 
     public static String  ChecklistEditorGeneralPreference_Configure_area_order;
+    public static String Preference_Use_Default;
 
 
     static {
index cab5eb9e126543ae58421d15a3a70d9c436a0788..c181e5c250e7692d27a008b1c1fa988da97227ef 100644 (file)
@@ -491,3 +491,4 @@ TermOrder_Title=Title
 TermOrder_natural=Natural
 
 ChecklistEditorGeneralPreference_Configure_area_order=Order of Areas
+Preference_Use_Default= (Use Default)
index 8af901162d376fe66ef4fbeead4d2dcc06d4ff44..8d3395418a9c3fd2945857df65317671db9d8d39 100644 (file)
@@ -334,36 +334,45 @@ public class ChecklistEditorGeneralPreference extends CdmPreferencePage implemen
 
             PreferencesUtil.setBooleanValue(PreferencePredicate.DistributionEditorActivated.getKey(),
                     isEditorActivated);
-
+            boolean override = false;
             if (distributionEditorPref == null
                     || isEditorActivated != Boolean.parseBoolean(distributionEditorPref.getValue())) {
-                PreferencesUtil.setBooleanValue(
-                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()),
-                        true);
+                override = true;
             }
+            PreferencesUtil.setBooleanValue(
+                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()),
+                    override);
             PreferencesUtil.setSortNamedAreasInDistributionEditor(orderAreas);
+            override = false;
             if (prefAreaSort == null || orderAreas != prefAreaSort.getValue()) {
-                PreferencesUtil.setBooleanValue(
-                        PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()),
-                        true);
+                override = true;
             }
+            PreferencesUtil.setBooleanValue(
+                    PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()),
+                    override);
             PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
+            override = false;
             if (prefRank == null || isShowRank != Boolean.parseBoolean(prefRank.getValue())) {
-                PreferencesUtil.setBooleanValue(
-                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()),
-                        true);
+                override = true;
             }
+            PreferencesUtil.setBooleanValue(
+                    PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()),
+                    true);
             PreferencesUtil.setDisplayStatusInChecklistEditor(displayStatus);
+            override = false;
             if (prefStatusDisplay == null || displayStatus != prefStatusDisplay.getValue()) {
-                PreferencesUtil.setBooleanValue(
-                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()),
-                        true);
+               override = true;
             }
+            PreferencesUtil.setBooleanValue(
+                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()),
+                    true);
             PreferencesUtil.setAreaDisplayInChecklistEditor(displayArea);
+            override = false;
             if (prefAreaDisplay == null || displayArea != prefAreaDisplay.getValue()) {
-                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(
-                        PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), overrideAreaDisplay);
+                override = true;
             }
+            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(
+                    PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), overrideAreaDisplay);
             PreferencesUtil.setOwnDescriptionForChecklistEditor(ownDescriptionForDistributionEditor);
             PreferencesUtil.setBooleanValue(
                     PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()),
@@ -424,7 +433,7 @@ public class ChecklistEditorGeneralPreference extends CdmPreferencePage implemen
         }
         if (e.getSource().equals(this.activateRankCombo)) {
             String text = activateRankCombo.getText();
-            text = text.replace(" (Default)", "");
+            text = text.replace(Messages.Preference_Use_Default, "");
             if (text.equals(SHOW_RANK)){
                 isShowRank = true;
             }else{
index 0bf1e7efd0ba83a75de9aa10119aee83158a6159..262ad92779266f2c282485c2376404461f4c35be 100755 (executable)
@@ -223,7 +223,7 @@ public class GeneralPreferencePage extends CdmPreferencePage implements Selectio
     public void widgetSelected(SelectionEvent e) {
         if (e.getSource().equals(this.showIOMenuButton)) {
             String text = showIOMenuButton.getText();
-            text = text.replace(" (Default)", "");
+            text = text.replace(Messages.Preference_Use_Default, "");
             if (text.equals(SHOW)){
                 isShowIOMenu = true;
             }else{
@@ -232,7 +232,7 @@ public class GeneralPreferencePage extends CdmPreferencePage implements Selectio
         }
         if (e.getSource().equals(this.showChecklistPerspectiveButton)) {
             String text = showChecklistPerspectiveButton.getText();
-            text = text.replace(" (Default)", "");
+            text = text.replace(Messages.Preference_Use_Default, "");
             if (text.equals(SHOW)){
                 isShowCheckListPerspective = true;
             }else{
@@ -241,13 +241,14 @@ public class GeneralPreferencePage extends CdmPreferencePage implements Selectio
         }
         if (e.getSource().equals(this.showTaxonNodeWizardButton)) {
             String text = showTaxonNodeWizardButton.getText();
-            text = text.replace(" (Default)", "");
+            text = text.replace(Messages.Preference_Use_Default, "");
             if (text.equals(SHOW)){
                 isShowTaxonNodeWizard = true;
             }else{
                 isShowTaxonNodeWizard = false;
             }
         }
+        this.setApply(true);
 
 
     }
index bf0bffb0e7ca1ddc24a2b04a2e5f7bc9b9fde0f2..7db16aacaf8022eecfb81eb46d02251cea34e931 100644 (file)
@@ -9,6 +9,7 @@ import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 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;
@@ -26,6 +27,7 @@ public class NameDetailsViewConfiguration extends CdmPreferencePage {
        protected NameDetailsConfigurator nameDetailsConfig;
     Composite localSettings ;
 
+    CdmPreference nameDetailsPref;
 
     protected boolean isShowTaxon;
     protected boolean isShowNameApprobiation ;
@@ -51,7 +53,7 @@ public class NameDetailsViewConfiguration extends CdmPreferencePage {
     private Button showSecDetail;
     private Button secEnabled;
 
-    protected Button activateCheckButton;
+    protected Combo activateCheckButton;
     protected Button allowLocalPreference;
     protected Button showTaxon;
     protected Button showLsid;
@@ -84,19 +86,35 @@ public class NameDetailsViewConfiguration extends CdmPreferencePage {
                 nameDetailsConfig = new NameDetailsConfigurator(false);
             }
 
-            activateCheckButton = new Button(title, SWT.CHECK);
-            allowLocalPreference = createAllowOverrideButton(title);
+            activateCheckButton = createBooleanCombo(title, "Enable", "Disable", PreferencePredicate.SimpleDetailsViewActivated, Messages.NameDetailsViewConfiguration_activateSimpleDetailsView, isAdminPreference);
+            if (isAdminPreference){
+                allowLocalPreference = createAllowOverrideButton(title);
+
+                allowLocalPreference.addSelectionListener(new SelectionAdapter(){
+                    @Override
+                    public void widgetSelected(SelectionEvent e) {
+                        setApply(true);
+                        if (isAdminPreference){
+                            isAllowOverride = allowLocalPreference.getSelection();
+                        }else{
+                            isOverride = allowLocalPreference.getSelection();
+                        }
+
+                    }
+                });
+
+            }
             Composite dbSettings  = new Composite(parent, SWT.NONE);
 
-            activateCheckButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
-            activateCheckButton.setText(Messages.NameDetailsViewConfiguration_activateSimpleDetailsView);
+//            activateCheckButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
+//            activateCheckButton.setText(Messages.NameDetailsViewConfiguration_activateSimpleDetailsView);
             isSimpleDetailsViewActivated = nameDetailsConfig.isSimpleDetailsViewActivated();
 
             activateCheckButton.addSelectionListener(new SelectionAdapter(){
                 @Override
                 public void widgetSelected(SelectionEvent e) {
                     setApply(true);
-                    isSimpleDetailsViewActivated = activateCheckButton.getSelection();
+                    isSimpleDetailsViewActivated = activateCheckButton.getSelectionIndex() == 0? true:false;
                     nameDetailsConfig.setSimpleDetailsViewActivated(isSimpleDetailsViewActivated);
                     dbSettings.setEnabled(isSimpleDetailsViewActivated);
                     PreferencesUtil.recursiveSetEnabled(dbSettings, isSimpleDetailsViewActivated);
@@ -109,19 +127,6 @@ public class NameDetailsViewConfiguration extends CdmPreferencePage {
              });
 
 
-            allowLocalPreference.addSelectionListener(new SelectionAdapter(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    setApply(true);
-                    if (isAdminPreference){
-                        isAllowOverride = allowLocalPreference.getSelection();
-                    }else{
-                        isOverride = allowLocalPreference.getSelection();
-                    }
-
-                }
-            });
-
             dbSettings.setLayout(new GridLayout());
             dbSettings.setEnabled(isSimpleDetailsViewActivated);
 
@@ -396,7 +401,9 @@ public class NameDetailsViewConfiguration extends CdmPreferencePage {
     public boolean performOk() {
         if (nameDetailsConfig != null){
             PreferencesUtil.setStringValue(PreferencePredicate.NameDetailsView.getKey(), nameDetailsConfig.toString());
-            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.NameDetailsView.getKey()), isOverride);
+            if (nameDetailsPref == null || !nameDetailsConfig.toString().equals(nameDetailsPref.getValue())) {
+                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.NameDetailsView.getKey()), true);
+            }
         }
 
         return true;
@@ -406,7 +413,7 @@ public class NameDetailsViewConfiguration extends CdmPreferencePage {
     @Override
     public void getValues(){
         if (nameDetailsConfig == null){
-            CdmPreference nameDetailsPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.NameDetailsView);
+            nameDetailsPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.NameDetailsView);
             isAdminPreference = false;
             isAllowOverride = true;
             if (nameDetailsPref != null){
@@ -419,11 +426,10 @@ public class NameDetailsViewConfiguration extends CdmPreferencePage {
     }
 
     protected void setButtonSelections(){
-        activateCheckButton.setSelection(isSimpleDetailsViewActivated);;
+        int index = isSimpleDetailsViewActivated?0:1;
+        activateCheckButton.select(index);
         if (isAdminPreference){
             allowLocalPreference.setSelection(isAllowOverride);
-        }else{
-            allowLocalPreference.setSelection(isOverride);
         }
         showTaxon.setSelection(isShowTaxon);
         showLsid.setSelection(isShowLSID);
index ca85e91cc5bbfca6fc6ab6c6ced83476e5888405..8789b759263a6af5ed2399460f740c6dae8dfdd0 100644 (file)
@@ -247,7 +247,7 @@ public class PreferencesUtil implements IPreferenceKeys {
      *
      *
      **/
-    public static int getIntValue(String name) {
+    public static int getIntValue(String name, boolean local) {
         CdmPreference pref= getDBPreferenceValue(name);
         String prefValue = null;
         if (pref != null){
@@ -259,7 +259,13 @@ public class PreferencesUtil implements IPreferenceKeys {
         }catch(NumberFormatException e){
             logger.debug("Preference value of " + name + " is not a number");
         }
-        if (result == null){
+
+        String overrideKey =  createPreferenceString(createOverridePreferenceString(name));
+        boolean override = true;
+        if (getPreferenceStore().contains(overrideKey)){
+            override = getPreferenceStore().getBoolean(overrideKey);
+        }
+        if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
             String dbSpecific = prefKey(name);
             if (getPreferenceStore().contains(dbSpecific)){
                 result = getPreferenceStore().getInt(dbSpecific);
@@ -270,7 +276,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         }
         return result;
 
-
     }
 
     public static boolean getBooleanValue(String name) {
@@ -287,16 +292,16 @@ public class PreferencesUtil implements IPreferenceKeys {
     public static boolean getBooleanValue(String name, boolean local) {
         if (CdmStore.isActive()){
             CdmPreference pref = getDBPreferenceValue(name);
-            String prefValue = null;
-            if (pref == null || local){
+
+            String overrideKey =  createPreferenceString(createOverridePreferenceString(name));
+            boolean override = true;
+            if (getPreferenceStore().contains(overrideKey)){
+                override = getPreferenceStore().getBoolean(overrideKey);
+            }
+            if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
                 String dbSpecific = prefKey(name);
-                if (getPreferenceStore().contains(dbSpecific)){
-                    return getPreferenceStore().getBoolean(dbSpecific);
-                }else{
-                    return getPreferenceStore().
-                            getBoolean(name);
-                }
-            }else{
+                return getPreferenceStore().getBoolean(dbSpecific);
+             }else{
                 return Boolean.valueOf(pref.getValue());
             }
 
@@ -345,7 +350,7 @@ public class PreferencesUtil implements IPreferenceKeys {
      *
      *
      **/
-    public static float getFloatValue(String name) {
+    public static float getFloatValue(String name, boolean local) {
         CdmPreference pref = getDBPreferenceValue(name);
         String prefValue = null;
         if (pref != null){
@@ -357,7 +362,12 @@ public class PreferencesUtil implements IPreferenceKeys {
         }catch(NumberFormatException e){
             logger.debug("Preference value of " + name + " is not a number");
         }
-        if (result == null){
+        String overrideKey =  createPreferenceString(createOverridePreferenceString(name));
+        boolean override = true;
+        if (getPreferenceStore().contains(overrideKey)){
+            override = getPreferenceStore().getBoolean(overrideKey);
+        }
+        if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
             String dbSpecific = prefKey(name);
             if (getPreferenceStore().contains(dbSpecific)){
                 result = getPreferenceStore().getFloat(dbSpecific);
@@ -945,6 +955,7 @@ public class PreferencesUtil implements IPreferenceKeys {
                getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowIdInSource.getDefaultValue().toString()));
                getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(PreferencePredicate.DisableMultiClassification.getDefaultValue().toString()));
                getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowImportExportMenu.getKey()), Boolean.valueOf(PreferencePredicate.ShowImportExportMenu.getDefaultValue().toString()));
+               getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowSpecimen.getKey()), Boolean.valueOf(PreferencePredicate.ShowSpecimen.getDefaultValue().toString()));
 
        }
 
@@ -1492,45 +1503,31 @@ public class PreferencesUtil implements IPreferenceKeys {
         }else{
             value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local);
         }
-        String [] sections = value.split(";");
-        Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
-        String[] sectionValues;
-        for (String sectionValue: sections){
-            sectionValues = sectionValue.split(":");
-            sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
-        }
-
-        config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
-
-        config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
-
-        config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
-        config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
-
-        config.setLSIDActivated(getValue(sectionMap, "lsid"));
-
-        config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
-
-        config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
-
-        config.setRankActivated(getValue(sectionMap, "rank"));
-
-        config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
-
-        config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
-
-        config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
-
-        config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
-
-        config.setProtologueActivated(getValue(sectionMap,"protologue"));
-
-        config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
-
-        config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
-
+        if (value!= null){
+            String [] sections = value.split(";");
+            Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
+            String[] sectionValues;
+            for (String sectionValue: sections){
+                sectionValues = sectionValue.split(":");
+                sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
+            }
+            config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
+            config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
+            config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
+            config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
+            config.setLSIDActivated(getValue(sectionMap, "lsid"));
+            config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
+            config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
+            config.setRankActivated(getValue(sectionMap, "rank"));
+            config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
+            config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
+            config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
+            config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
+            config.setProtologueActivated(getValue(sectionMap,"protologue"));
+            config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
+            config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
             config.setHybridActivated(getValue(sectionMap,"hybrid"));
-
+        }
         return config;
     }
 
index 963cabd98dfc33d669b110638436ca2ff5e2a6bf..b5b45976e9f94f3d6cbdcfad448b9486836a7dae 100755 (executable)
@@ -137,7 +137,11 @@ public class PublishFlagLocalPreference extends CdmPreferencePage {
                 }
             }
             PreferencesUtil.setStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey(), text);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey()), allowOverride);
+            if (pref == null || !pref.getValue().equals(text)){
+                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey()), true);
+            }else{
+                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey()), false);
+            }
         }
         return true;
     }
index c0a8e6bacc3d66513d7dc9b09e6ba1b65c8cf397..8fb5d39fe42c7802251bd9c6d871bf4231d60808 100644 (file)
@@ -11,8 +11,10 @@ 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;
@@ -30,7 +32,7 @@ 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;
@@ -52,17 +54,22 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
     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() {
@@ -105,29 +112,18 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
         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);
+        if (isShowSpecimenRelatedIssues){
+            showSpecimenButton.select(0);
+        }else{
+            showSpecimenButton.select(1);
+        }
 
 
         if (isAdminPreference){
+            allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
             allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
             allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -136,20 +132,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();
@@ -157,21 +141,16 @@ 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);
+        if (isShowCollectingAreaInGeneralSection){
+            showCollectingAreaInGeneralSectionButton.select(0);
+        }else{
+            showCollectingAreaInGeneralSectionButton.select(1);
+        }
         if (isAdminPreference){
+            allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
             allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
             allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -180,34 +159,20 @@ 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);
-            }
         }
 
-        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();
-             }
-         });
+        determinationOnlyForFieldUnitsButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.DeterminationOnlyForFieldUnits, Messages.DatabasePreferncesPage_Determination_only_for_field_unnits, isAdminPreference);
+
+
+        determinationOnlyForFieldUnitsButton.addSelectionListener(this);
+        if (isDeterminationOnlyForFieldUnits){
+            determinationOnlyForFieldUnitsButton.select(0);
+        }else{
+            determinationOnlyForFieldUnitsButton.select(1);
+        }
 
-        allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
         if (isAdminPreference){
+            allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
             allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
             allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -216,36 +181,19 @@ 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 =createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowTaxonAssociations, Messages.DatabasePreferncesPage_Taxon_Associations, isAdminPreference);
 
-        showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
 
-        showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
-        showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
-             @Override
-             public void widgetSelected(SelectionEvent e) {
-                 setApply(true);
-                 isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
-
-              }
-         });
-        allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
+        showTaxonAssociationButton.addSelectionListener(this);
+        if (isShowTaxonAssociation){
+            showTaxonAssociationButton.select(0);
+        }else{
+            showTaxonAssociationButton.select(1);
+        }
         if (isAdminPreference){
+            allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
             allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
             allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -254,35 +202,19 @@ 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);
 
-              }
-         });
+        if (isShowLifeForm){
+            showLifeFormButton.select(0);
+        }else{
+            showLifeFormButton.select(1);
+        }
 
-        allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
         if (isAdminPreference){
+            allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
             allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
             allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
                 @Override
@@ -291,28 +223,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;
     }
 
@@ -324,36 +240,48 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
     protected void getValues() {
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
 
-        isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), true);
+        isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey());
         PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
-        CdmPreference showSpecimenPref = cache.findBestMatching(key);
+        showSpecimenPref = cache.findBestMatching(key);
+        if (showSpecimenPref == null){
+            showSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, PreferencePredicate.ShowSpecimen.getDefaultValue() != null ?  PreferencePredicate.ShowSpecimen.getDefaultValue().toString(): null);
+        }
         allowOverrideShowSpecimenRelatedIssues = showSpecimenPref != null ? showSpecimenPref.isAllowOverride():true;
 
-        overrideShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowSpecimen.getKey()), true);
+
 
         isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
         key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
-        CdmPreference showCollectingAreaInGeneralSection = cache.findBestMatching(key);
+        showCollectingAreaInGeneralSection = cache.findBestMatching(key);
+        if (showCollectingAreaInGeneralSection == null){
+            showCollectingAreaInGeneralSection = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue() != null ?  PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue().toString(): null);
+        }
         allowOverrideShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSection != null ? showCollectingAreaInGeneralSection.isAllowOverride():true;
-        overrideShowCollectionAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true);
+
 
         isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
         key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
-        CdmPreference showDeterminationOnlyForFieldUnits = cache.findBestMatching(key);
+        showDeterminationOnlyForFieldUnits = cache.findBestMatching(key);
+        if (showDeterminationOnlyForFieldUnits == null){
+            showDeterminationOnlyForFieldUnits = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue() != null ?  PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue().toString(): null);
+        }
         allowOverrideDeterminationOnlyForFieldUnits = showDeterminationOnlyForFieldUnits != null ? showDeterminationOnlyForFieldUnits.isAllowOverride():true;
-        overrideDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true);
 
         isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
-        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
-        CdmPreference showTaxonAssociation = cache.findBestMatching(key);
+        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
+        showTaxonAssociation = cache.findBestMatching(key);
+        if (showTaxonAssociation == null){
+            showTaxonAssociation = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, PreferencePredicate.ShowTaxonAssociations.getDefaultValue() != null ?  PreferencePredicate.ShowTaxonAssociations.getDefaultValue().toString(): null);
+        }
         allowOverrideShowTaxonAssociation = showTaxonAssociation != null ? showTaxonAssociation.isAllowOverride():true;
-        overrideShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowTaxonAssociations.getKey()), true);
 
         isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
-        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
-        CdmPreference showLifeForm = cache.findBestMatching(key);
+        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
+        showLifeForm = cache.findBestMatching(key);
+        if (showLifeForm == null){
+            showLifeForm = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, PreferencePredicate.ShowLifeForm.getDefaultValue() != null ?  PreferencePredicate.ShowLifeForm.getDefaultValue().toString(): null);
+        }
         allowOverrideShowLifeForm = showLifeForm != null ? showLifeForm.isAllowOverride():true;
-        overrideShowLifeForm = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowLifeForm.getKey()), true);
 
 
     }
@@ -362,23 +290,24 @@ public class SpecimenOrObservationPreferences extends CdmPreferencePage {
     public boolean performOk() {
         if (allowOverrideShowSpecimenRelatedIssues){
             PreferencesUtil.setBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowSpecimen.getKey()), overrideShowSpecimenRelatedIssues);
+            boolean test = isShowSpecimenRelatedIssues != Boolean.parseBoolean(showSpecimenPref.getValue());
+            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowSpecimen.getKey()), isShowSpecimenRelatedIssues != Boolean.parseBoolean(showSpecimenPref.getValue()));
         }
         if (allowOverrideShowCollectingAreaInGeneralSection){
             PreferencesUtil.setBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), overrideShowCollectionAreaInGeneralSection);
+            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), isShowCollectingAreaInGeneralSection != Boolean.parseBoolean(showCollectingAreaInGeneralSection.getValue()));
         }
         if (allowOverrideDeterminationOnlyForFieldUnits){
             PreferencesUtil.setBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), overrideDeterminationOnlyForFieldUnits);
+            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), isDeterminationOnlyForFieldUnits != Boolean.parseBoolean(showDeterminationOnlyForFieldUnits.getValue()));
         }
         if (allowOverrideShowTaxonAssociation){
             PreferencesUtil.setBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowTaxonAssociations.getKey()), overrideShowTaxonAssociation);
+            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowTaxonAssociations.getKey()), isShowTaxonAssociation != Boolean.parseBoolean(showTaxonAssociation.getValue()));
         }
         if (allowOverrideShowLifeForm){
             PreferencesUtil.setBooleanValue(PreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm);
-            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowLifeForm.getKey()), overrideShowLifeForm);
+            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowLifeForm.getKey()), isShowLifeForm != Boolean.parseBoolean(showLifeForm.getValue()));
         }
         return true;
     }
@@ -388,37 +317,128 @@ 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(showSpecimenButton)){
+           String text = showSpecimenButton.getText();
+           text = text.replace(Messages.Preference_Use_Default, "");
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowSpecimenRelatedIssues = true;
+           }else{
+               isShowSpecimenRelatedIssues = false;
+           }
+       }
+       if (e.getSource().equals(showCollectingAreaInGeneralSectionButton)){
+           String text = showCollectingAreaInGeneralSectionButton.getText();
+           text = text.replace(" (Use default)", "");
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowCollectingAreaInGeneralSection = true;
+           }else{
+               isShowCollectingAreaInGeneralSection = false;
+           }
+       }
+
+       if (e.getSource().equals(determinationOnlyForFieldUnitsButton)){
+           String text = determinationOnlyForFieldUnitsButton.getText();
+           text = text.replace(" (Use default)", "");
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isDeterminationOnlyForFieldUnits = true;
+           }else{
+               isDeterminationOnlyForFieldUnits = false;
+           }
+       }
+       if (e.getSource().equals(showTaxonAssociationButton)){
+           String text = showTaxonAssociationButton.getText();
+           text = text.replace(" (Use default)", "");
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowTaxonAssociation = true;
+           }else{
+               isShowTaxonAssociation = false;
+           }
+       }
+       if (e.getSource().equals(showLifeFormButton)){
+           String text = showLifeFormButton.getText();
+           text = text.replace(" (Use default)", "");
+           if (text.equals(Messages.GeneralPreference_yes)){
+               isShowLifeForm = true;
+           }else{
+               isShowLifeForm = false;
+           }
+       }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void widgetDefaultSelected(SelectionEvent e) {
+        // TODO Auto-generated method stub
+
+    }
+
+
+
 
 }
index 38e7be20f2782da0cfb9569c3cf61630665686e0..783c509e1d32c0dbfe4c6222dbd585fee810b819 100644 (file)
@@ -166,11 +166,11 @@ public abstract class CdmPreferencePage extends PreferencePage implements IE4Pre
             defaultValue = (Boolean)predicate.getDefaultValue();
         }
         if (defaultValue){
-            booleanCombo.add(textTrue + " (Use Default)");
+            booleanCombo.add(textTrue + Messages.Preference_Use_Default);
             booleanCombo.add(textFalse);
         }else{
             booleanCombo.add(textTrue);
-            booleanCombo.add(textFalse +" (Use Default)");
+            booleanCombo.add(textFalse + Messages.Preference_Use_Default);
         }
         return booleanCombo;
 
@@ -204,7 +204,7 @@ public abstract class CdmPreferencePage extends PreferencePage implements IE4Pre
 
         for (IKeyLabel value: enumValues){
             if (defaultValue.equals(value.getKey())){
-                booleanCombo.add(value.getLabel() + " (Use Default)");
+                booleanCombo.add(value.getLabel() + Messages.Preference_Use_Default);
             }else{
                 booleanCombo.add(value.getLabel());
             }
index e6d2bdce633f7e48f1753fabb644159081b41e1e..e0c251706d66f044fbda4075a9ccbaad3786a4e9 100644 (file)
@@ -10,7 +10,6 @@ package eu.etaxonomy.taxeditor.preference.menu;
 
 import java.util.List;
 
-import org.eclipse.jface.preference.BooleanFieldEditor;
 import org.eclipse.jface.preference.ComboFieldEditor;
 
 import eu.etaxonomy.cdm.api.application.ICdmRepository;
@@ -40,14 +39,11 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePageE4 {
            PreferencesUtil.setPreferredNomenclaturalCode(null, false);
            if (pref.isAllowOverride()) {
                addField(new ComboFieldEditor(
-                       PreferencesUtil.createPreferenceString(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NomenclaturalCode.getKey())),
+                       PreferencesUtil.createPreferenceString(PreferencePredicate.NomenclaturalCode.getKey()),
                                Messages.NomenclaturalCodePreferences_available_codes, getLabelAndValues(),
                                getFieldEditorParent()));
 
-            addField(new BooleanFieldEditor(
-                    PreferencesUtil.createPreferenceString(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NomenclaturalCode.getKey())),
-                    Messages.NomenclaturalCodePreferences_useLocalCode,
-                    getFieldEditorParent()));
+
         } else {
             setDescription(Messages.NomenclaturalCodePreferences_localChangesNotAllowed);
         }
@@ -61,9 +57,16 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePageE4 {
                List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
                                .getSupportedCodes();
                String[][] labelAndValues = new String[supportedCodes.size()][2];
+               String label;
                for (int i = 0; i < supportedCodes.size(); i++) {
-                       labelAndValues[i][0] = NomenclaturalCodeHelper
-                                       .getDescription(supportedCodes.get(i));
+                   label = NomenclaturalCodeHelper
+                    .getDescription(supportedCodes.get(i));
+                   String value = supportedCodes.get(i).toString();
+                   String prefValue = pref.getValue();
+                   if (pref.getValue().equals(supportedCodes.get(i).toString())) {
+                        label +=Messages.Preference_Use_Default;
+            }
+                   labelAndValues[i][0] = label;
                        labelAndValues[i][1] = PreferencesUtil
                                        .getPreferenceKey(supportedCodes.get(i));
                }
@@ -104,17 +107,15 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePageE4 {
         public boolean performOk() {
 
                boolean result = super.performOk();
-//             if (result){
-//                     String value = getPreferenceStore().getString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY);
-//                     CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
-//                     ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
-//                     if (controller == null){
-//                             return false;
-//                     }
-//                     IPreferenceService service = controller.getPreferenceService();
-//                     service.set(pref);
-//             }
-        return result;
-    }
+               String value = pref.getValue();
+               String test = PreferencesUtil.getStringValue(PreferencePredicate.NomenclaturalCode.getKey(), true);
+               if (!pref.getValue().equals(PreferencesUtil.getStringValue(PreferencePredicate.NomenclaturalCode.getKey(), true))) {
+            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NomenclaturalCode.getKey()), true);
+        }else{
+            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NomenclaturalCode.getKey()), false);
+        }
+               return result;
+       }
+
 
 }
index 1cc10f5d8e10efd31dcd7ab28cdd6548a4748405..1ff6d85363bc6badfc5fbc3f1a154fccf57835d1 100755 (executable)
@@ -84,14 +84,16 @@ public class AvailableVocabularyWizard extends Wizard implements IConversationEn
         Object[] checkedElements = aPage.getViewer().getCheckedElements();
 
         ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
+        int countChecked = 0;
         for (Object o : checkedElements) {
             if(o instanceof TermVocabularyDto){
                 TermVocabularyDto vocDto = (TermVocabularyDto) o;
                 listUIIDChecked.add(vocDto.getUuid());
+                countChecked++;
             }
         }
         String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
-
+        int countVoc = aPage.getVocabularies().size();
         String predicate = null;
         pref = aPage.getPreference();
         if (pref != null){
@@ -99,7 +101,7 @@ public class AvailableVocabularyWizard extends Wizard implements IConversationEn
         }
 
         if (!localPref){
-            if (StringUtils.isBlank(saveCheckedElements)){
+            if (StringUtils.isBlank(saveCheckedElements) || countChecked == countVoc){
                 saveCheckedElements = null;
             }
             CdmPreference savePref = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.getByKey(predicate), saveCheckedElements);