Merge branch 'develop' into wset
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / TaxonNodeSelectionDialog.java
index 35239371ca5ab3ccaa73602f62ed12fe85a1c447..be19d2b2eabea1e31d09f841e5de8b2732b68193 100644 (file)
@@ -20,11 +20,11 @@ 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;
 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -33,9 +33,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 +52,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 +128,43 @@ 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
-
-
-               if(classifications == null){
+       protected void callService(String pattern) {
+           model = CdmStore.getService(IClassificationService.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification.getUuid(), limitOfInitialElements, pattern);
+       }
+       @Override
+       protected void sort() {
+           if(!PreferencesUtil.isSortTaxaByRankAndName()){
+            Collections.sort(model, getItemsComparator());
+        }
+      // otherwise result is already sorted
+    }
+
+    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.getUuid(), excludeTaxa);
-       }
+    }
 
        /** {@inheritDoc} */
        @Override
@@ -154,7 +174,7 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
        /** {@inheritDoc} */
        @Override
-       protected String getNewWizardLinkText() {
+       protected String[] getNewWizardText() {
                return null;
        }
 
@@ -164,7 +184,9 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
                selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
 
 //             refresh();
-               setPattern(null);
+               if (getSearchField().getText() != null){
+                   search();
+               }
        }
 
        /** {@inheritDoc} */