ref #8293: use distribution editor preference for area filter in details view
authorKatja Luther <k.luther@bgbm.org>
Tue, 11 Jun 2019 13:37:34 +0000 (15:37 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 11 Jun 2019 13:37:34 +0000 (15:37 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/NomenclaturalStatusTypeAdminPreference.java [new file with mode: 0755]
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/NamedAreaSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/NomenclaturalStatusTypeAdminPreference.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/NomenclaturalStatusTypeAdminPreference.java
new file mode 100755 (executable)
index 0000000..292293d
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.databaseAdmin.preferencePage;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.commons.lang.StringUtils;
+
+import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.taxeditor.preference.LocalOrDefaultEnum;
+import eu.etaxonomy.taxeditor.preference.NomenclaturalStatusTypePreferences;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @since 05.06.2019
+ *
+ */
+public class NomenclaturalStatusTypeAdminPreference extends NomenclaturalStatusTypePreferences {
+
+
+    public NomenclaturalStatusTypeAdminPreference(){
+        super();
+        setLocalPref(false);
+     }
+
+
+
+    @Override
+    public boolean performOk() {
+        if (!isApply()){
+            return true;
+        }
+        Object[] checkedElements = treeComposite.getViewer().getCheckedElements();
+        List<UUID> listUIIDChecked = new ArrayList<>();
+        List<DefinedTermBase> preferredTerms = new ArrayList<>();
+        for (Object o : checkedElements) {
+            if(o instanceof TermDto){
+                TermDto termDto = (TermDto) o;
+                listUIIDChecked.add(termDto.getUuid());
+                preferredTerms.add(CdmStore.getService(ITermService.class).load(termDto.getUuid()));
+            }
+        }
+        String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
+        if (StringUtils.isBlank(saveCheckedElements)){
+            saveCheckedElements = null;
+        }
+        CdmPreference savePref = CdmPreference.NewTaxEditorInstance(predicate, saveCheckedElements);
+        String text = this.useLocalOrAdmin.getText();
+        if (text.equals(LocalOrDefaultEnum.Database.getLabel()) ){
+            savePref.setAllowOverride(false);
+        }else if (text.equals(LocalOrDefaultEnum.AllowOverride.getLabel())){
+            savePref.setAllowOverride(true);
+        }
+
+        PreferencesUtil.setPreferenceToDB(savePref);
+        PreferencesUtil.updateDBPreferences();
+        PreferencesUtil.firePreferencesChanged(this.getClass());
+        return true;
+
+    }
+}
index e6d87905a40fad223a73c1926945853d48bd73ef..5a0fb678bdb318f4eac8ca5f217aabb980cf825f 100755 (executable)
@@ -16,11 +16,13 @@ import org.apache.commons.lang.StringUtils;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.term.TermType;
-import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -48,7 +50,7 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
     }
 
     private static UUID[] createVocabularyUuidList() {
-        String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.CommonNameAreaVocabularies.getKey());
+        String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.CommonNameAreaVocabularies.getKey(), false);
         if (StringUtils.isBlank(preselectedVocString)){
             return null;
         }
@@ -72,17 +74,23 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
 
         UUID[] preselectedVocabularyUuids = createVocabularyUuidList();
         CdmPreferenceCache cache = CdmPreferenceCache.instance();
-        CdmPreference pref = cache.get(PreferencePredicate.CommonNameAreaVocabularies.getKey());
+        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.CommonNameAreaVocabularies);
+        CdmPreference pref = cache.findBestMatching(key);
+        if (preselectedVocabularyUuids != null){
+            for(int i=0;i<preselectedVocabularyUuids.length;i++){
+                TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
+                vocabularies.add(preselectedVocabulary);
+            }
+        }
         if ((pref != null && !pref.isAllowOverride()) && preselectedVocabularyUuids!=null) {
-                for(int i=0;i<preselectedVocabularyUuids.length;i++){
-                    TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
-                    vocabularies.add(preselectedVocabulary);
-                }
+             return vocabularies;
         }else{
-            vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
+            selectedVocabularies = vocabularies;
+
+            return CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
         }
 
