3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
.specimenSearch
;
12 import java
.util
.Calendar
;
13 import java
.util
.GregorianCalendar
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.widgets
.Button
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Event
;
19 import org
.eclipse
.swt
.widgets
.Listener
;
21 import eu
.etaxonomy
.cdm
.ext
.occurrence
.OccurenceQuery
;
24 * Controller class for handling a {@link SpecimenSearchComposite}.
29 public class SpecimenSearchController
implements Listener
{
31 private SpecimenSearchComposite specimenSearchComposite
;
32 private OccurenceQuery lastQuery
= null;
34 private static SpecimenSearchController instance
= null;
36 public static SpecimenSearchController
getInstance(Composite parent
){
38 instance
= new SpecimenSearchController(parent
);
41 instance
.init(parent
);
46 * Constructs a new controller which will itself construct the composite
47 * @param parent the parent {@link Composite} for the one handles by this controller
49 private SpecimenSearchController(Composite parent
) {
53 private void init(Composite parent
){
54 this.specimenSearchComposite
= new SpecimenSearchComposite(parent
, SWT
.NONE
);
55 this.specimenSearchComposite
.addListener(SWT
.Selection
, this);
56 specimenSearchComposite
.getBtnShowDate().addListener(SWT
.Selection
, this);
57 specimenSearchComposite
.getBtnShowDate().setSelection(false);
58 specimenSearchComposite
.getDateFrom().setEnabled(false);
59 specimenSearchComposite
.getDateTo().setEnabled(false);
65 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
68 public void handleEvent(Event event
) {
69 Button btnShowDate
= specimenSearchComposite
.getBtnShowDate();
70 if(event
.widget
==btnShowDate
){
71 specimenSearchComposite
.getDateFrom().setEnabled(btnShowDate
.getSelection());
72 specimenSearchComposite
.getDateTo().setEnabled(btnShowDate
.getSelection());
77 private void loadLastState(){
79 specimenSearchComposite
.getTextAccessionNumber().setText(lastQuery
.accessionNumber
);
80 specimenSearchComposite
.getTextCollector().setText(lastQuery
.collector
);
81 specimenSearchComposite
.getTextCollectorNumber().setText(lastQuery
.collectorsNumber
);
82 specimenSearchComposite
.getTextCountry().setText(lastQuery
.country
);
83 specimenSearchComposite
.getTextHerbarium().setText(lastQuery
.herbarium
);
84 specimenSearchComposite
.getTextLocality().setText(lastQuery
.locality
);
85 specimenSearchComposite
.getTextTaxonName().setText(lastQuery
.taxonName
);
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
));
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
));
95 public void saveLastSate() {
96 lastQuery
= new OccurenceQuery(getTaxonName(), getCollector(), getCollectorNumber(), getAccessionNumber(), getHerbarium(), getCountry(), getLocality(), getDateFrom(), getDateTo());
100 * Returns the {@link Composite} handled by this controller
103 public Composite
getComposite() {
104 return specimenSearchComposite
;
108 * Returns the taxon name entered in the search view
109 * @return the taxon name as a {@link String}
110 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextTaxonName()
112 public String
getTaxonName() {
113 return specimenSearchComposite
.getTextTaxonName().getText();
117 * Returns the collector entered in the search view
118 * @return the collector as a {@link String}
119 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextCollector()
121 public String
getCollector() {
122 return specimenSearchComposite
.getTextCollector().getText();
126 * Returns the collecting number entered in the search view
127 * @return the collecting as a {@link String}
128 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextCollectorNumber()
130 public String
getCollectorNumber() {
131 return specimenSearchComposite
.getTextCollectorNumber().getText();
135 * Returns the accession number entered in the search view
136 * @return the accession number as a {@link String}
137 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextAccessionNumber()
139 public String
getAccessionNumber() {
140 return specimenSearchComposite
.getTextAccessionNumber().getText();
144 * Returns the herbarium entered in the search view
145 * @return the herbarium as a {@link String}
146 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getComboHerbarium()
148 public String
getHerbarium() {
149 return specimenSearchComposite
.getTextHerbarium().getText();
153 * Returns the country entered in the search view
154 * @return the country as a {@link String}
155 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getComboCountry()
157 public String
getCountry() {
158 return specimenSearchComposite
.getTextCountry().getText();
159 // return specimenSearchComposite.getComboCountry().getItem(specimenSearchComposite.getComboCountry().getSelectionIndex());
163 * Returns the locality entered in the search view
164 * @return the locality as a {@link String}
165 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextLocality()
167 public String
getLocality() {
168 return specimenSearchComposite
.getTextLocality().getText();
172 * Returns the start date entered in the search view.
173 * @return the date as an instance of {@link Calendar}
174 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateFrom()
176 public Calendar
getDateFrom() {
177 if(specimenSearchComposite
.getBtnShowDate().getSelection()){
178 Calendar dateFrom
= new GregorianCalendar();
180 dateFrom
.set(specimenSearchComposite
.getDateFrom().getYear(), specimenSearchComposite
.getDateFrom().getMonth(), specimenSearchComposite
.getDateFrom().getDay());
187 * Returns the end date entered in the search view.
188 * @return the date as an instance of {@link Calendar}
189 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateTo()
191 public Calendar
getDateTo() {
192 if(specimenSearchComposite
.getBtnShowDate().getSelection()){
193 Calendar dateTo
= new GregorianCalendar();
195 dateTo
.set(specimenSearchComposite
.getDateTo().getYear(), specimenSearchComposite
.getDateTo().getMonth(), specimenSearchComposite
.getDateTo().getDay());