Project

General

Profile

Download (3.59 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.List;
13
import java.util.UUID;
14

    
15
import org.eclipse.swt.widgets.Control;
16
import org.eclipse.swt.widgets.Shell;
17
import org.eclipse.swt.widgets.Text;
18

    
19
import eu.etaxonomy.cdm.api.service.ITaxonService;
20
import eu.etaxonomy.cdm.model.taxon.Synonym;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
23
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
24
import eu.etaxonomy.taxeditor.newWizard.NewTaxonWizard;
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 extends AbstractFilteredCdmResourceSelectionDialog<TaxonBase> {
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
        this.cdmBaseToBeFiltered = taxonToBeFiltered;
63
        this.clazz = clazz;
64
        search();
65
    }
66

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

    
73
    /** {@inheritDoc} */
74
    @SuppressWarnings({ "unchecked", "rawtypes" })
75
	@Override
76
    protected void search() {
77
        Control control =getSearchField();
78
        String pattern = null;
79
        if (control != null){
80
            pattern = ((Text)control).getText();
81
        }
82

    
83
        if (pattern == null || pattern.equals("?")){
84
            model = (List)CdmStore.getService(ITaxonService.class).getUuidAndTitleCache(Taxon.class, null, null);
85
        }else{
86
            model = (List)CdmStore.getService(ITaxonService.class).getUuidAndTitleCache(Taxon.class, limitOfInitialElements, pattern);
87
        }
88
    }
89

    
90
    /** {@inheritDoc} */
91
    @Override
92
    protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
93
        return new NewTaxonWizard();
94
    }
95

    
96
    /** {@inheritDoc} */
97
    @Override
98
    protected String[] getNewWizardText() {
99
        return new String[]{"Taxon "};
100
    }
101
}
(35-35/39)