Project

General

Profile

Download (3.6 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.Collections;
13
import java.util.HashSet;
14
import java.util.UUID;
15

    
16
import org.eclipse.swt.widgets.Shell;
17

    
18
import eu.etaxonomy.cdm.api.service.ITaxonService;
19
import eu.etaxonomy.cdm.model.taxon.Synonym;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
22
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23
import eu.etaxonomy.taxeditor.newWizard.NewTaxonWizard;
24
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * @author n.hoffmann
29
 * @created Sep 21, 2009
30
 * @version 1.0
31
 */
32
public class TaxonBaseSelectionDialog<T extends TaxonBase> extends AbstractFilteredCdmResourceSelectionDialog {
33

    
34

    
35
    public static TaxonBase selectTaxonBase(Shell shell){//, ConversationHolder conversation) {
36
        AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(TaxonBase.class, shell, //conversation,
37
                "Choose a taxon/synonym", false, null, null);
38
        return getSelectionFromDialog(dialog);
39
    }
40

    
41
    public static Taxon selectTaxon(Shell shell, //ConversationHolder conversation,
42
            Taxon taxonToBeFiltered) {
43

    
44

    
45
        AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Taxon.class, shell, //conversation,
46
                "Choose a taxon", false, null, taxonToBeFiltered);
47
        return (Taxon) getSelectionFromDialog(dialog);
48
    }
49

    
50
    public static Synonym selectSynonym(Shell shell){//, ConversationHolder conversation) {
51
        AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Synonym.class, shell, //conversation,
52
                "Choose a synonym", false, null, null);
53
        return (Synonym) getSelectionFromDialog(dialog);
54
    }
55

    
56
    private final Class<? extends TaxonBase> clazz;
57

    
58
    protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, //ConversationHolder conversation,
59
            String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
60
        super(shell, //conversation,
61
                title, multi, TaxonBaseSelectionDialog.class.getCanonicalName(), taxon);
62
        if (taxonToBeFiltered != null){
63
            this.cdmBaseToBeFiltered = new HashSet<>();
64
            this.cdmBaseToBeFiltered.add(taxonToBeFiltered.getUuid());
65
        }
66
        this.clazz = clazz;
67
        search();
68
    }
69

    
70
    /** {@inheritDoc} */
71
    @Override
72
    protected TaxonBase getPersistentObject(UUID uuid) {
73
        return CdmStore.getService(ITaxonService.class).load(uuid);
74
    }
75

    
76
    /** {@inheritDoc} */
77
    @SuppressWarnings({ "unchecked", "rawtypes" })
78
	@Override
79
    protected void callService(String pattern) {
80

    
81
        model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
82
    }
83

    
84
    /** {@inheritDoc} */
85
    @Override
86
    protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
87
        return new NewTaxonWizard();
88
    }
89

    
90
    /** {@inheritDoc} */
91
    @Override
92
    protected String[] getNewWizardText() {
93
        return new String[]{"New Taxon"};
94
    }
95

    
96
    @Override
97
    protected void sort() {
98
        if(!PreferencesUtil.isSortTaxaByRankAndName()){
99
            Collections.sort(model, getItemsComparator());
100
        }
101
      // otherwise result is already sorted
102
    }
103
}
(39-39/46)