Merge branch 'develop' into wset
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / TaxonNodeSelectionDialog.java
index 821fc8c5bd8377e720cf0f043061a73f9a1e1d0d..b25f02f1ff1b6576810cf907c9204df4a9bcd77d 100644 (file)
@@ -20,7 +20,6 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
@@ -33,9 +32,10 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonNode> implements SelectionListener{
 
-       public static TaxonNode select(Shell shell, ConversationHolder conversation, String title, List<UUID> excludeTaxa, TaxonNode node, Classification classification) {
+       public static TaxonNode select(Shell shell, //ConversationHolder conversation,
+               String title, List<UUID> excludeTaxa, TaxonNode node, Classification classification) {
                TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
-                               conversation,
+                               //conversation,
                                title,
                                excludeTaxa,
                                false,
@@ -51,24 +51,29 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
        private Classification selectedClassification;
        private final List<UUID> excludeTaxa;
 
-       protected TaxonNodeSelectionDialog(Shell shell, ConversationHolder conversation, String title, List<UUID> excludeTaxa, boolean multi, TaxonNode node, Classification classification) {
-               super(shell, conversation, title, multi, TaxonNodeSelectionDialog.class.getCanonicalName(), node);
+       protected TaxonNodeSelectionDialog(Shell shell, //ConversationHolder conversation,
+               String title, List<UUID> excludeTaxa, boolean multi, TaxonNode node, Classification classification) {
+               super(shell, //conversation,
+                       title, multi, TaxonNodeSelectionDialog.class.getCanonicalName(), node);
 
                ILabelProvider labelProvider = new FilteredCdmResourceLabelProvider();
 
                setListLabelProvider(labelProvider);
-               setDetailsLabelProvider(labelProvider);
+//             setDetailsLabelProvider(labelProvider);
                this.excludeTaxa = excludeTaxa;
                if(classification != null){
                        selectedClassification = classification;
                }
-               initModel();
+
+               fillClassifications();
+               createClassificationSelectionCombo(shell);
        }
 
        /** {@inheritDoc} */
        @Override
-       protected Control createExtendedContentArea(Composite parent) {
-               return createClassificationSelectionCombo(parent);
+       protected Control createDialogArea(Composite parent) {
+           Composite container = (Composite) super.createDialogArea(parent);
+               return createClassificationSelectionCombo(container);
        }
 
        /*
@@ -122,29 +127,36 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
        /** {@inheritDoc} */
        @Override
-       protected void initModel() {
-               // default to first tree
-               // TODO this will be problematic and can only be seen as workaround
-
+       protected void callService(String pattern) {
+           model = CdmStore.getService(IClassificationService.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification.getUuid(), limitOfInitialElements, pattern);
+       }
 
-               if(classifications == null){
+    private void fillClassifications() {
+        if(classifications == null){
                        classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
                        Collections.sort(classifications, new Comparator<Classification>() {
 
                 @Override
                 public int compare(Classification o1, Classification o2) {
-                    return o1.getTitleCache().compareTo(o2.getTitleCache());
+                    if (o1.equals(o2)){
+                        return 0;
+                    }
+                    int result = o1.getTitleCache().compareTo(o2.getTitleCache());
+                    if (result == 0){
+                        return o1.getUuid().compareTo(o2.getUuid());
+                    }
+                    return result;
                 }
             });
-                       if (this.cdmBaseToBeFiltered == null){
-                           selectedClassification = classifications.iterator().next();
-                       } else {
+                       if (selectedClassification == null){
+                           if (this.cdmBaseToBeFiltered == null){
+                               selectedClassification = classifications.iterator().next();
+                           } else {
                            selectedClassification = this.cdmBaseToBeFiltered.getClassification();
+                           }
                        }
                }
-
-               model = CdmStore.getService(IClassificationService.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification, excludeTaxa);
-       }
+    }
 
        /** {@inheritDoc} */
        @Override
@@ -154,7 +166,7 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
        /** {@inheritDoc} */
        @Override
-       protected String getNewWizardLinkText() {
+       protected String[] getNewWizardText() {
                return null;
        }
 
@@ -164,7 +176,9 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
                selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
 
 //             refresh();
-               setPattern(null);
+               if (getSearchField().getText() != null){
+                   search();
+               }
        }
 
        /** {@inheritDoc} */