ref #7793: fix named area and commonNameArea selection filter
authorKatja Luther <k.luther@bgbm.org>
Fri, 19 Oct 2018 21:25:10 +0000 (23:25 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 19 Oct 2018 21:25:10 +0000 (23:25 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/VokabularyAdminPreferences.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/CommonNameNamedAreaSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/FilterDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java

index 5600ecd3ffebfc0fc6a918b117440e5b6c43d47f..b5462270760d69ad8d3ffb311eaefd33715e58aa 100755 (executable)
@@ -68,5 +68,12 @@ public class VokabularyAdminPreferences extends CdmPreferencePage implements IE4
         return composite;
     }
 
+    @Override
+    public boolean performOk() {
+        PreferencesUtil.updateDBPreferences();
+        return true;
+
+    }
+
 
 }
index 82f64da5cd5f1ce3e16af6a542a1c887ab7c435d..2d3e206fe0839b6a785a480eea4a02dd86d8a6df 100644 (file)
@@ -145,6 +145,8 @@ public interface IPreferenceKeys {
     public static final String DISTRIBUTION_AREA_OCCURENCE_STATUS = "eu.etaxonomy.taxeditor.checklist.distributionAreaStatus";
     public static final String DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED = "eu.etaxonomy.taxeditor.checklist.distributionAreaStatusGrayed";
     public static final String DISTRIBUTION_VOCABULARIES = "eu.etaxonomy.taxeditor.checklist.distributionVocabularies";
+    public static final String DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE = "eu.etaxonomy.taxeditor.checklist.distributionVocabulariesAllowOverride";
+    public static final String DISTRIBUTION_VOCABULARIES_OVERRIDE = "eu.etaxonomy.taxeditor.checklist.distributionVocabulariesOverride";
     public static final String CHECKLIST_AREA_DISPLAY = "eu.etaxonomy.taxeditor.checklist.checklistAreaDisplay";
     public static final String CHECKLIST_AREA_DISPLAY_ID_IN_VOCABULARY = "IdInVocabulary";
     public static final String CHECKLIST_AREA_DISPLAY_TITLE = "Title";
@@ -262,4 +264,5 @@ public interface IPreferenceKeys {
 
 
 
+
 }
index b55d6d8b133dd17b1559feec26a06722554d85a2..867bc9be10a11b2f4179964f60a43929c6e048aa 100644 (file)
@@ -1704,9 +1704,13 @@ public static void updateDBPreferences() {
     //Distribution Editor
     preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
     if (preference != null){
-        if (!prefStore.getBoolean(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE) ||  !preference.isAllowOverride()){
+        if (!prefStore.getBoolean(DISTRIBUTION_VOCABULARIES_OVERRIDE) ||  !preference.isAllowOverride()){
             prefStore.setValue(DISTRIBUTION_VOCABULARIES, preference.getValue());
+            prefStore.setValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE, preference.getValue());
         }
+    }else{
+        prefStore.setValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE,true);
+        prefStore.setToDefault(DISTRIBUTION_VOCABULARIES);
     }
 
     preference = getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
@@ -1734,9 +1738,13 @@ public static void updateDBPreferences() {
 
     preference = getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
     if (preference != null){
-        if (!prefStore.getBoolean(COMMON_NAME_AREA_VOCABULARIES_OVERRIDE) ||  !preference.isAllowOverride()){
+        if (!prefStore.getBoolean(COMMON_NAME_AREA_VOCABULARIES) ||  !preference.isAllowOverride()){
             prefStore.setValue(COMMON_NAME_AREA_VOCABULARIES, preference.getValue());
+            prefStore.setValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
         }
+    }else{
+        prefStore.setToDefault(COMMON_NAME_AREA_VOCABULARIES);
+        prefStore.setValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, true);
     }
 
     preference = getPreferenceFromDB(PreferencePredicate.CommonNameReferencesWithMarker);
index 1e4170d4dc1c66ed486ba3e1dd545cb5a3a27884..fa0836c82bb8ee2639d4f8c331e5e21161cf1eff 100755 (executable)
@@ -8,13 +8,20 @@
 */
 package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.swt.widgets.Shell;
 
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * @author k.luther
@@ -40,6 +47,9 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
 
     private static UUID[] createVocabularyUuidList() {
         String preselectedVocString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.COMMON_NAME_AREA_VOCABULARIES);
+        if (StringUtils.isBlank(preselectedVocString)){
+            return null;
+        }
         String[] preselectedVocArray = preselectedVocString.split(";");
         UUID[] uuidList = new UUID[preselectedVocArray.length];
         int i = 0;
@@ -49,6 +59,27 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
         }
         return uuidList;
     }
+    @Override
+    protected void init() {
+        vocabularies = getAvailableVocabularies();
+    }
+
+
+    protected List<TermVocabulary> getAvailableVocabularies(){
+        List<TermVocabulary> vocabularies = new ArrayList();
+
+        if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE)){
+            UUID[] preselectedVocabularyUuids = createVocabularyUuidList();
+
+            for(int i=0;i<preselectedVocabularyUuids.length;i++){
+                TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
+                vocabularies.add(preselectedVocabulary);
+            }
+        }else{
+            vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
+        }
+        return vocabularies;
+    }
 
     /**
      * Creates a filtered selection dialog to select a named area.
index e6a3885648e1aab73aac7ca8cf4756b48ba3b99f..2f7307de2b9020c316d7e4c9a567044c7830b666 100644 (file)
@@ -24,11 +24,8 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 
-import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * @author k.luther
@@ -48,15 +45,15 @@ public class FilterDialog extends Dialog {
     /**
      * @param parentShell
      */
