Revision b9d3a4d8
Added by Patrick Plitzner almost 10 years ago
- saved last parameters entered for specimen search
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/specimenSearch/SpecimenSearchController.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.view.specimenSearch; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
12 | 13 |
import java.util.Calendar; |
13 | 14 |
import java.util.GregorianCalendar; |
15 |
import java.util.List; |
|
14 | 16 |
|
15 | 17 |
import org.eclipse.swt.SWT; |
16 | 18 |
import org.eclipse.swt.widgets.Button; |
... | ... | |
18 | 20 |
import org.eclipse.swt.widgets.Event; |
19 | 21 |
import org.eclipse.swt.widgets.Listener; |
20 | 22 |
|
23 |
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery; |
|
24 |
|
|
21 | 25 |
/** |
22 | 26 |
* Controller class for handling a {@link SpecimenSearchComposite}. |
23 | 27 |
* @author pplitzner |
... | ... | |
26 | 30 |
*/ |
27 | 31 |
public class SpecimenSearchController implements Listener{ |
28 | 32 |
|
29 |
private final SpecimenSearchComposite specimenSearchComposite; |
|
33 |
private SpecimenSearchComposite specimenSearchComposite; |
|
34 |
private final List<String> lastStateList = new ArrayList<String>(); |
|
35 |
private OccurenceQuery lastQuery = null; |
|
36 |
|
|
37 |
private static SpecimenSearchController instance = null; |
|
38 |
|
|
39 |
public static SpecimenSearchController getInstance(Composite parent){ |
|
40 |
if(instance==null){ |
|
41 |
instance = new SpecimenSearchController(parent); |
|
42 |
return instance; |
|
43 |
} |
|
44 |
instance.init(parent); |
|
45 |
return instance; |
|
46 |
} |
|
30 | 47 |
|
31 | 48 |
/** |
32 | 49 |
* Constructs a new controller which will itself construct the composite |
33 | 50 |
* @param parent the parent {@link Composite} for the one handles by this controller |
34 | 51 |
*/ |
35 |
public SpecimenSearchController(Composite parent) { |
|
52 |
private SpecimenSearchController(Composite parent) { |
|
53 |
init(parent); |
|
54 |
} |
|
55 |
|
|
56 |
private void init(Composite parent){ |
|
36 | 57 |
this.specimenSearchComposite = new SpecimenSearchComposite(parent, SWT.NONE); |
58 |
this.specimenSearchComposite.addListener(SWT.Selection, this); |
|
37 | 59 |
specimenSearchComposite.getBtnShowDate().addListener(SWT.Selection, this); |
38 | 60 |
specimenSearchComposite.getBtnShowDate().setSelection(false); |
39 | 61 |
specimenSearchComposite.getDateFrom().setEnabled(false); |
40 | 62 |
specimenSearchComposite.getDateTo().setEnabled(false); |
63 |
|
|
64 |
loadLastState(); |
|
41 | 65 |
} |
42 | 66 |
|
43 | 67 |
/* (non-Javadoc) |
... | ... | |
52 | 76 |
} |
53 | 77 |
} |
54 | 78 |
|
79 |
|
|
80 |
private void loadLastState(){ |
|
81 |
if(lastQuery!=null){ |
|
82 |
specimenSearchComposite.getTextAccessionNumber().setText(lastQuery.accessionNumber); |
|
83 |
specimenSearchComposite.getTextCollector().setText(lastQuery.collector); |
|
84 |
specimenSearchComposite.getTextCollectorNumber().setText(lastQuery.collectorsNumber); |
|
85 |
specimenSearchComposite.getTextCountry().setText(lastQuery.country); |
|
86 |
specimenSearchComposite.getTextHerbarium().setText(lastQuery.herbarium); |
|
87 |
specimenSearchComposite.getTextLocality().setText(lastQuery.locality); |
|
88 |
specimenSearchComposite.getTextTaxonName().setText(lastQuery.taxonName); |
|
89 |
if(lastQuery.dateFrom!=null){ |
|
90 |
specimenSearchComposite.getDateFrom().setDate(lastQuery.dateFrom.get(Calendar.YEAR), lastQuery.dateFrom.get(Calendar.MONTH), lastQuery.dateFrom.get(Calendar.DAY_OF_MONTH)); |
|
91 |
} |
|
92 |
if(lastQuery.dateTo!=null){ |
|
93 |
specimenSearchComposite.getDateTo().setDate(lastQuery.dateTo.get(Calendar.YEAR), lastQuery.dateTo.get(Calendar.MONTH), lastQuery.dateTo.get(Calendar.DAY_OF_MONTH)); |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
public void saveLastSate() { |
|
99 |
lastQuery = new OccurenceQuery(getTaxonName(), getCollector(), getCollectorNumber(), getAccessionNumber(), getHerbarium(), getCountry(), getLocality(), getDateFrom(), getDateTo()); |
|
100 |
} |
|
101 |
|
|
55 | 102 |
/** |
56 | 103 |
* Returns the {@link Composite} handled by this controller |
57 | 104 |
* @return |
... | ... | |
103 | 150 |
*/ |
104 | 151 |
public String getHerbarium() { |
105 | 152 |
return specimenSearchComposite.getTextHerbarium().getText(); |
106 |
// return specimenSearchComposite.getComboHerbarium().getItem(specimenSearchComposite.getComboHerbarium().getSelectionIndex()); |
|
107 | 153 |
} |
108 | 154 |
|
109 | 155 |
/** |
Also available in: Unified diff