fix #6049 Store vocabulary filters for NamedArea selection dialogs in
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 1 Sep 2016 15:11:37 +0000 (17:11 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 2 Sep 2016 06:03:23 +0000 (08:03 +0200)
preferences
 - when passing pre-selected vocabularies programmatically these will
ignore the preferences and will always be selected

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java

index 055fd74cbbe41fc27ae496f6722b1d261df2d5a8..3ce78078176180b8192a39bdfb7406455a8dfd11 100644 (file)
@@ -34,6 +34,7 @@ import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -62,6 +63,7 @@ public class NamedAreaSelectionDialog extends
                        }else{
                                selectedVocabularies.remove(vocabulary);
                        }
+                       PreferencesUtil.getPreferenceStore().setValue(getPrefKey(vocabulary), isChecked());
                        initModel();
                }
        }
@@ -89,15 +91,20 @@ public class NamedAreaSelectionDialog extends
 
        protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
                super(shell, conversation, title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
-               if(preselectedVocabularyUuids.length>0){
-                   preselectedVocabularies = new ArrayList<TermVocabulary>();
-                   for(int i=0;i<preselectedVocabularyUuids.length;i++){
-                       TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
-                       preselectedVocabularies.add(preselectedVocabulary);
-                   }
-                   selectedVocabularies.retainAll(preselectedVocabularies);
-                   initModel();//re-init to consider pre-selected vocabularies
+               preselectedVocabularies = new ArrayList<TermVocabulary>();
+               for(int i=0;i<preselectedVocabularyUuids.length;i++){
+                       TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
+                       preselectedVocabularies.add(preselectedVocabulary);
                }
+               Collection<TermVocabulary> tempSelectedVocabularies = new HashSet<>();
+               for(TermVocabulary vocabulary:selectedVocabularies){
+                       if(preselectedVocabularies.contains(vocabulary)
+                                       || PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
+                               tempSelectedVocabularies.add(vocabulary);
+                       }
+               }
+               selectedVocabularies = tempSelectedVocabularies;
+               initModel();//re-init to consider pre-selected vocabularies
        }
 
        /** {@inheritDoc} */
@@ -109,11 +116,18 @@ public class NamedAreaSelectionDialog extends
                for(TermVocabulary<NamedArea> vocabulary : getAvailableVocabularies()){
                        IncludeNamedAreaVocabulary action = new IncludeNamedAreaVocabulary(vocabulary);
                        menuManager.add(action);
-                       if(preselectedVocabularies==null || preselectedVocabularies.isEmpty() || preselectedVocabularies.contains(vocabulary)) {
+                       if(preselectedVocabularies.contains(vocabulary)) {
                            action.setChecked(true);
                        }
+                       else{
+                               action.setChecked(PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary)));
+                       }
                }
        }
+       
+       private String getPrefKey(TermVocabulary vocabulary){
+               return NamedAreaSelectionDialog.class.toString()+vocabulary.getUuid();
+       }
 
        /** {@inheritDoc} */
        @Override
@@ -133,6 +147,9 @@ public class NamedAreaSelectionDialog extends
        @Override
        protected void init() {
                selectedVocabularies = getAvailableVocabularies();
+               for(TermVocabulary vocabulary:selectedVocabularies){
+                       PreferencesUtil.getPreferenceStore().setDefault(getPrefKey(vocabulary), true);
+               }
        }
 
        private List<TermVocabulary> getAvailableVocabularies(){
index f45adb155aa90406699a326606c3b69de21ca977..b2eb369697a60c3c06683e92915d924829002f12 100644 (file)
@@ -45,7 +45,6 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
 import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
-import eu.etaxonomy.taxeditor.ui.section.description.detail.DistributionDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
 
@@ -126,10 +125,7 @@ public class SelectionDialogFactory {
                    return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, conversation, (SpecimenOrObservationBase) currentSelection);
                }
                if(clazz.equals(NamedArea.class)){
-                   if(parentElement instanceof DistributionDetailElement){
-//                return (T) NamedAreaSelectionForDistributionDialog.select(shell, conversation, (NamedArea) currentSelection, CdmStore.getTermManager().getPreferredVocabulary(TermType.NamedArea));
-                return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
-                   }else if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
+                   if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
                        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
                    }
                    else{