import java.util.GregorianCalendar;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+
+import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
/**
* Controller class for handling a {@link SpecimenSearchComposite}.
* @date 03.09.2013
*
*/
-public class SpecimenSearchController {
+public class SpecimenSearchController implements Listener{
+
+ private SpecimenSearchComposite specimenSearchComposite;
+ private OccurenceQuery lastQuery = null;
- private final SpecimenSearchComposite specimenSearchComposite;
+ private static SpecimenSearchController instance = null;
+
+ public static SpecimenSearchController getInstance(Composite parent){
+ if(instance==null){
+ instance = new SpecimenSearchController(parent);
+ return instance;
+ }
+ instance.init(parent);
+ return instance;
+ }
/**
* Constructs a new controller which will itself construct the composite
* @param parent the parent {@link Composite} for the one handles by this controller
*/
- public SpecimenSearchController(Composite parent) {
+ private SpecimenSearchController(Composite parent) {
+ init(parent);
+ }
+
+ private void init(Composite parent){
this.specimenSearchComposite = new SpecimenSearchComposite(parent, SWT.NONE);
+ this.specimenSearchComposite.addListener(SWT.Selection, this);
+ specimenSearchComposite.getBtnShowDate().addListener(SWT.Selection, this);
+ specimenSearchComposite.getBtnShowDate().setSelection(false);
+ specimenSearchComposite.getDateFrom().setEnabled(false);
+ specimenSearchComposite.getDateTo().setEnabled(false);
+
+ loadLastState();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
+ */
+ @Override
+ public void handleEvent(Event event) {
+ Button btnShowDate = specimenSearchComposite.getBtnShowDate();
+ if(event.widget==btnShowDate){
+ specimenSearchComposite.getDateFrom().setEnabled(btnShowDate.getSelection());
+ specimenSearchComposite.getDateTo().setEnabled(btnShowDate.getSelection());
+ }
+ }
+
+
+ private void loadLastState(){
+ if(lastQuery!=null){
+ specimenSearchComposite.getTextAccessionNumber().setText(lastQuery.accessionNumber);
+ specimenSearchComposite.getTextCollector().setText(lastQuery.collector);
+ specimenSearchComposite.getTextCollectorNumber().setText(lastQuery.collectorsNumber);
+ specimenSearchComposite.getTextCountry().setText(lastQuery.country);
+ specimenSearchComposite.getTextHerbarium().setText(lastQuery.herbarium);
+ specimenSearchComposite.getTextLocality().setText(lastQuery.locality);
+ specimenSearchComposite.getTextTaxonName().setText(lastQuery.taxonName);
+ if(lastQuery.dateFrom!=null){
+ specimenSearchComposite.getDateFrom().setDate(lastQuery.dateFrom.get(Calendar.YEAR), lastQuery.dateFrom.get(Calendar.MONTH), lastQuery.dateFrom.get(Calendar.DAY_OF_MONTH));
+ }
+ if(lastQuery.dateTo!=null){
+ specimenSearchComposite.getDateTo().setDate(lastQuery.dateTo.get(Calendar.YEAR), lastQuery.dateTo.get(Calendar.MONTH), lastQuery.dateTo.get(Calendar.DAY_OF_MONTH));
+ }
+ }
+ }
+
+ public void saveLastSate() {
+ lastQuery = new OccurenceQuery(getTaxonName(), getCollector(), getCollectorNumber(), getAccessionNumber(), getHerbarium(), getCountry(), getLocality(), getDateFrom(), getDateTo());
}
/**
*/
public String getHerbarium() {
return specimenSearchComposite.getTextHerbarium().getText();
-// return specimenSearchComposite.getComboHerbarium().getItem(specimenSearchComposite.getComboHerbarium().getSelectionIndex());
}
/**
* @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateFrom()
*/
public Calendar getDateFrom() {
- Calendar dateFrom = new GregorianCalendar();
- dateFrom.clear();
- dateFrom.set(specimenSearchComposite.getDateFrom().getYear(), specimenSearchComposite.getDateFrom().getMonth(), specimenSearchComposite.getDateFrom().getDay());
- return dateFrom;
+ if(specimenSearchComposite.getBtnShowDate().getSelection()){
+ Calendar dateFrom = new GregorianCalendar();
+ dateFrom.clear();
+ dateFrom.set(specimenSearchComposite.getDateFrom().getYear(), specimenSearchComposite.getDateFrom().getMonth(), specimenSearchComposite.getDateFrom().getDay());
+ return dateFrom;
+ }
+ return null;
}
/**
* @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateTo()
*/
public Calendar getDateTo() {
- Calendar dateTo = new GregorianCalendar();
- dateTo.clear();
- dateTo.set(specimenSearchComposite.getDateTo().getYear(), specimenSearchComposite.getDateTo().getMonth(), specimenSearchComposite.getDateTo().getDay());
- return dateTo;
+ if(specimenSearchComposite.getBtnShowDate().getSelection()){
+ Calendar dateTo = new GregorianCalendar();
+ dateTo.clear();
+ dateTo.set(specimenSearchComposite.getDateTo().getYear(), specimenSearchComposite.getDateTo().getMonth(), specimenSearchComposite.getDateTo().getDay());
+ return dateTo;
+ }
+ return null;
}
}
\ No newline at end of file