ref #6058 store named area filters more individually
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 20 Oct 2016 15:09:19 +0000 (17:09 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 20 Oct 2016 15:09:19 +0000 (17:09 +0200)
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
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/CollectingAreasDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/GeoScopeDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/GeoScopePolyKeyDetailSection.java

index 3ce78078176180b8192a39bdfb7406455a8dfd11..024bdd6db4fb41b606cb530cfd6b51656eab2436 100644 (file)
@@ -63,13 +63,14 @@ public class NamedAreaSelectionDialog extends
                        }else{
                                selectedVocabularies.remove(vocabulary);
                        }
-                       PreferencesUtil.getPreferenceStore().setValue(getPrefKey(vocabulary), isChecked());
+                       PreferencesUtil.getPreferenceStore().setValue(getPrefKey(vocabulary), !isChecked());
                        initModel();
                }
        }
 
        protected Collection<TermVocabulary> selectedVocabularies;
     protected ArrayList<TermVocabulary> preselectedVocabularies;
+    private Object preferenceID;
 
 
        /**
@@ -80,17 +81,20 @@ public class NamedAreaSelectionDialog extends
         * @param namedArea
         *                              A namedArea that should be selected when the dialog opens
         * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+        * @param preferenceId a class which is used for generating the preference key so that every 
+        * dialogs can be grouped to have their own preferences depending on this id
         * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies
         * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
         */
-       public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
+       public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea, String preferenceId, UUID... preselectedVocabularyUuids) {
                NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, conversation,
-                               "Choose an area", false, namedArea, preselectedVocabularyUuids);
+                               "Choose an area", false, namedArea, preferenceId, preselectedVocabularyUuids);
                return getSelectionFromDialog(dialog);
        }
 
-       protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
+       protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea, Object preferenceId, UUID... preselectedVocabularyUuids) {
                super(shell, conversation, title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
+               this.preferenceID = preferenceId;
                preselectedVocabularies = new ArrayList<TermVocabulary>();
                for(int i=0;i<preselectedVocabularyUuids.length;i++){
                        TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
@@ -99,7 +103,7 @@ public class NamedAreaSelectionDialog extends
                Collection<TermVocabulary> tempSelectedVocabularies = new HashSet<>();
                for(TermVocabulary vocabulary:selectedVocabularies){
                        if(preselectedVocabularies.contains(vocabulary)
-                                       || PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
+                                       || !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
                                tempSelectedVocabularies.add(vocabulary);
                        }
                }
@@ -120,13 +124,13 @@ public class NamedAreaSelectionDialog extends
                            action.setChecked(true);
                        }
                        else{
-                               action.setChecked(PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary)));
+                               action.setChecked(!PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary)));
                        }
                }
        }
        
        private String getPrefKey(TermVocabulary vocabulary){
-               return NamedAreaSelectionDialog.class.toString()+vocabulary.getUuid();
+               return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID;
        }
 
        /** {@inheritDoc} */
@@ -147,9 +151,6 @@ 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 b2eb369697a60c3c06683e92915d924829002f12..610334db0584e0e3a94ee820b3f6d30d1363f7f4 100644 (file)
@@ -126,10 +126,10 @@ public class SelectionDialogFactory {
                }
                if(clazz.equals(NamedArea.class)){
                    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
-                       return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
+                       return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary);
                    }
                    else{
-                       return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
+                       return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());
                    }
                }
                if(clazz.equals(Collection.class)){
index ce0fc596f2986a86ecd81ca5ad1ab0e7c1308619..3ca63239923cf3c0b200e05b0180941d87a0cd14 100644 (file)
@@ -15,6 +15,7 @@ import java.util.Collection;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.model.location.NamedArea;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.NamedAreaSelectionDialog;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -59,7 +60,7 @@ public class CollectingAreasDetailSection extends AbstractEntityCollectionSectio
        /** {@inheritDoc} */
        @Override
        public NamedArea createNewElement() {
-               NamedArea selection = NamedAreaSelectionDialog.select(getLayoutComposite().getShell(), getConversationHolder(), null);
+               NamedArea selection = NamedAreaSelectionDialog.select(getLayoutComposite().getShell(), getConversationHolder(), null, FieldUnit.class.getCanonicalName());
 
                return selection;
        }
index 8ce8454a5ffa5b33eae62cc7912b55da4255d4af..4c159d941640e14b0b0603988475f06172a42932 100644 (file)
@@ -59,7 +59,7 @@ public class GeoScopeDetailSection extends AbstractEntityCollectionSection<Class
        /** {@inheritDoc} */
        @Override
        public NamedArea createNewElement() {
-               NamedArea selection = NamedAreaSelectionDialog.select(getLayoutComposite().getShell(), getConversationHolder(), null);
+               NamedArea selection = NamedAreaSelectionDialog.select(getLayoutComposite().getShell(), getConversationHolder(), null, Classification.class.getCanonicalName());
 
                return selection;
        }
index 2c5cdc6b92acc1241bd1bac5ce5ce84a3c7263a7..f4858f2a2d15a0100af6bea77b3dffd4e60a3d85 100644 (file)
@@ -42,7 +42,7 @@ public class GeoScopePolyKeyDetailSection extends AbstractEntityCollectionSectio
        /** {@inheritDoc} */
        @Override
        public NamedArea createNewElement() {
-               NamedArea selection = NamedAreaSelectionDialog.select(getLayoutComposite().getShell(), getConversationHolder(), null);
+               NamedArea selection = NamedAreaSelectionDialog.select(getLayoutComposite().getShell(), getConversationHolder(), null, PolytomousKey.class.getCanonicalName());
 
                return selection;
        }