Pre-select country as named area type for country selection for
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 1 Oct 2015 06:08:28 +0000 (08:08 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 1 Oct 2015 08:55:07 +0000 (10:55 +0200)
specimens (#2353)

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/selection/EntitySelectionElement.java

index b9c1b5c078706fe7163a898c2115659ec29756cf..dc1ce081de1037bf229965bc79c480c40cf94b79 100644 (file)
@@ -63,12 +63,12 @@ public class NamedAreaSelectionDialog extends
                        }else{
                                selectedVocabularies.remove(vocabulary);
                        }
-
                        initModel();
                }
        }
 
        private Collection<TermVocabulary<NamedArea>> selectedVocabularies;
+    private final ArrayList<TermVocabulary> preselectedVocabularies;
 
 
        /**
@@ -79,11 +79,12 @@ 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 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) {
+       public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
                NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, conversation,
-                               "Choose an area", false, namedArea);
+                               "Choose an area", false, namedArea, preselectedVocabularyUuids);
                return getSelectionFromDialog(dialog);
        }
 
@@ -95,9 +96,17 @@ public class NamedAreaSelectionDialog extends
         * @param title a {@link java.lang.String} object.
         * @param multi a boolean.
         * @param namedArea a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
+        * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected Vocabularies
         */
-       protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea) {
+       protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
                super(shell, conversation, title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
+               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
        }
 
        /** {@inheritDoc} */
@@ -106,10 +115,12 @@ public class NamedAreaSelectionDialog extends
 
                super.fillViewMenu(menuManager);
 
-               for(TermVocabulary<NamedArea> vocabulary : getVocabularies()){
+               for(TermVocabulary<NamedArea> vocabulary : getAvailableVocabularies()){
                        IncludeNamedAreaVocabulary action = new IncludeNamedAreaVocabulary(vocabulary);
                        menuManager.add(action);
-                       action.setChecked(true);
+                       if(preselectedVocabularies.isEmpty() || preselectedVocabularies.contains(vocabulary)) {
+                           action.setChecked(true);
+                       }
                }
        }
 
@@ -130,10 +141,10 @@ public class NamedAreaSelectionDialog extends
        /** {@inheritDoc} */
        @Override
        protected void init() {
-               selectedVocabularies = getVocabularies();
+               selectedVocabularies = getAvailableVocabularies();
        }
 
-       private List<TermVocabulary<NamedArea>> getVocabularies(){
+       private List<TermVocabulary<NamedArea>> getAvailableVocabularies(){
                List<TermVocabulary<NamedArea>> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermClass(NamedArea.class, null, null, null, null);
                vocabularies.add(CdmStore.getService(IVocabularyService.class).find(Country.uuidCountryVocabulary));
                return vocabularies;
index 93f7108d0c31bf32b3640ca560afa2ca676a67ed..f6752d97249a171a4889be32dccbf539e6062731 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.ui.dialog.selection;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.Institution;
 import eu.etaxonomy.cdm.model.agent.Person;
@@ -25,6 +26,7 @@ import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.cdm.model.location.Country;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.molecular.Amplification;
 import eu.etaxonomy.cdm.model.molecular.Primer;
@@ -39,6 +41,8 @@ import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
 
 /**
  * @author n.hoffmann
@@ -47,7 +51,11 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
  */
 public class SelectionDialogFactory {
 
-       public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection){
+    public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection){
+        return getSelectionFromDialog(clazz, shell, conversation, currentSelection, null);
+    }
+
+       public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection, ICdmFormElement parentElement){
 
                if(clazz.equals(Taxon.class)){
                        return (T) TaxonBaseSelectionDialog.selectTaxon(shell, conversation, (Taxon) currentSelection);
@@ -101,7 +109,12 @@ public class SelectionDialogFactory {
                        return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
                }
                if(clazz.equals(NamedArea.class)){
-                       return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
+                   if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
+                       return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
+                   }
+                   else{
+                       return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
+                   }
                }
                if(clazz.equals(Collection.class)){
                        return (T) CollectionSelectionDialog.select(shell, conversation, (Collection) currentSelection);
index 88e9bb723bf99e2b093478774a4c4a2ffb9409f0..6f87d5e634a1e55e677a1b44656a0b7b0657b89b 100644 (file)
@@ -238,7 +238,7 @@ public class EntitySelectionElement<T extends ICdmBase> extends
 
        @Override
     public void widgetSelected(SelectionEvent e) {
-               T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getEntity());
+               T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getEntity(), getParentElement());
                setSelectionInternal(selection);
        }