Project

General

Profile

Download (3.62 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.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.service.ITaxonService;
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
25
import eu.etaxonomy.taxeditor.newWizard.NewTaxonWizard;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

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

    
35

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

    
42
    public static Taxon selectTaxon(Shell shell, ConversationHolder conversation, 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, String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
59
        super(shell, conversation, title, multi, TaxonBaseSelectionDialog.class.getCanonicalName(), taxon);
60
        this.cdmBaseToBeFiltered = taxonToBeFiltered;
61
        this.clazz = clazz;
62
        search();
63
    }
64

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

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

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

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

    
94
    /** {@inheritDoc} */
95
    @Override
96
    protected String getNewWizardLinkText() {
97
        return String.format("Create a new <a>%1s</a>", "Taxon ");
98
    }
99
}
(34-34/38)