ref #10202: add preference handling
authorKatja Luther <k.luther@bgbm.org>
Fri, 16 Dec 2022 12:43:14 +0000 (13:43 +0100)
committerKatja Luther <k.luther@bgbm.org>
Fri, 16 Dec 2022 12:43:59 +0000 (13:43 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/FactualDataAdminPreferencePage.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/l10n/messages_de.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FactualDataPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceElement.java

index eddbf96043f645afd88ac49b7f830d8e5065d1ed..1f88aad1c99f66ca390c738978a655dead190dcf 100755 (executable)
@@ -34,6 +34,12 @@ public class FactualDataAdminPreferencePage extends FactualDataPreference {
 
         allowOverrideFreeText = getPrefAllowOverride(prefFreeText);
         isShowModifierFreeText = getBooleanPrefValue(prefFreeText);
+        
+        prefShowSpecimenAsSource = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSpecimenInFactSource);
+
+        allowOverrideSpecimen = getPrefAllowOverride(prefShowSpecimenAsSource);
+
+        isShowSpecimenAsSource = getBooleanPrefValue(prefShowSpecimenAsSource);
     }
 
 
@@ -48,6 +54,10 @@ public class FactualDataAdminPreferencePage extends FactualDataPreference {
             prefFreeText = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowModifierFreeText, isShowModifierFreeText != null? Boolean.toString(this.isShowModifierFreeText): null);
             prefFreeText.setAllowOverride(allowOverrideFreeText);
             PreferencesUtil.setPreferenceToDB(prefFreeText);
+            
+            prefShowSpecimenAsSource = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimenInFactSource, isShowSpecimenAsSource != null? Boolean.toString(this.isShowSpecimenAsSource): null);
+            prefShowSpecimenAsSource.setAllowOverride(allowOverrideSpecimen);
+            PreferencesUtil.setPreferenceToDB(prefShowSpecimenAsSource);
             setApply(false);
         }
         return true;
index 41d3e8083456329845a6bfc324fb3815e84124c4..e5c212d93df95091950089a8a1318268b98b6786 100644 (file)
@@ -681,6 +681,8 @@ public class Messages extends NLS {
 
     public static String FactualData_showModifier;
     public static String FactualData_showModifier_FreeText;
+    public static String FactualData_showSpecimenAsSource;
+    
     public static String FactualData_description;
     public static String FactualData_showIdInVocabulary;
     public static String FactualData_showIdInVocabulary_tooltip;
index 749cd3623afd52b633c3f684236e27d4d1eef1fb..41283c20c3ea7cd9a55d0b092a99c08a3b46e54b 100644 (file)
@@ -575,6 +575,7 @@ Delete=Delete
 Preference_update=Update
 FactualData_showModifier=Show modifier
 FactualData_showModifier_FreeText=Show modifier freetext
+FactualData_showSpecimenAsSource=Show specimen as source
 FactualData_description=If a preference is not selectable, there is a serverside preference not allowed to override.
 FactualData_showIdInVocabulary=Show id in vocabulary in area text field
 FactualData_showIdInVocabulary_tooltip=Show id in vocabulary in area text field of details view
index 053879606c6badaadecadbcf20fd4ef1212e3fd4..c50c8c6c5e70578b7e8be18d19b3b70096f20f38 100644 (file)
@@ -572,6 +572,7 @@ Delete=L
 Preference_update=Aktualisieren
 FactualData_showModifier=Zeige Modifier
 FactualData_showModifier_FreeText=Zeige Freitext-Modifier
+FactualData_showSpecimenAsSource=Zeige Specimen als Quelle
 FactualData_description=Wenn die Präferenz nicht ausgewählt werden kann, dann gibt es eine serverseitige Präferenz, die das Überschreiben nicht erlaubt.
 FactualData_showIdInVocabulary=Zeige Id im Vokabular im Areal-Textfeld
 FactualData_showIdInVocabulary_tooltip=Zeige die Id im Vokabular im Areal-Textfeld des Details View
index ed89d334c63debb7ff1f82ec8a054e559c6e1706..d924ec2a7ad626a0b02280542d6616326896a5b4 100755 (executable)
@@ -48,6 +48,15 @@ public class FactualDataPreference extends CdmPreferencePage implements Selectio
 
     protected boolean allowOverrideFreeText;
     private boolean isOverrideFreeText = true;
+    
+    protected Boolean isShowSpecimenAsSource;
+
+    protected Combo comboShowSpecimenAsSource;
+    protected CdmPreference prefShowSpecimenAsSource = null;
+    Button allowOverrideShowSpecimenButton;
+
+    protected boolean allowOverrideSpecimen;
+    private boolean isOverrideSpecimen = true;
 
 
 
@@ -134,6 +143,39 @@ public class FactualDataPreference extends CdmPreferencePage implements Selectio
             comboShowModifierFreeText.setEnabled(allowOverrideFreeText);
         }
 
+        //Show specimen as source
+        comboShowSpecimenAsSource = createBooleanCombo(composite, SHOW, DO_NOT_SHOW, PreferencePredicate.ShowSpecimenInFactSource, Messages.FactualData_showSpecimenAsSource, isAdminPreference);
+        comboShowSpecimenAsSource.addSelectionListener(this);
+        if (this.isAdminPreference){
+            allowOverrideShowSpecimenButton = createAllowOverrideButton(composite);
+            allowOverrideShowSpecimenButton.setSelection(allowOverrideSpecimen);
+            allowOverrideShowSpecimenButton.addSelectionListener(new SelectionAdapter(){
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    allowOverrideSpecimen = !allowOverrideSpecimen;
+                    setApply(true);
+                    }
+            });
+        }
+        index = 0;
+        if(isShowSpecimenAsSource==null){
+               comboShowSpecimenAsSource.select(0);
+        } else{
+            for (String itemLabel : comboShowSpecimenAsSource.getItems()){
+                if (itemLabel.startsWith(this.SHOW) && isShowSpecimenAsSource){
+                       comboShowSpecimenAsSource.select(index);
+                    break;
+                }
+                if (itemLabel.startsWith(DO_NOT_SHOW) && !isShowSpecimenAsSource){
+                       comboShowSpecimenAsSource.select(index);
+                    break;
+                }
+                index++;
+            }
+        }
+        if (!isAdminPreference){
+               comboShowSpecimenAsSource.setEnabled(allowOverrideSpecimen);
+        }
 
         return composite;
 
