Merge branch 'release/5.17.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / TaxonNodeSelectionDialog.java
index 84a4f3e6b8304cbf3e2270c81de7a19eb17a8260..3ac813c44dd7deea7ddfef106f5f5f2363f8552c 100644 (file)
@@ -6,10 +6,12 @@ package eu.etaxonomy.taxeditor.ui.dialog.selection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
@@ -21,6 +23,7 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
@@ -30,31 +33,41 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * @author p.ciardelli
- * @version $Id: $
  */
 public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonNode> implements SelectionListener{
 
        public static TaxonNode select(Shell shell, //ConversationHolder conversation,
-               String title, List<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID) {
+               String title, Set<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID, boolean allowSelectClassification) {
                TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
                                //conversation,
                                title,
                                excludeTaxa,
                                false,
                                node,
-                               classificationUUID);
+                               classificationUUID, allowSelectClassification);
                return getSelectionFromDialog(dialog);
        }
+       public static TaxonNode select(Shell shell, //ConversationHolder conversation,
+            String title, Set<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID) {
+        TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
+                //conversation,
+                title,
+                excludeTaxa,
+                false,
+                node,
+                classificationUUID);
+        return getSelectionFromDialog(dialog);
+    }
 
        public static UuidAndTitleCache<TaxonNode> selectUuidAndTitleCache(Shell shell, //ConversationHolder conversation,
-            String title, List<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID) {
+            String title, Set<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID) {
         TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
                 //conversation,
                 title,
                 excludeTaxa,
                 false,
                 node,
-                classificationUUID);
+                classificationUUID, false);
         return getUuidAndTitleCacheSelectionFromDialog(dialog);
     }
 
@@ -64,10 +77,11 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
        private Classification selectedClassification;
        private UUID selectedUuid;
-       private final List<UUID> excludeTaxa;
+//     private final Set<UUID> excludeTaxa;
+       private boolean allowClassificationSelection = false;
 
        protected TaxonNodeSelectionDialog(Shell shell, //ConversationHolder conversation,
-               String title, List<UUID> excludeTaxa, boolean multi, TaxonNode node, UUID classificationUUID) {
+               String title, Set<UUID> excludeTaxa, boolean multi, TaxonNode node, UUID classificationUUID, boolean allowSelectClassification) {
                super(shell, //conversation,
                        title, multi, TaxonNodeSelectionDialog.class.getCanonicalName(), node);
 
@@ -75,14 +89,19 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
                setListLabelProvider(labelProvider);
 //             setDetailsLabelProvider(labelProvider);
-               this.excludeTaxa = excludeTaxa;
+               this.cdmBaseToBeFiltered = excludeTaxa;
                if(classificationUUID != null){
             selectedUuid = classificationUUID;
         }
 
                fillClassifications();
+               this.allowClassificationSelection = allowSelectClassification;
 
-               createClassificationSelectionCombo(shell);
+               //createClassificationSelectionCombo(shell);
+       }
+       protected TaxonNodeSelectionDialog(Shell shell, //ConversationHolder conversation,
+            String title, Set<UUID> excludeTaxa, boolean multi, TaxonNode node, UUID classificationUUID) {
+           this(shell, title, excludeTaxa, multi, node, classificationUUID, false);
        }
 
        /** {@inheritDoc} */
@@ -128,7 +147,6 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
                return classificationSelection;
        }
 
-       /** {@inheritDoc} */
        @Override
        protected String getTitle(TaxonNode taxonNode) {
                if(taxonNode != null && taxonNode.getTaxon() != null){
@@ -138,17 +156,31 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
                return "";
        }
 
-       /** {@inheritDoc} */
+       @Override
+    protected SelectionListener getNewWizardButtonSelectionListener(){
+        return new SelectionAdapter() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                Classification tree = selectedClassification;
+                setPattern(tree.getRootNode());
+
+            }
+        };
+    }
+
        @Override
        protected TaxonNode getPersistentObject(UUID uuid) {
-               return CdmStore.getService(IClassificationService.class).getTaxonNodeByUuid(uuid);
+               return CdmStore.getService(ITaxonNodeService.class).find(uuid);
        }
 
-       /** {@inheritDoc} */
        @Override
        protected void callService(String pattern) {
-           model = CdmStore.getService(IClassificationService.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedUuid, limitOfInitialElements, pattern);
+           model = CdmStore.getService(IClassificationService.class)
+                       .getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(
+                                       selectedClassification.getUuid(), limitOfInitialElements, pattern, allowClassificationSelection, true);
        }
+
        @Override
        protected void sort() {
            if(!PreferencesUtil.isSortTaxaByRankAndName()){
@@ -175,28 +207,26 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
                 }
             });
                        if (selectedClassification == null){
-                           if (this.cdmBaseToBeFiltered == null){
+//                         if (this.cdmBaseToBeFiltered.isEmpty()){
                                selectedClassification = classifications.iterator().next();
-                           } else {
-                               selectedClassification = this.cdmBaseToBeFiltered.getClassification();
-                           }
+
+//                         } else {
+//                             selectedClassification = this.cdmBaseToBeFiltered.getClassification();
+//                         }
                        }
                }
     }
 
-       /** {@inheritDoc} */
        @Override
        protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
                return null;
        }
 
-       /** {@inheritDoc} */
        @Override
        protected String[] getNewWizardText() {
                return null;
        }
 
-       /** {@inheritDoc} */
        @Override
     public void widgetSelected(SelectionEvent e) {
                selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
@@ -207,9 +237,6 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
                }
        }
 
-       /** {@inheritDoc} */
        @Override
     public void widgetDefaultSelected(SelectionEvent e) {}
-
-
 }