Project

General

Profile

Download (2.69 KB) Statistics
| Branch: | Tag: | Revision:
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.store.CdmStore;
23

    
24
/**
25
 *
26
 * @author pplitzner
27
 * @since Jun 1, 2018
28
 *
29
 */
30
public class TermVocabularySelectionDialog extends
31
		AbstractFilteredCdmResourceSelectionDialog<TermVocabulary> {
32

    
33
    public static TermVocabulary select(String dialogTitle, Shell shell, TermVocabulary voc){
34
        return select_internal(dialogTitle, shell, voc);
35
    }
36

    
37
    public static TermVocabulary select(Shell shell, TermVocabulary voc){
38
        return select_internal("Choose Vocabulary", shell, voc);
39
    }
40

    
41
	private static TermVocabulary select_internal(String dialogTitle, Shell shell, TermVocabulary voc){
42
		TermVocabularySelectionDialog dialog = new TermVocabularySelectionDialog(shell,
43
				dialogTitle!=null?dialogTitle:"Choose Vocabulary",
44
				false,
45
				TermVocabularySelectionDialog.class.getCanonicalName(),
46
				voc);
47
		return getSelectionFromDialog(dialog);
48
	}
49

    
50
	protected TermVocabularySelectionDialog(Shell shell,
51
			 String title, boolean multi,
52
			String settings, TermVocabulary cdmObject) {
53
		super(shell, title, multi, settings, cdmObject);
54
	}
55

    
56
	@Override
57
	protected TermVocabulary getPersistentObject(UUID uuid) {
58
		return CdmStore.getService(IVocabularyService.class).load(uuid);
59
	}
60

    
61
	@Override
62
	protected void callService(String pattern) {
63
		List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).list(TermVocabulary.class, null, null, null, null);
64

    
65
		List<UuidAndTitleCache<TermVocabulary>> featureUuidAndTitleCache = new ArrayList<>();
66

    
67
		for(TermVocabulary voc : vocabularies){
68
			UuidAndTitleCache<TermVocabulary> uuidAndTitleCache = new UuidAndTitleCache<>(TermVocabulary.class, voc.getUuid(), voc.getId(), voc.getTitleCache());
69
			if (pattern == null || uuidAndTitleCache.getTitleCache().matches("(?i)"+pattern + ".*")) {
70
                featureUuidAndTitleCache.add(uuidAndTitleCache);
71
            }
72
		}
73
		model =  featureUuidAndTitleCache;
74
	}
75

    
76
	@Override
77
	protected String[] getNewWizardText() {
78
		return null;
79
	}
80

    
81
	@Override
82
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
83
		return null;
84
	}
85

    
86
}
(42-42/43)