@@ -157,6 +199,14 @@ public class FactualDataPreference extends CdmPreferencePage implements Selectio
             }else{
                 PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey()), false);
             }
+            
+            if (isShowSpecimenAsSource != null){
+                PreferencesUtil.setStringValue(PreferencePredicate.ShowSpecimenInFactSource.getKey(), Boolean.toString(isShowSpecimenAsSource));
+                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimenInFactSource.getKey()), true);
+
+            }else{
+                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimenInFactSource.getKey()), false);
+            }
 
         }
         return true;
@@ -176,7 +226,7 @@ public class FactualDataPreference extends CdmPreferencePage implements Selectio
             isShowModifier = Boolean.valueOf(showModifierString);
         }
 
-        isOverride = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifier.getKey()));
+        isOverride = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifier.getKey()), true);
         if (!isOverride){
            isShowModifier = null;
         }
@@ -193,10 +243,27 @@ public class FactualDataPreference extends CdmPreferencePage implements Selectio
             isShowModifierFreeText = Boolean.valueOf(showModifierStringFreeText);
         }
 
-        isOverrideFreeText = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey()));
+        isOverrideFreeText = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey()), true);
         if (!isOverrideFreeText){
            isShowModifierFreeText = null;
         }
+        
+     // get specimen values
+        prefShowSpecimenAsSource = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSpecimenInFactSource);
+        if (prefShowSpecimenAsSource == null){
+               prefShowSpecimenAsSource = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimenInFactSource, PreferencePredicate.ShowSpecimenInFactSource.getDefaultValue().toString());
+        }
+        allowOverrideSpecimen = prefShowSpecimenAsSource.isAllowOverride();
+        isShowSpecimenAsSource = null;
+        String showSpecimenString = PreferencesUtil.getStringValue(PreferencePredicate.ShowSpecimenInFactSource.getKey(), true);
+        if (showSpecimenString != null){
+               isShowSpecimenAsSource = Boolean.valueOf(showSpecimenString);
+        }
+
+        isOverrideSpecimen = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimenInFactSource.getKey()), true);
+        if (!isOverrideSpecimen){
+               isShowSpecimenAsSource = null;
+        }
 
 
     }
@@ -218,6 +285,14 @@ public class FactualDataPreference extends CdmPreferencePage implements Selectio
        if (isAdminPreference){
             allowOverrideFreeTextButton.setSelection(allowOverrideFreeText);
         }
+       
+       isShowSpecimenAsSource = null;
+       allowOverrideSpecimen = true;
+
+       comboShowSpecimenAsSource.select(0);
+       if (isAdminPreference){
+            allowOverrideShowSpecimenButton.setSelection(allowOverrideSpecimen);
+        }
         setApply(true);
         super.performDefaults();
     }
@@ -254,6 +329,23 @@ public class FactualDataPreference extends CdmPreferencePage implements Selectio
             }
 
         }
+        
+        if (e.getSource().equals(this.comboShowSpecimenAsSource)) {
+            String text = comboShowSpecimenAsSource.getText();
+            if (text.startsWith(Messages.Preference_Use_Default)){
+                isOverrideSpecimen = false;
+                isShowSpecimenAsSource = null;
+
+            }else if (text.equals(SHOW)){
+               isShowSpecimenAsSource = true;
+               isOverrideSpecimen = true;
+            }else{
+               isShowSpecimenAsSource = false;
+               isOverrideSpecimen = true;
+            }
+
+        }
+
         setApply(true);
 
     }
index 770d6be93d84e00c1eb6ade0bde4d500cbe24b4f..49729085de8b10bc82ea4e5ad5ff7e30fa018da6 100644 (file)
@@ -52,10 +52,12 @@ public class DescriptionElementSourceElement extends
                                .createSelectionElement(TaxonName.class,
                                        formElement, "Name in Source",
                                                null, EntitySelectionElement.ALL, SWT.NULL);
-               selection_specimen = formFactory
-                               .createSelectionElement(SpecimenOrObservationBase.class,
-                                       formElement, "Specimen",
-                                               null, EntitySelectionElement.ALL, SWT.NULL);
+               if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimenInFactSource.getKey())) {
+                       selection_specimen = formFactory
+                                       .createSelectionElement(SpecimenOrObservationBase.class,
+                                               formElement, "Specimen",
+                                                       null, EntitySelectionElement.ALL, SWT.NULL);
+               }
                externalLinks = formFactory.createExternalLinksSection(formElement, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
         externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
         if (getEntity() != null){
@@ -78,7 +80,9 @@ public class DescriptionElementSourceElement extends
                        text_referenceDetail.setText(entity.getCitationMicroReference());
                        text_originalInfo.setText(entity.getOriginalInfo());
                        selection_name.setEntity(entity.getNameUsedInSource());
-                       selection_specimen.setEntity(entity.getSpecimen());
+                       if (selection_specimen != null) {
+                               selection_specimen.setEntity(entity.getSpecimen());
+                       }
                        combo_origsourcetype.setSelection(entity.getType());
                        externalLinks.setEntity(entity);
                }