Project

General

Profile

Download (3.46 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.UUID;
14

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

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

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

    
33

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

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

    
43

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

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

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

    
57
    protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, //ConversationHolder conversation,
58
            String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
59
        super(shell, //conversation,
60
                title, multi, TaxonBaseSelectionDialog.class.getCanonicalName(), taxon);
61
        this.cdmBaseToBeFiltered = taxonToBeFiltered;
62
        this.clazz = clazz;
63
        search();
64
    }
65

    
66
    /** {@inheritDoc} */
67
    @Override
68
    protected TaxonBase getPersistentObject(UUID uuid) {
69
        return CdmStore.getService(ITaxonService.class).load(uuid);
70
    }
71

    
72
    /** {@inheritDoc} */
73
    @SuppressWarnings({ "unchecked", "rawtypes" })
74
	@Override
75
    protected void callService(String pattern) {
76

    
77
        model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
78
    }
79

    
80
    /** {@inheritDoc} */
81
    @Override
82
    protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
83
        return new NewTaxonWizard();
84
    }
85

    
86
    /** {@inheritDoc} */
87
    @Override
88
    protected String[] getNewWizardText() {
89
        return new String[]{"New Taxon"};
90
    }
91

    
92
    @Override
93
    protected void sort() {
94
        if(!PreferencesUtil.isSortTaxaByRankAndName()){
95
            Collections.sort(model, getItemsComparator());
96
        }
97
      // otherwise result is already sorted
98
    }
99
}
(35-35/41)