Moving editor sources back into trunk
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / TaxonSearchDialog.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.editor.name;
12
13 import java.util.List;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.swt.widgets.Shell;
17
18 import eu.etaxonomy.cdm.model.taxon.Taxon;
19 import eu.etaxonomy.taxeditor.store.CdmStore;
20
21 /**
22 * @author p.ciardelli
23 * @created 08.05.2009
24 * @version 1.0
25 */
26 public class TaxonSearchDialog extends NameSearchDialog {
27 private static final Logger logger = Logger
28 .getLogger(TaxonSearchDialog.class);
29
30 protected String dialogTitle = "Search for a taxib in datasource";
31 protected String dialogMessage = "Enter a search term for a taxon, using '*' as a wildcard.";
32
33 private Taxon taxon;
34 private Taxon excludeTaxon;
35
36 /**
37 * @param parent
38 */
39 public TaxonSearchDialog(Shell parent) {
40 super(parent);
41 }
42
43 /**
44 * @param parent
45 */
46 public TaxonSearchDialog(Shell parent, Taxon excludeTaxon) {
47 super(parent);
48
49 this.excludeTaxon = excludeTaxon;
50 }
51
52 protected List doSearch() {
53 List results = CdmStore.searchTaxaByName(searchTermText.getText(), true);
54 if (excludeTaxon != null) {
55 results.remove(excludeTaxon);
56 }
57 return results;
58 }
59
60 /**
61 * @param element
62 */
63 protected String getText(Object element) {
64 if (element instanceof Taxon) {
65 return ((Taxon) element).getTitleCache();
66 }
67 return null;
68 }
69
70 /**
71 * @param data
72 * @return
73 */
74 protected boolean setSelection(Object data) {
75 if (data instanceof Taxon) {
76 setSelectedTaxon((Taxon) data);
77 return true;
78 }
79 return false;
80 }
81
82 /**
83 * @param data
84 */
85 private void setSelectedTaxon(Taxon taxon) {
86 this.taxon = taxon;
87 }
88
89 /**
90 * @return
91 */
92 private Object getSelectedTaxon() {
93 return taxon;
94 }
95
96 protected void submitResult() {
97 result = getSelectedTaxon();
98 shell.dispose();
99 }
100 }