-        return vocabularies;
+
     }
 
     /**
@@ -104,4 +112,6 @@ public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog
                 "Choose an area", false, namedArea, preferenceId);
         return getSelectionFromDialog(dialog);
     }
+
+
 }
index 5bd973b915c0428456e577d737dda478d4b525b4..b1808a5b27e34088819949a230cb4daf4ab01858 100644 (file)
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.ui.dialog.selection;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-
-import eu.etaxonomy.cdm.api.service.ITermService;
-import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.location.NamedArea;
-import eu.etaxonomy.cdm.model.term.DefinedTermBase;
-import eu.etaxonomy.cdm.model.term.TermType;
-import eu.etaxonomy.cdm.model.term.TermVocabulary;
-import eu.etaxonomy.taxeditor.model.ImageResources;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
-import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-/**
- * @author n.hoffmann
- * @created May 11, 2010
- * @version 1.0
- */
-public class NamedAreaSelectionDialog extends
-               AbstractFilteredCdmResourceSelectionDialog<NamedArea> {
-
-       private class IncludeNamedAreaVocabulary extends Action {
-               private final TermVocabulary<NamedArea> vocabulary;
-
-               /**
-                * Creates a new instance of the class.
-                */
-               public IncludeNamedAreaVocabulary(TermVocabulary<NamedArea> vocabulary) {
-                       super(vocabulary.getTitleCache(), IAction.AS_CHECK_BOX);
-                       this.vocabulary = vocabulary;
-               }
-
-               @Override
-        public void run(){
-                       if(isChecked()){
-                               selectedVocabularies.add(vocabulary);
-                       }else{
-                               selectedVocabularies.remove(vocabulary);
-                       }
-                       PreferencesUtil.setBooleanValue(getPrefKey(vocabulary), !isChecked());
-                       search();
-               }
-       }
-
-       protected List<TermVocabulary> selectedVocabularies;
-    protected List<TermVocabulary> vocabularies;
-
-
-
-       /**
-        * Creates a filtered selection dialog to select a named area.
-        *
-        * @param shell
-        *                              The shell for displaying this widget
-        * @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, String preferenceId, UUID... preselectedVocabularyUuids) {
-               NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, //conversation,
-                               "Choose an area", false, namedArea, preferenceId, preselectedVocabularyUuids);
-               return getSelectionFromDialog(dialog);
-       }
-
-       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);
-
-               selectedVocabularies = new ArrayList<TermVocabulary>();
-               this.preferenceID = preferenceId;
-
-               if (preselectedVocabularyUuids != null && preselectedVocabularyUuids.length > 0){
-               for(int i=0;i<preselectedVocabularyUuids.length;i++){
-                       TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
-                       selectedVocabularies.add(preselectedVocabulary);
-               }
-               }else{
-                   selectedVocabularies = createSelectedVocabularies();
-               }
-
-       }
-
-    protected List<TermVocabulary> createSelectedVocabularies() {
-        List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
-        for(TermVocabulary vocabulary:vocabularies){
-                       if((selectedVocabularies.contains(vocabulary) && !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary)))
-                                       || !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))){
-                               tempSelectedVocabularies.add(vocabulary);
-                       }
-               }
-        return tempSelectedVocabularies;
-    }
-
-//    private static UUID[] createVocabularyUuidList() {
-//        String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
-//        if (StringUtils.isBlank(preselectedVocString)){
-//            return null;
-//        }
-//        String[] preselectedVocArray = preselectedVocString.split(";");
-//        UUID[] uuidList = new UUID[preselectedVocArray.length];
-//        int i = 0;
-//        for (String uuidString: preselectedVocArray){
-//            uuidList[i]= UUID.fromString(uuidString);
-//            i++;
-//        }
-//        return uuidList;
-//    }
-
-
-       private String getPrefKey(TermVocabulary vocabulary){
-               return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID;
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       protected NamedArea getPersistentObject(UUID uuid) {
-
-           DefinedTermBase area =  CdmStore.getService(ITermService.class).find(uuid);
-           if (area instanceof NamedArea){
-               return (NamedArea) area;
-           }
-
-               return null;
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       protected void init() {
-               vocabularies = getAvailableVocabularies();
-       }
-
-       private List<TermVocabulary> getAvailableVocabularies(){
-           vocabularies = new ArrayList();
-           CdmPreferenceCache cache = CdmPreferenceCache.instance();
-//        CdmPreference pref = cache.get(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
-//         if (pref != null && !pref.isAllowOverride()){
-//            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;
-       }
-
-//     /** {@inheritDoc} */
-//     @Override
-//     protected void search() {
-//         Control control =getSearchField();
-//        String pattern = null;
-//        if (control != null){
-//            pattern = ((Text)control).getText();
-//        }
-//
-//        if (pattern == null || pattern.equals("?")){
-//            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, null, PreferencesUtil.getGlobalLanguage());
-//        }else{
-//            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
-//        }
-//     }
-
-//     /** {@inheritDoc} */
-//     @Override
-//     protected Control createExtendedContentArea(Composite parent) {
-//             return null;
-//     }
-
-       /** {@inheritDoc} */
-       @Override
-       protected String getTitle(NamedArea namedArea) {
-               try {
-                       String result = NamedArea.labelWithLevel(namedArea, CdmStore.getDefaultLanguage());
-                       return result;
-               } catch (Exception e) {
-                       MessagingUtils.error(NamedAreaSelectionDialog.class, "Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid(), e);
-                       return namedArea.getTitleCache();
-               }
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
-               return null;
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       protected String[] getNewWizardText() {
-               return null;
-       }
-
-       @Override
-    void createFilterButton(Composite searchAndFilter)
-           {
-            filterButton = new Button(searchAndFilter, SWT.NONE);
-//            filterButton.setText("Filter");
-            filterButton.setImage(ImageResources.getImage(ImageResources.FUNNEL_ICON));
-//            SelectionListener filterSelectionListener = new FilterSelectionListener(preferenceID, this);
-            filterButton.addSelectionListener(new SelectionListener(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-
-                        Object source = e.getSource();
-                        String text = null;
-                        if (source instanceof Button){
-                            Shell shell = ((Button)source).getShell();
-                            Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies, vocabularies);
-                            if(dialog!=null){
-                                dialog.open();
-                            }
-                            createSelectedVocabularies();
-                            search();
-                        }
-
-
-
-
-                }
-
-                @Override
-                public void widgetDefaultSelected(SelectionEvent e) {
-                    // TODO Auto-generated method stub
-
-                }
-
-
-            });
-
-        }
-
-
-
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)
-     */
-    @Override
-    void callService(String pattern) {
-        if (selectedVocabularies == null || selectedVocabularies.size() == 0){
-            model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(vocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
-        }else{
-            model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
-        }
-    }
-
-}
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.taxeditor.ui.dialog.selection;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.UUID;\r
+\r
+import org.eclipse.jface.action.Action;\r
+import org.eclipse.jface.action.IAction;\r
+import org.eclipse.jface.dialogs.Dialog;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Shell;\r
+\r
+import eu.etaxonomy.cdm.api.service.ITermService;\r
+import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
+import eu.etaxonomy.cdm.model.location.NamedArea;\r
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;\r
+import eu.etaxonomy.cdm.model.term.TermType;\r
+import eu.etaxonomy.cdm.model.term.TermVocabulary;\r
+import eu.etaxonomy.taxeditor.model.ImageResources;\r
+import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
+import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;\r
+import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;\r
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;\r
+import eu.etaxonomy.taxeditor.store.CdmStore;\r
+\r
+/**\r
+ * @author n.hoffmann\r
+ * @created May 11, 2010\r
+ * @version 1.0\r
+ */\r
+public class NamedAreaSelectionDialog extends\r
+               AbstractFilteredCdmResourceSelectionDialog<NamedArea> {\r
+\r
+       private class IncludeNamedAreaVocabulary extends Action {\r
+               private final TermVocabulary<NamedArea> vocabulary;\r
+\r
+               /**\r
+                * Creates a new instance of the class.\r
+                */\r
+               public IncludeNamedAreaVocabulary(TermVocabulary<NamedArea> vocabulary) {\r
+                       super(vocabulary.getTitleCache(), IAction.AS_CHECK_BOX);\r
+                       this.vocabulary = vocabulary;\r
+               }\r
+\r
+               @Override\r
+        public void run(){\r
+                       if(isChecked()){\r
+                               selectedVocabularies.add(vocabulary);\r
+                       }else{\r
+                               selectedVocabularies.remove(vocabulary);\r
+                       }\r
+                       PreferencesUtil.setBooleanValue(getPrefKey(vocabulary), !isChecked());\r
+                       search();\r
+               }\r
+       }\r
+       protected List<NamedArea> selectedAreas;\r
+       protected List<TermVocabulary> selectedVocabularies;\r
+    protected List<TermVocabulary> vocabularies;\r
+\r
+\r
+\r
+       /**\r
+        * Creates a filtered selection dialog to select a named area.\r
+        *\r
+        * @param shell\r
+        *                              The shell for displaying this widget\r
+        * @param namedArea\r
+        *                              A namedArea that should be selected when the dialog opens\r
+        * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.\r
+        * @param preferenceId a class which is used for generating the preference key so that every\r
+        * dialogs can be grouped to have their own preferences depending on this id\r
+        * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies\r
+        * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.\r
+        */\r
+       public static NamedArea select(Shell shell, //ConversationHolder conversation,\r
+               NamedArea namedArea, String preferenceId, UUID... preselectedVocabularyUuids) {\r
+               NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, //conversation,\r
+                               "Choose an area", false, namedArea, preferenceId, preselectedVocabularyUuids);\r
+               return getSelectionFromDialog(dialog);\r
+       }\r
+\r
+       protected NamedAreaSelectionDialog(Shell shell, //ConversationHolder conversation,\r
+               String title, boolean multi, NamedArea namedArea, Object preferenceId, UUID... preselectedVocabularyUuids) {\r
+               super(shell, //conversation,\r
+                       title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);\r
+\r
+               selectedVocabularies = new ArrayList<TermVocabulary>();\r
+               this.preferenceID = preferenceId;\r
+\r
+               if (preselectedVocabularyUuids != null && preselectedVocabularyUuids.length > 0){\r
+               for(int i=0;i<preselectedVocabularyUuids.length;i++){\r
+                       TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);\r
+                       selectedVocabularies.add(preselectedVocabulary);\r
+               }\r
+               }else{\r
+                   selectedVocabularies = createSelectedVocabularies();\r
+               }\r
+\r
+       }\r
+\r
+    protected List<TermVocabulary> createSelectedVocabularies() {\r
+        List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();\r
+        for(TermVocabulary vocabulary:vocabularies){\r
+                       if((selectedVocabularies.contains(vocabulary) && !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary)))\r
+                                       || !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))){\r
+                               tempSelectedVocabularies.add(vocabulary);\r
+                       }\r
+               }\r
+        return tempSelectedVocabularies;\r
+    }\r
+\r
+//    private static UUID[] createVocabularyUuidList() {\r
+//        String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());\r
+//        if (StringUtils.isBlank(preselectedVocString)){\r
+//            return null;\r
+//        }\r
+//        String[] preselectedVocArray = preselectedVocString.split(";");\r
+//        UUID[] uuidList = new UUID[preselectedVocArray.length];\r
+//        int i = 0;\r
+//        for (String uuidString: preselectedVocArray){\r
+//            uuidList[i]= UUID.fromString(uuidString);\r
+//            i++;\r
+//        }\r
+//        return uuidList;\r
+//    }\r
+\r
+\r
+       private String getPrefKey(TermVocabulary vocabulary){\r
+               return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID;\r
+       }\r
+\r
+       /** {@inheritDoc} */\r
+       @Override\r
+       protected NamedArea getPersistentObject(UUID uuid) {\r
+\r
+           DefinedTermBase area =  CdmStore.getService(ITermService.class).find(uuid);\r
+           if (area instanceof NamedArea){\r
+               return (NamedArea) area;\r
+           }\r
+\r
+               return null;\r
+       }\r
+\r
+       /** {@inheritDoc} */\r
+       @Override\r
+       protected void init() {\r
+               vocabularies = getAvailableVocabularies();\r
+       }\r
+\r
+       private List<TermVocabulary> getAvailableVocabularies(){\r
+           vocabularies = new ArrayList();\r
+           CdmPreferenceCache cache = CdmPreferenceCache.instance();\r
+           vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);\r
+           return vocabularies;\r
+       }\r
+\r
+\r
+\r
+       /** {@inheritDoc} */\r
+       @Override\r
+       protected String getTitle(NamedArea namedArea) {\r
+               try {\r
+                       String result = NamedArea.labelWithLevel(namedArea, CdmStore.getDefaultLanguage());\r
+                       return result;\r
+               } catch (Exception e) {\r
+                       MessagingUtils.error(NamedAreaSelectionDialog.class, "Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid(), e);\r
+                       return namedArea.getTitleCache();\r
+               }\r
+       }\r
+\r
+       /** {@inheritDoc} */\r
+       @Override\r
+       protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {\r
+               return null;\r
+       }\r
+\r
+       /** {@inheritDoc} */\r
+       @Override\r
+       protected String[] getNewWizardText() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+    void createFilterButton(Composite searchAndFilter)\r
+           {\r
+            filterButton = new Button(searchAndFilter, SWT.NONE);\r
+//            filterButton.setText("Filter");\r
+            filterButton.setImage(ImageResources.getImage(ImageResources.FUNNEL_ICON));\r
+//            SelectionListener filterSelectionListener = new FilterSelectionListener(preferenceID, this);\r
+            filterButton.addSelectionListener(new SelectionListener(){\r
+                @Override\r
+                public void widgetSelected(SelectionEvent e) {\r
+\r
+                        Object source = e.getSource();\r
+                        String text = null;\r
+                        if (source instanceof Button){\r
+                            Shell shell = ((Button)source).getShell();\r
+                            Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies, vocabularies);\r
+                            if(dialog!=null){\r
+                                dialog.open();\r
+                            }\r
+                            createSelectedVocabularies();\r
+                            search();\r
+                        }\r
+\r
+\r
+\r
+\r
+                }\r
+\r
+                @Override\r
+                public void widgetDefaultSelected(SelectionEvent e) {\r
+                    // TODO Auto-generated method stub\r
+\r
+                }\r
+\r
+\r
+            });\r
+\r
+        }\r
+\r
+\r
+\r
+    /* (non-Javadoc)\r
+     * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)\r
+     */\r
+    @Override\r
+    void callService(String pattern) {\r
+        if (selectedVocabularies == null || selectedVocabularies.size() == 0){\r
+            model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(vocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());\r
+        }else{\r
+            model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());\r
+        }\r
+    }\r
+\r
+}\r
index c8d9eba8ca668b064b7fdc4c76897294663a502f..111cfab25cf070910e810016c83e24b2223a7e2e 100644 (file)
-/**
-* Copyright (C) 2009 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.taxeditor.ui.dialog.selection;
-
-import org.eclipse.swt.widgets.Shell;
-
-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;
-import eu.etaxonomy.cdm.model.agent.Team;
-import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
-import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
-import eu.etaxonomy.cdm.model.common.Group;
-import eu.etaxonomy.cdm.model.common.ICdmBase;
-import eu.etaxonomy.cdm.model.common.User;
-import eu.etaxonomy.cdm.model.description.Feature;
-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.media.Media;
-import eu.etaxonomy.cdm.model.media.Rights;
-import eu.etaxonomy.cdm.model.molecular.Amplification;
-import eu.etaxonomy.cdm.model.molecular.Primer;
-import eu.etaxonomy.cdm.model.name.TaxonName;
-import eu.etaxonomy.cdm.model.occurrence.Collection;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.Synonym;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.model.term.FeatureTree;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-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.CommonNameSourceElement;
-import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
-
-/**
- * @author n.hoffmann
- * @date Jan 25, 2012
- *
- */
-public class SelectionDialogFactory {
-
-    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) TaxonSelectionDialog.selectTaxon(shell, //conversation,
-                               (Taxon) currentSelection);
-               }
-               if(clazz.equals(Synonym.class)){
-                       return (T) TaxonBaseSelectionDialog.selectSynonym(shell );//,conversation);
-               }
-               if(clazz.equals(TaxonBase.class)){
-                       return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell);//, conversation);
-               }
-               if(clazz.equals(Classification.class)){
-                       return (T) ClassificationSelectionDialog.select(shell, //conversation,
-                               (Classification) currentSelection);
-               }
-               if(clazz.equals(TaxonNode.class)){
-                       return (T) TaxonNodeSelectionDialog.select(shell, //conversation,
-                               null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification().getUuid());
-               }
-               if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){
-                       return (T) NomenclaturalReferenceSelectionDialog.select(shell, //conversation,
-                               (Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement).getEntity().getCombinationAuthorship());
-               }
-               if(clazz.equals(Reference.class) && parentElement instanceof CommonNameSourceElement && PreferencesUtil.getFilterCommonNameReferences()){
-            return (T) CommonNameReferenceSelectionDialog.select(shell, //conversation,
-                    (Reference) currentSelection);
-        }
-               if(clazz.equals(Reference.class)){
-                   if (parentElement instanceof ReferenceDetailElement){
-                       return (T) ReferenceSelectionDialog.select(shell, //conversation,
-                               ((ReferenceDetailElement) parentElement).getEntity(), true);
-                   }
-                       return (T) ReferenceSelectionDialog.select(shell, //conversation,
-                               (Reference) currentSelection);
-               }
-
-               if(clazz.equals(TaxonName.class)){
-                       return (T) NameSelectionDialog.select(shell, //conversation,
-                               (TaxonName) currentSelection);
-               }
-               if(clazz.equals(Team.class)){
-                       return (T) TeamSelectionDialog.select(shell, //conversation,
-                               (Team) currentSelection);
-               }
-               if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){
-            return (T) NomenclaturalAuthorSelectionDialog.select(shell, //conversation,
-                    (TeamOrPersonBase) currentSelection, false);
-        }else if(clazz.equals(TeamOrPersonBase.class)){
-                   //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
-                   return (T) TeamOrPersonBaseSelectionDialog.select(shell, //conversation,
-                           (TeamOrPersonBase) currentSelection, false);
-               }
-               if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){
-                   return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell, //conversation,
-                           (TeamOrPersonBase) currentSelection, true);
-        }
-               if(clazz.equals(AgentBase.class)){
-                       return (T) AgentSelectionDialog.select(shell, //conversation,
-                               (AgentBase) currentSelection, false);
-               }
-               if(clazz.equals(Feature.class)){
-                       return (T) FeatureSelectionDialog.select(shell, //conversation,
-                               (Feature) currentSelection);
-               }
-               if(clazz.equals(FeatureTree.class)){
-                       return (T) FeatureTreeSelectionDialog.select(shell, //conversation,
-                               (FeatureTree) currentSelection);
-               }
-               if(clazz.equals(PolytomousKey.class)){
-                       return (T) PolytomousKeySelectionDialog.select(shell, //conversation,
-                               (PolytomousKey) currentSelection);
-               }
-               if(clazz.equals(PolytomousKeyNode.class)){
-                       MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,
-                                       "This functionality is not implemented yet.");
-                       return null;
-               }
-               if(clazz.equals(DerivedUnit.class)){
-                   return (T) DerivedUnitSelectionDialog.select(shell, //conversation,
-                           (DerivedUnit) currentSelection);
-               }
-               if(clazz.equals(FieldUnit.class)){
-                   return (T) FieldUnitSelectionDialog.select(shell, //conversation,
-                           (FieldUnit) currentSelection);
-               }
-               if(clazz.equals(SpecimenOrObservationBase.class)){
-                   return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, //conversation,
-                           (SpecimenOrObservationBase) currentSelection);
-               }
-               if(clazz.equals(NamedArea.class)){
-                   if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
-                       return (T) NamedAreaSelectionDialog.select(shell, //conversation,
-                               (NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary);
-                   }
-                   else if(parentElement instanceof CommonNameDetailElement ){
-                return (T) CommonNameNamedAreaSelectionDialog.select(shell, //conversation,
-                        (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());
-            }
-                   else{
-                       return (T) NamedAreaSelectionDialog.select(shell, //conversation,
-                               (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());
-                   }
-               }
-               if(clazz.equals(Collection.class)){
-                       return (T) CollectionSelectionDialog.select(shell, //conversation,
-                               (Collection) currentSelection);
-               }
-               if(clazz.equals(User.class) && parentElement instanceof MemberDetailElement){
-                   MemberDetailSection section = (MemberDetailSection)((MemberDetailElement)parentElement).getParentElement();
-                       return (T) UserSelectionDialog.select(shell, //conversation,
-                               (User) currentSelection, section.getEntity());
-               }
-               if(clazz.equals(GrantedAuthorityImpl.class)){
-                       return (T) GrantedAuthoritySelectionDialog.select(shell, //conversation,
-                               (GrantedAuthorityImpl) currentSelection);
-               }
-               if (clazz.equals(Person.class)){
-                       return (T) PersonSelectionDialog.select(shell, //conversation,
-                               (Person) currentSelection);
-               }
-               if(clazz.equals(Group.class) &&  parentElement instanceof GroupsByUserDetailElement){
-                   GroupsByUserDetailSection section =(GroupsByUserDetailSection)((GroupsByUserDetailElement)parentElement).getParentElement();
-                       return (T) GroupSelectionDialog.select(shell, //conversation,
-                               (Group) currentSelection, section.getEntity());
-               }
-               if(clazz.equals(Institution.class)){
-                       return (T) InstitutionSelectionDialog.select(shell, //conversation,
-                               (Institution) currentSelection);
-               }
-               if(clazz.equals(Primer.class)){
-                   return (T) PrimerSelectionDialog.select(shell, //conversation,
-                           (Primer) currentSelection);
-               }
-               if(clazz.equals(Amplification.class)){
-                   return (T) AmplificationSelectionDialog.select(shell, //conversation,
-                           (Amplification) currentSelection);
-               }
-               if(clazz.equals(Media.class)){
-                   return (T) MediaSelectionDialog.select(shell, //conversation,
-                           (Media) currentSelection);
-               }
-               if(clazz.equals(Rights.class)){
-            return (T) RightsSelectionDialog.select(shell, //conversation,
-                    (Rights) currentSelection);
-        }
-
-               return null;
-       }
-
-       public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,
-               ICdmFormElement parentElement){
-           return (T) ExtReferenceSelectionDialog.select(shell, //conversation,
-                   null);
-       }
-
-
-}
+/**\r
+* Copyright (C) 2009 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.taxeditor.ui.dialog.selection;\r
+\r
+import java.util.List;\r
+import java.util.UUID;\r
+\r
+import org.eclipse.swt.widgets.Shell;\r
+\r
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;\r
+import eu.etaxonomy.cdm.model.agent.AgentBase;\r
+import eu.etaxonomy.cdm.model.agent.Institution;\r
+import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
+import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;\r
+import eu.etaxonomy.cdm.model.common.Group;\r
+import eu.etaxonomy.cdm.model.common.ICdmBase;\r
+import eu.etaxonomy.cdm.model.common.User;\r
+import eu.etaxonomy.cdm.model.description.Feature;\r
+import eu.etaxonomy.cdm.model.description.PolytomousKey;\r
+import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;\r
+import eu.etaxonomy.cdm.model.location.Country;\r
+import eu.etaxonomy.cdm.model.location.NamedArea;\r
+import eu.etaxonomy.cdm.model.media.Media;\r
+import eu.etaxonomy.cdm.model.media.Rights;\r
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;\r
+import eu.etaxonomy.cdm.model.molecular.Amplification;\r
+import eu.etaxonomy.cdm.model.molecular.Primer;\r
+import eu.etaxonomy.cdm.model.name.TaxonName;\r
+import eu.etaxonomy.cdm.model.occurrence.Collection;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
+import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.model.taxon.Classification;\r
+import eu.etaxonomy.cdm.model.taxon.Synonym;\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
+import eu.etaxonomy.cdm.model.term.FeatureTree;\r
+import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;\r
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;\r
+import eu.etaxonomy.taxeditor.ui.element.IEntityElement;\r
+import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;\r
+import eu.etaxonomy.taxeditor.ui.section.description.CommonNameSourceElement;\r
+import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement;\r
+import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement;\r
+import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection;\r
+import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;\r
+import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;\r
+import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;\r
+import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;\r
+import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;\r
+\r
+/**\r
+ * @author n.hoffmann\r
+ * @date Jan 25, 2012\r
+ *\r
+ */\r
+public class SelectionDialogFactory {\r
+\r
+    public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,\r
+            T currentSelection){\r
+        return getSelectionFromDialog(clazz, shell, //conversation,\r
+                currentSelection, null);\r
+    }\r
+\r
+       public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,\r
+               T currentSelection, ICdmFormElement parentElement){\r
+\r
+               if(clazz.equals(Taxon.class)){\r
+                       return (T) TaxonSelectionDialog.selectTaxon(shell, //conversation,\r
+                               (Taxon) currentSelection);\r
+               }\r
+               if(clazz.equals(Synonym.class)){\r
+                       return (T) TaxonBaseSelectionDialog.selectSynonym(shell );//,conversation);\r
+               }\r
+               if(clazz.equals(TaxonBase.class)){\r
+                       return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell);//, conversation);\r
+               }\r
+               if(clazz.equals(Classification.class)){\r
+                       return (T) ClassificationSelectionDialog.select(shell, //conversation,\r
+                               (Classification) currentSelection);\r
+               }\r
+               if(clazz.equals(TaxonNode.class)){\r
+                       return (T) TaxonNodeSelectionDialog.select(shell, //conversation,\r
+                               null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification().getUuid());\r
+               }\r
+               if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){\r
+                       return (T) NomenclaturalReferenceSelectionDialog.select(shell, //conversation,\r
+                               (Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement).getEntity().getCombinationAuthorship());\r
+               }\r
+               if(clazz.equals(Reference.class) && parentElement instanceof CommonNameSourceElement && PreferencesUtil.getFilterCommonNameReferences()){\r
+            return (T) CommonNameReferenceSelectionDialog.select(shell, //conversation,\r
+                    (Reference) currentSelection);\r
+        }\r
+               if(clazz.equals(Reference.class)){\r
+                   if (parentElement instanceof ReferenceDetailElement){\r
+                       return (T) ReferenceSelectionDialog.select(shell, //conversation,\r
+                               ((ReferenceDetailElement) parentElement).getEntity(), true);\r
+                   }\r
+                       return (T) ReferenceSelectionDialog.select(shell, //conversation,\r
+                               (Reference) currentSelection);\r
+               }\r
+\r
+               if(clazz.equals(TaxonName.class)){\r
+                       return (T) NameSelectionDialog.select(shell, //conversation,\r
+                               (TaxonName) currentSelection);\r
+               }\r
+               if(clazz.equals(Team.class)){\r
+                       return (T) TeamSelectionDialog.select(shell, //conversation,\r
+                               (Team) currentSelection);\r
+               }\r
+               if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){\r
+            return (T) NomenclaturalAuthorSelectionDialog.select(shell, //conversation,\r
+                    (TeamOrPersonBase) currentSelection, false);\r
+        }else if(clazz.equals(TeamOrPersonBase.class)){\r
+                   //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)\r
+                   return (T) TeamOrPersonBaseSelectionDialog.select(shell, //conversation,\r
+                           (TeamOrPersonBase) currentSelection, false);\r
+               }\r
+               if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){\r
+                   return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell, //conversation,\r
+                           (TeamOrPersonBase) currentSelection, true);\r
+        }\r
+               if(clazz.equals(AgentBase.class)){\r
+                       return (T) AgentSelectionDialog.select(shell, //conversation,\r
+                               (AgentBase) currentSelection, false);\r
+               }\r
+               if(clazz.equals(Feature.class)){\r
+                       return (T) FeatureSelectionDialog.select(shell, //conversation,\r
+                               (Feature) currentSelection);\r
+               }\r
+               if(clazz.equals(FeatureTree.class)){\r
+                       return (T) FeatureTreeSelectionDialog.select(shell, //conversation,\r
+                               (FeatureTree) currentSelection);\r
+               }\r
+               if(clazz.equals(PolytomousKey.class)){\r
+                       return (T) PolytomousKeySelectionDialog.select(shell, //conversation,\r
+                               (PolytomousKey) currentSelection);\r
+               }\r
+               if(clazz.equals(PolytomousKeyNode.class)){\r
+                       MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,\r
+                                       "This functionality is not implemented yet.");\r
+                       return null;\r
+               }\r
+               if(clazz.equals(DerivedUnit.class)){\r
+                   return (T) DerivedUnitSelectionDialog.select(shell, //conversation,\r
+                           (DerivedUnit) currentSelection);\r
+               }\r
+               if(clazz.equals(FieldUnit.class)){\r
+                   return (T) FieldUnitSelectionDialog.select(shell, //conversation,\r
+                           (FieldUnit) currentSelection);\r
+               }\r
+               if(clazz.equals(SpecimenOrObservationBase.class)){\r
+                   return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, //conversation,\r
+                           (SpecimenOrObservationBase) currentSelection);\r
+               }\r
+               if(clazz.equals(NamedArea.class)){\r
+                   if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){\r
+                       return (T) NamedAreaSelectionDialog.select(shell, //conversation,\r
+                               (NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary);\r
+                   }\r
+                   else if(parentElement instanceof CommonNameDetailElement ){\r
+                return (T) CommonNameNamedAreaSelectionDialog.select(shell, //conversation,\r
+                        (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());\r
+            }\r
+                   else{\r
+                       //if (parentElement == null){\r
+                           List<UUID> uuidList = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());\r
+                           UUID[] uuidArray = new UUID[uuidList.size()];\r
+                           uuidList.toArray(uuidArray);\r
+                           return (T)NamedAreaSelectionDialog.select(shell, (NamedArea) currentSelection, null, uuidArray);\r
+                       //}\r
+                       //return (T) NamedAreaSelectionDialog.select(shell, //conversation,\r
+                       //        (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());\r
+                   }\r
+               }\r
+               if(clazz.equals(Collection.class)){\r
+                       return (T) CollectionSelectionDialog.select(shell, //conversation,\r
+                               (Collection) currentSelection);\r
+               }\r
+               if(clazz.equals(User.class) && parentElement instanceof MemberDetailElement){\r
+                   MemberDetailSection section = (MemberDetailSection)((MemberDetailElement)parentElement).getParentElement();\r
+                       return (T) UserSelectionDialog.select(shell, //conversation,\r
+                               (User) currentSelection, section.getEntity());\r
+               }\r
+               if(clazz.equals(GrantedAuthorityImpl.class)){\r
+                       return (T) GrantedAuthoritySelectionDialog.select(shell, //conversation,\r
+                               (GrantedAuthorityImpl) currentSelection);\r
+               }\r
+               if (clazz.equals(Person.class)){\r
+                       return (T) PersonSelectionDialog.select(shell, //conversation,\r
+                               (Person) currentSelection);\r
+               }\r
+               if(clazz.equals(Group.class) &&  parentElement instanceof GroupsByUserDetailElement){\r
+                   GroupsByUserDetailSection section =(GroupsByUserDetailSection)((GroupsByUserDetailElement)parentElement).getParentElement();\r
+                       return (T) GroupSelectionDialog.select(shell, //conversation,\r
+                               (Group) currentSelection, section.getEntity());\r
+               }\r
+               if(clazz.equals(Institution.class)){\r
+                       return (T) InstitutionSelectionDialog.select(shell, //conversation,\r
+                               (Institution) currentSelection);\r
+               }\r
+               if(clazz.equals(Primer.class)){\r
+                   return (T) PrimerSelectionDialog.select(shell, //conversation,\r
+                           (Primer) currentSelection);\r
+               }\r
+               if(clazz.equals(Amplification.class)){\r
+                   return (T) AmplificationSelectionDialog.select(shell, //conversation,\r
+                           (Amplification) currentSelection);\r
+               }\r
+               if(clazz.equals(Media.class)){\r
+                   return (T) MediaSelectionDialog.select(shell, //conversation,\r
+                           (Media) currentSelection);\r
+               }\r
+               if(clazz.equals(Rights.class)){\r
+            return (T) RightsSelectionDialog.select(shell, //conversation,\r
+                    (Rights) currentSelection);\r
+        }\r
+\r
+               return null;\r
+       }\r
+\r
+       public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,\r
+               ICdmFormElement parentElement){\r
+           return (T) ExtReferenceSelectionDialog.select(shell, //conversation,\r
+                   null);\r
+       }\r
+\r
+\r
+}\r