Project

General

Profile

Download (8.42 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2013 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
package eu.etaxonomy.taxeditor.view.search.specimen;
10

    
11
import java.util.Calendar;
12
import java.util.GregorianCalendar;
13

    
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Event;
18
import org.eclipse.swt.widgets.Listener;
19

    
20
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
21

    
22
/**
23
 * Controller class for handling a {@link SpecimenSearchComposite}.
24
 * @author pplitzner
25
 * @date 03.09.2013
26
 *
27
 */
28
public class SpecimenSearchController implements Listener{
29

    
30
    private SpecimenSearchComposite specimenSearchComposite;
31
    private OccurenceQuery lastQuery = null;
32

    
33
    private static SpecimenSearchController instance = null;
34

    
35
    public static SpecimenSearchController getInstance(Composite parent){
36
        if(instance==null){
37
            instance = new SpecimenSearchController(parent);
38
            return instance;
39
        }
40
        instance.init(parent);
41
        return instance;
42
    }
43

    
44
    /**
45
     * Constructs a new controller which will itself construct the composite
46
     * @param parent the parent {@link Composite} for the one handles by this controller
47
     */
48
    private SpecimenSearchController(Composite parent) {
49
        init(parent);
50
    }
51

    
52
    private void init(Composite parent){
53
        this.specimenSearchComposite = new SpecimenSearchComposite(parent, SWT.NONE);
54
        this.specimenSearchComposite.addListener(SWT.Selection, this);
55
        specimenSearchComposite.getBtnShowDate().addListener(SWT.Selection, this);
56
        specimenSearchComposite.getBtnShowDate().setSelection(false);
57
        specimenSearchComposite.getDateFrom().setEnabled(false);
58
        specimenSearchComposite.getDateTo().setEnabled(false);
59

    
60
        loadLastState();
61
    }
62

    
63
    /* (non-Javadoc)
64
     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
65
     */
66
    @Override
67
    public void handleEvent(Event event) {
68
        Button btnShowDate = specimenSearchComposite.getBtnShowDate();
69
        if(event.widget==btnShowDate){
70
            specimenSearchComposite.getDateFrom().setEnabled(btnShowDate.getSelection());
71
            specimenSearchComposite.getDateTo().setEnabled(btnShowDate.getSelection());
72
        }
73
    }
74

    
75

    
76
    private void loadLastState(){
77
        if(lastQuery!=null){
78
            specimenSearchComposite.getTextAccessionNumber().setText(lastQuery.accessionNumber);
79
            specimenSearchComposite.getTextCollector().setText(lastQuery.collector);
80
            specimenSearchComposite.getTextCollectorNumber().setText(lastQuery.collectorsNumber);
81
            specimenSearchComposite.getTextCountry().setText(lastQuery.country);
82
            specimenSearchComposite.getTextHerbarium().setText(lastQuery.herbarium);
83
            specimenSearchComposite.getTextLocality().setText(lastQuery.locality);
84
            specimenSearchComposite.getTextTaxonName().setText(lastQuery.taxonName);
85
            specimenSearchComposite.getTextHigherTaxon().setText(lastQuery.higherTaxon);
86
            if(lastQuery.dateFrom!=null){
87
                specimenSearchComposite.getDateFrom().setDate(lastQuery.dateFrom.get(Calendar.YEAR), lastQuery.dateFrom.get(Calendar.MONTH), lastQuery.dateFrom.get(Calendar.DAY_OF_MONTH));
88
            }
89
            if(lastQuery.dateTo!=null){
90
                specimenSearchComposite.getDateTo().setDate(lastQuery.dateTo.get(Calendar.YEAR), lastQuery.dateTo.get(Calendar.MONTH), lastQuery.dateTo.get(Calendar.DAY_OF_MONTH));
91
            }
92
        }
93
    }
94

    
95
    public void saveLastSate() {
96
        lastQuery = new OccurenceQuery(getTaxonName(), getCollector(), getCollectorNumber(), getAccessionNumber(), getHerbarium(), getCountry(false), getLocality(), getDateFrom(), getDateTo(), false);
97
        lastQuery.higherTaxon =getHigherTaxon();
98
    }
99

    
100
    /**
101
     * Returns the {@link Composite} handled by this controller
102
     * @return
103
     */
104
    public Composite getComposite() {
105
        return specimenSearchComposite;
106
    }
107

    
108
    /**
109
     * Returns the taxon name entered in the search view
110
     * @return the taxon name as a {@link String}
111
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getTextTaxonName()
112
     */
113
    public String getTaxonName() {
114
        return specimenSearchComposite.getTextTaxonName().getText();
115
    }
116

    
117
    /**
118
     * Returns the higher taxon entered in the search view
119
     * @return the higher taxon as a {@link String}
120
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getTextHigherTaxon()
121
     */
122
    public String getHigherTaxon() {
123
        return specimenSearchComposite.getTextHigherTaxon().getText();
124
    }
125

    
126
    /**
127
     * Returns the collector entered in the search view
128
     * @return the collector as a {@link String}
129
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getTextCollector()
130
     */
131
    public String getCollector() {
132
        return specimenSearchComposite.getTextCollector().getText();
133
    }
134

    
135
    /**
136
     * Returns the collecting number entered in the search view
137
     * @return the collecting as a {@link String}
138
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getTextCollectorNumber()
139
     */
140
    public String getCollectorNumber() {
141
        return specimenSearchComposite.getTextCollectorNumber().getText();
142
    }
143

    
144
    /**
145
     * Returns the accession number entered in the search view
146
     * @return the accession number as a {@link String}
147
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getTextAccessionNumber()
148
     */
149
    public String getAccessionNumber() {
150
        return specimenSearchComposite.getTextAccessionNumber().getText();
151
    }
152

    
153
    /**
154
     * Returns the herbarium entered in the search view
155
     * @return the herbarium as a {@link String}
156
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getComboHerbarium()
157
     */
158
    public String getHerbarium() {
159
        return specimenSearchComposite.getTextHerbarium().getText();
160
    }
161

    
162
    /**
163
     * Returns the country entered in the search view
164
     * @return the country as a {@link String}
165
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getComboCountry()
166
     */
167
    public String getCountry(boolean biocase) {
168

    
169
        String result = specimenSearchComposite.getTextCountry().getText();
170
        if (result.contains("-") && biocase){
171
            result = result.substring(4).trim();
172
        }else if (result.contains("-")){
173
            result = result.substring(0,2).trim();
174
        }
175
        return result;
176

    
177
//        return specimenSearchComposite.getComboCountry().getItem(specimenSearchComposite.getComboCountry().getSelectionIndex());
178
    }
179

    
180
    /**
181
     * Returns the locality entered in the search view
182
     * @return the locality as a {@link String}
183
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getTextLocality()
184
     */
185
    public String getLocality() {
186
        return specimenSearchComposite.getTextLocality().getText();
187
    }
188

    
189
    /**
190
     * Returns the start date entered in the search view.
191
     * @return the date as an instance of {@link Calendar}
192
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getDateFrom()
193
     */
194
    public Calendar getDateFrom() {
195
        if(specimenSearchComposite.getBtnShowDate().getSelection()){
196
            Calendar dateFrom = new GregorianCalendar();
197
            dateFrom.clear();
198
            dateFrom.set(specimenSearchComposite.getDateFrom().getYear(), specimenSearchComposite.getDateFrom().getMonth(), specimenSearchComposite.getDateFrom().getDay());
199
            return dateFrom;
200
        }
201
        return null;
202
    }
203

    
204
    /**
205
     * Returns the end date entered in the search view.
206
     * @return the date as an instance of {@link Calendar}
207
     * @see eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchComposite#getDateTo()
208
     */
209
    public Calendar getDateTo() {
210
        if(specimenSearchComposite.getBtnShowDate().getSelection()){
211
            Calendar dateTo = new GregorianCalendar();
212
            dateTo.clear();
213
            dateTo.set(specimenSearchComposite.getDateTo().getYear(), specimenSearchComposite.getDateTo().getMonth(), specimenSearchComposite.getDateTo().getDay());
214
            return dateTo;
215
        }
216
        return null;
217
    }
218

    
219
}
(4-4/4)