*/
package eu.etaxonomy.taxeditor.view.specimenSearch;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
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}.
* @author pplitzner
*/
public class SpecimenSearchController implements Listener{
- private final SpecimenSearchComposite specimenSearchComposite;
+ private SpecimenSearchComposite specimenSearchComposite;
+ private final List<String> lastStateList = new ArrayList<String>();
+ private OccurenceQuery lastQuery = null;
+
+ 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)
}
}
+
+ 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());
+ }
+
/**
* Returns the {@link Composite} handled by this controller
* @return
*/
public String getHerbarium() {
return specimenSearchComposite.getTextHerbarium().getText();
-// return specimenSearchComposite.getComboHerbarium().getItem(specimenSearchComposite.getComboHerbarium().getSelectionIndex());
}
/**