ref #7849: remove OVERRIDE constants from IPreferenceKeys and handle it by method
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / TermVocabularySelectionDialog.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.UUID;
15
16 import org.eclipse.swt.widgets.Shell;
17
18 import eu.etaxonomy.cdm.api.service.IVocabularyService;
19 import eu.etaxonomy.cdm.model.common.TermVocabulary;
20 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
21 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
22 import eu.etaxonomy.taxeditor.newWizard.NewVocabularyWizard;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 /**
26 *
27 * @author pplitzner
28 * @since Jun 1, 2018
29 *
30 */
31 public class TermVocabularySelectionDialog extends
32 AbstractFilteredCdmResourceSelectionDialog<TermVocabulary> {
33
34 public static TermVocabulary select(String dialogTitle, Shell shell, TermVocabulary voc){
35 return select_internal(dialogTitle, shell, voc);
36 }
37
38 public static TermVocabulary select(Shell shell, TermVocabulary voc){
39 return select_internal("Choose Vocabulary", shell, voc);
40 }
41
42 private static TermVocabulary select_internal(String dialogTitle, Shell shell, TermVocabulary voc){
43 TermVocabularySelectionDialog dialog = new TermVocabularySelectionDialog(shell,
44 dialogTitle!=null?dialogTitle:"Choose Vocabulary",
45 false,
46 TermVocabularySelectionDialog.class.getCanonicalName(),
47 voc);
48 return getSelectionFromDialog(dialog);
49 }
50
51 protected TermVocabularySelectionDialog(Shell shell,
52 String title, boolean multi,
53 String settings, TermVocabulary cdmObject) {
54 super(shell, title, multi, settings, cdmObject);
55 }
56
57 @Override
58 protected TermVocabulary getPersistentObject(UUID uuid) {
59 return CdmStore.getService(IVocabularyService.class).load(uuid);
60 }
61
62 @Override
63 protected void callService(String pattern) {
64 List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).list(TermVocabulary.class, null, null, null, null);
65
66 List<UuidAndTitleCache<TermVocabulary>> featureUuidAndTitleCache = new ArrayList<>();
67
68 for(TermVocabulary voc : vocabularies){
69 UuidAndTitleCache<TermVocabulary> uuidAndTitleCache = new UuidAndTitleCache<>(TermVocabulary.class, voc.getUuid(), voc.getId(), voc.getTitleCache());
70 if (pattern == null || uuidAndTitleCache.getTitleCache().matches("(?i)"+pattern + ".*")) {
71 featureUuidAndTitleCache.add(uuidAndTitleCache);
72 }
73 }
74 model = featureUuidAndTitleCache;
75 }
76
77 @Override
78 protected String[] getNewWizardText() {
79 return new String[]{ "New Vocabulary"};
80 }
81
82 @Override
83 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
84 return new NewVocabularyWizard();
85 }
86
87 }