-    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies) {
+    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies, List<TermVocabulary> vocabularies) {
         super(parentShell);
-        vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
+        this.vocabularies = vocabularies;
         this.preferenceId = preferenceId;
         this.selectedVocabularies = selectedVocabularies;
         this.tempSelectedVocabularies = new ArrayList();
         this.tempSelectedVocabularies.addAll(selectedVocabularies);
-       
-       
+
+
     }
 
     @Override
@@ -114,7 +111,7 @@ public class FilterDialog extends Dialog {
 
     @Override
     protected void okPressed(){
-       
+
         for (TermVocabulary voc: vocabularies){
             if (tempSelectedVocabularies.contains(voc)){
                 PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), false);
@@ -126,7 +123,7 @@ public class FilterDialog extends Dialog {
         }
         super.okPressed();
     }
-    
+
     private String getPrefKey(TermVocabulary vocabulary){
         return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceId;
     }
index c1317a4a016db63a9189e524c9e899c417da2f59..327383730b035225d7b3464586ec8e7ef6cad7bf 100644 (file)
@@ -13,6 +13,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.Dialog;
@@ -68,7 +69,7 @@ public class NamedAreaSelectionDialog extends
        }
 
        protected List<TermVocabulary> selectedVocabularies;
-    protected ArrayList<TermVocabulary> preselectedVocabularies;
+    protected List<TermVocabulary> vocabularies;
 
 
 
@@ -97,13 +98,16 @@ public class NamedAreaSelectionDialog extends
                super(shell, //conversation,
                        title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
 
-               preselectedVocabularies = new ArrayList<TermVocabulary>();
+               selectedVocabularies = new ArrayList<TermVocabulary>();
+               this.preferenceID = preferenceId;
                if (preselectedVocabularyUuids == null || preselectedVocabularyUuids.length == 0){
                    preselectedVocabularyUuids = createVocabularyUuidList();
                }
-               for(int i=0;i<preselectedVocabularyUuids.length;i++){
-                       TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
-                       preselectedVocabularies.add(preselectedVocabulary);
+               if (preselectedVocabularyUuids != null){
+               for(int i=0;i<preselectedVocabularyUuids.length;i++){
+                       TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
+                       selectedVocabularies.add(preselectedVocabulary);
+               }
                }
 
 
@@ -113,8 +117,8 @@ public class NamedAreaSelectionDialog extends
 
     protected List<TermVocabulary> createSelectedVocabularies() {
         List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
-        for(TermVocabulary vocabulary:selectedVocabularies){
-                       if(preselectedVocabularies.contains(vocabulary)
+        for(TermVocabulary vocabulary:vocabularies){
+                       if((selectedVocabularies.contains(vocabulary) && !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary)))
                                        || !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
                                tempSelectedVocabularies.add(vocabulary);
                        }
@@ -124,6 +128,9 @@ public class NamedAreaSelectionDialog extends
 
     private static UUID[] createVocabularyUuidList() {
         String preselectedVocString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.DISTRIBUTION_VOCABULARIES);
+        if (StringUtils.isBlank(preselectedVocString)){
+            return null;
+        }
         String[] preselectedVocArray = preselectedVocString.split(";");
         UUID[] uuidList = new UUID[preselectedVocArray.length];
         int i = 0;
@@ -154,11 +161,22 @@ public class NamedAreaSelectionDialog extends
        /** {@inheritDoc} */
        @Override
        protected void init() {
-               selectedVocabularies = getAvailableVocabularies();
+               vocabularies = getAvailableVocabularies();
        }
 
        private List<TermVocabulary> getAvailableVocabularies(){
-               List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
+           vocabularies = new ArrayList();
+           if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE)){
+            UUID[] preselectedVocabularyUuids = createVocabularyUuidList();
+
+            for(int i=0;i<preselectedVocabularyUuids.length;i++){
+                TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
+                vocabularies.add(preselectedVocabulary);
+            }
+        }else{
+            vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
+        }
+               //List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
                return vocabularies;
        }
 
@@ -223,7 +241,7 @@ public class NamedAreaSelectionDialog extends
                         String text = null;
                         if (source instanceof Button){
                             Shell shell = ((Button)source).getShell();
-                            Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies);
+                            Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies, vocabularies);
                             if(dialog!=null){
                                 dialog.open();
                             }
@@ -247,20 +265,18 @@ public class NamedAreaSelectionDialog extends
 
         }
 
-    /**
-     *
-     */
-    public void setSelectedVocabularies() {
-        // TODO Auto-generated method stub
 
-    }
 
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)
      */
     @Override
     void callService(String pattern) {
-        model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
+        if (selectedVocabularies == null || selectedVocabularies.size() == 0){
+            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(vocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
+        }else{
+            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
+        }
     }
 
 }