ref #9204 upgrade and remove further libraries in taxeditor (including commons-lang...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / TermVocabularySelectionDialog.java
index d2e195fdf8b2ef02a0830620a30ee8d4c30d42c9..10beb90b3e99fb38e5bfe8c3c0634f4f446d9caf 100644 (file)
@@ -9,16 +9,17 @@
 
 package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collections;
+import java.util.Set;
 import java.util.UUID;
 
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
-import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
+import eu.etaxonomy.taxeditor.newWizard.NewFeatureVocabularyWizard;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -30,28 +31,37 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
 public class TermVocabularySelectionDialog extends
                AbstractFilteredCdmResourceSelectionDialog<TermVocabulary> {
 
+    private TermType termType;
+
+    public static TermVocabulary select(String dialogTitle, Shell shell, Set<TermVocabulary> vocabulariesToBeFiltered,
+            TermType termType){
+        return select_internal(dialogTitle, shell, vocabulariesToBeFiltered, termType);
+    }
+
     public static TermVocabulary select(String dialogTitle, Shell shell, TermVocabulary voc){
-        return select_internal(dialogTitle, shell, voc);
+        return select_internal(dialogTitle, shell, voc!=null?Collections.singleton(voc):null, null);
     }
 
     public static TermVocabulary select(Shell shell, TermVocabulary voc){
-        return select_internal("Choose Vocabulary", shell, voc);
+        return select_internal("Choose Vocabulary", shell, voc!=null?Collections.singleton(voc):null, null);
     }
 
-       private static TermVocabulary select_internal(String dialogTitle, Shell shell, TermVocabulary voc){
+    private static TermVocabulary select_internal(String dialogTitle, Shell shell, Set<TermVocabulary> vocabulariesToBeFiltered,
+            TermType termType){
                TermVocabularySelectionDialog dialog = new TermVocabularySelectionDialog(shell,
                                dialogTitle!=null?dialogTitle:"Choose Vocabulary",
                                false,
                                TermVocabularySelectionDialog.class.getCanonicalName(),
-                               voc);
+                               vocabulariesToBeFiltered, termType);
                return getSelectionFromDialog(dialog);
        }
 
-       protected TermVocabularySelectionDialog(Shell shell,
-                        String title, boolean multi,
-                       String settings, TermVocabulary cdmObject) {
-               super(shell, title, multi, settings, cdmObject);
-       }
+    protected TermVocabularySelectionDialog(Shell shell,
+            String title, boolean multi,
+            String settings, Set<TermVocabulary> vocabulariesToBeFiltered, TermType termType) {
+        super(shell, title, multi, settings, vocabulariesToBeFiltered);
+        this.termType = termType;
+    }
 
        @Override
        protected TermVocabulary getPersistentObject(UUID uuid) {
@@ -60,27 +70,17 @@ public class TermVocabularySelectionDialog extends
 
        @Override
        protected void callService(String pattern) {
-               List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).list(TermVocabulary.class, null, null, null, null);
-
-               List<UuidAndTitleCache<TermVocabulary>> featureUuidAndTitleCache = new ArrayList<>();
-
-               for(TermVocabulary voc : vocabularies){
-                       UuidAndTitleCache<TermVocabulary> uuidAndTitleCache = new UuidAndTitleCache<>(TermVocabulary.class, voc.getUuid(), voc.getId(), voc.getTitleCache());
-                       if (pattern == null || uuidAndTitleCache.getTitleCache().matches("(?i)"+pattern + ".*")) {
-                featureUuidAndTitleCache.add(uuidAndTitleCache);
-            }
-               }
-               model =  featureUuidAndTitleCache;
+        model = CdmStore.getService(IVocabularyService.class).getUuidAndTitleCache(TermVocabulary.class, termType, limitOfInitialElements, pattern);
        }
 
        @Override
        protected String[] getNewWizardText() {
-               return null;
+        return new String[]{ "New Vocabulary"};
        }
 
        @Override
        protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
-               return null;
+        return new NewFeatureVocabularyWizard(termType);
        }
 
 }