2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.view
.specimenSearch
;
11 import java
.util
.Calendar
;
12 import java
.util
.GregorianCalendar
;
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
;
20 import eu
.etaxonomy
.cdm
.ext
.occurrence
.OccurenceQuery
;
23 * Controller class for handling a {@link SpecimenSearchComposite}.
28 public class SpecimenSearchController
implements Listener
{
30 private SpecimenSearchComposite specimenSearchComposite
;
31 private OccurenceQuery lastQuery
= null;
33 private static SpecimenSearchController instance
= null;
35 public static SpecimenSearchController
getInstance(Composite parent
){
37 instance
= new SpecimenSearchController(parent
);
40 instance
.init(parent
);
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
48 private SpecimenSearchController(Composite parent
) {
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);
64 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
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());
76 private void loadLastState(){
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 if(lastQuery
.dateFrom
!=null){
86 specimenSearchComposite
.getDateFrom().setDate(lastQuery
.dateFrom
.get(Calendar
.YEAR
), lastQuery
.dateFrom
.get(Calendar
.MONTH
), lastQuery
.dateFrom
.get(Calendar
.DAY_OF_MONTH
));
88 if(lastQuery
.dateTo
!=null){
89 specimenSearchComposite
.getDateTo().setDate(lastQuery
.dateTo
.get(Calendar
.YEAR
), lastQuery
.dateTo
.get(Calendar
.MONTH
), lastQuery
.dateTo
.get(Calendar
.DAY_OF_MONTH
));
94 public void saveLastSate() {
95 lastQuery
= new OccurenceQuery(getTaxonName(), getCollector(), getCollectorNumber(), getAccessionNumber(), getHerbarium(), getCountry(), getLocality(), getDateFrom(), getDateTo());
99 * Returns the {@link Composite} handled by this controller
102 public Composite
getComposite() {
103 return specimenSearchComposite
;
107 * Returns the taxon name entered in the search view
108 * @return the taxon name as a {@link String}
109 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextTaxonName()
111 public String
getTaxonName() {
112 return specimenSearchComposite
.getTextTaxonName().getText();
116 * Returns the collector entered in the search view
117 * @return the collector as a {@link String}
118 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextCollector()
120 public String
getCollector() {
121 return specimenSearchComposite
.getTextCollector().getText();
125 * Returns the collecting number entered in the search view
126 * @return the collecting as a {@link String}
127 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextCollectorNumber()
129 public String
getCollectorNumber() {
130 return specimenSearchComposite
.getTextCollectorNumber().getText();
134 * Returns the accession number entered in the search view
135 * @return the accession number as a {@link String}
136 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextAccessionNumber()
138 public String
getAccessionNumber() {
139 return specimenSearchComposite
.getTextAccessionNumber().getText();
143 * Returns the herbarium entered in the search view
144 * @return the herbarium as a {@link String}
145 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getComboHerbarium()
147 public String
getHerbarium() {
148 return specimenSearchComposite
.getTextHerbarium().getText();
152 * Returns the country entered in the search view
153 * @return the country as a {@link String}
154 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getComboCountry()
156 public String
getCountry() {
157 return specimenSearchComposite
.getTextCountry().getText();
158 // return specimenSearchComposite.getComboCountry().getItem(specimenSearchComposite.getComboCountry().getSelectionIndex());
162 * Returns the locality entered in the search view
163 * @return the locality as a {@link String}
164 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getTextLocality()
166 public String
getLocality() {
167 return specimenSearchComposite
.getTextLocality().getText();
171 * Returns the start date entered in the search view.
172 * @return the date as an instance of {@link Calendar}
173 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateFrom()
175 public Calendar
getDateFrom() {
176 if(specimenSearchComposite
.getBtnShowDate().getSelection()){
177 Calendar dateFrom
= new GregorianCalendar();
179 dateFrom
.set(specimenSearchComposite
.getDateFrom().getYear(), specimenSearchComposite
.getDateFrom().getMonth(), specimenSearchComposite
.getDateFrom().getDay());
186 * Returns the end date entered in the search view.
187 * @return the date as an instance of {@link Calendar}
188 * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateTo()
190 public Calendar
getDateTo() {
191 if(specimenSearchComposite
.getBtnShowDate().getSelection()){
192 Calendar dateTo
= new GregorianCalendar();
194 dateTo
.set(specimenSearchComposite
.getDateTo().getYear(), specimenSearchComposite
.getDateTo().getMonth(), specimenSearchComposite
.getDateTo().getDay());