Subversion Repositories eFlore/Applications.del

Rev

Rev 161 | Rev 200 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 161 Rev 166
Line 1... Line 1...
1
package org.tela_botanica.del.client.vues.rechercheobservations;
1
package org.tela_botanica.del.client.vues.rechercheobservations;
Line 2... Line 2...
2
 
2
 
3
import java.util.HashMap;
3
import java.util.HashMap;
-
 
4
import java.util.Iterator;
Line 4... Line 5...
4
import java.util.Iterator;
5
import java.util.List;
-
 
6
 
-
 
7
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
Line 5... Line 8...
5
 
8
import org.tela_botanica.del.client.modeles.Observation;
6
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
9
import org.tela_botanica.del.client.utils.MockDatasource;
7
 
10
 
8
import com.google.gwt.event.dom.client.ClickEvent;
11
import com.google.gwt.event.dom.client.ClickEvent;
Line 15... Line 18...
15
import com.google.gwt.user.client.ui.RootPanel;
18
import com.google.gwt.user.client.ui.RootPanel;
16
import com.google.gwt.user.client.ui.TextBox;
19
import com.google.gwt.user.client.ui.TextBox;
Line 17... Line 20...
17
 
20
 
Line -... Line 21...
-
 
21
public class RechercheObservationsPresenteur extends Presenteur {
-
 
22
 
18
public class RechercheObservationsPresenteur extends Presenteur {
23
	private List<Observation> observations;
19
 
24
 
20
	public RechercheObservationsPresenteur() {
25
	public RechercheObservationsPresenteur() {
Line 21... Line 26...
21
		super(new RechercheObservationsVue());
26
		super(new RechercheObservationsVue());
22
	}
27
	}
23
 
28
 
24
	public void go(HasWidgets composite) {
29
	public void go(HasWidgets composite) {
25
		if (composite == null) {
30
		if (composite == null) {
26
			composite = RootPanel.get();
31
			composite = RootPanel.get();
-
 
32
		}
-
 
33
		composite.add(this.getVue());
-
 
34
		handleEvents();
-
 
35
 
27
		}
36
		// On commence par afficher la totalité des observations
Line 28... Line 37...
28
		composite.add(this.getVue());
37
		chercherObservations(null);
Line 29... Line 38...
29
		handleEvents();
38
		afficherObservations();
Line 56... Line 65...
56
		// Gestion de l'évènement recherche sur le clic ou sur l'appui de la
65
		// Gestion de l'évènement recherche sur le clic ou sur l'appui de la
57
		// touche Entrée
66
		// touche Entrée
58
		vue.boutonRecherche.addClickHandler(new ClickHandler() {
67
		vue.boutonRecherche.addClickHandler(new ClickHandler() {
Line 59... Line 68...
59
 
68
 
-
 
69
			public void onClick(ClickEvent event) {
60
			public void onClick(ClickEvent event) {
70
				chercherObservations(collecterFormulaire());
61
				lancerRecherche();
71
				afficherObservations();
62
			}
72
			}
Line 63... Line 73...
63
		});
73
		});
64
 
74
 
-
 
75
		vue.boutonRechercheAvancee.addClickHandler(new ClickHandler() {
65
		vue.boutonRechercheAvancee.addClickHandler(new ClickHandler() {
76
			public void onClick(ClickEvent event) {
66
			public void onClick(ClickEvent event) {
77
				chercherObservations(collecterFormulaire());
67
				lancerRecherche();
78
				afficherObservations();
Line 68... Line 79...
68
			}
79
			}
Line 69... Line 80...
69
		});
80
		});
70
 
81
 
-
 
82
		vue.recherchePrincipale.addKeyPressHandler(new KeyPressHandler() {
71
		vue.recherchePrincipale.addKeyPressHandler(new KeyPressHandler() {
83
 
72
 
84
			public void onKeyPress(KeyPressEvent event) {
73
			public void onKeyPress(KeyPressEvent event) {
85
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
74
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
86
					chercherObservations(collecterFormulaire());
75
					lancerRecherche();
87
					afficherObservations();
Line 76... Line 88...
76
				}
88
				}
77
			}
89
			}
78
		});
-
 
79
	}
90
		});
Line -... Line 91...
-
 
91
	}
-
 
92
 
-
 
93
	// Gestion de la recherche d'observations :
-
 
94
	public HashMap<String, String> collecterFormulaire() {
-
 
95
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
-
 
96
 
-
 
97
		HashMap<String, String> champsRecherche = new HashMap<String, String>();
-
 
98
 
-
 
99
		if (!vue.recherchePrincipale.getText().equals("")) {
-
 
100
			champsRecherche.put("search", vue.recherchePrincipale.getText());
-
 
101
		}
-
 
102
		if (!vue.departement.getText().equals("")) {
-
 
103
			champsRecherche.put("dept", vue.departement.getText());
-
 
104
		}
-
 
105
		if (!vue.commune.getText().equals("")) {
-
 
106
			champsRecherche.put("com", vue.commune.getText());
-
 
107
		}
-
 
108
		if (!vue.taxon.getText().equals("")) {
-
 
109
			champsRecherche.put("taxon", vue.taxon.getText());
-
 
110
		}
-
 
111
		if (!vue.famille.getText().equals("")) {
-
 
112
			champsRecherche.put("fam", vue.famille.getText());
-
 
113
		}
-
 
114
		if (!vue.genre.getText().equals("")) {
-
 
115
			champsRecherche.put("gen", vue.genre.getText());
-
 
116
		}
-
 
117
		if (!vue.tag.getText().equals("")) {
-
 
118
			champsRecherche.put("tag", vue.tag.getText());
-
 
119
		}
-
 
120
		if (!vue.motCle.getText().equals("")) {
-
 
121
			champsRecherche.put("motCle", vue.motCle.getText());
-
 
122
		}
80
 
123
		if (!vue.auteur.getText().equals("")) {
-
 
124
			champsRecherche.put("auteur", vue.auteur.getText());
-
 
125
		}
-
 
126
		if (!vue.date.getText().equals("")) {
-
 
127
			champsRecherche.put("date", vue.date.getText());
-
 
128
		}
81
	// Lancer la recherche
129
		return champsRecherche;
-
 
130
	}
-
 
131
 
-
 
132
	public void chercherObservations(HashMap<String, String> champsRecherche) {
Line 82... Line 133...
82
	public void lancerRecherche() {
133
 
83
 
-
 
84
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
134
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
85
 
-
 
86
		// Masquer la recherche Avancée
-
 
87
		vue.rechercheAvancee.setVisible(false);
-
 
88
 
-
 
89
		// Collecter les valeurs du formulaire
-
 
90
		HashMap<String, String> valeursRecherche = new HashMap<String, String>();
-
 
91
		valeursRecherche.put("search", vue.recherchePrincipale.getText());
-
 
92
		valeursRecherche.put("dept", vue.departement.getText());
-
 
93
		valeursRecherche.put("com", vue.commune.getText());
-
 
Line -... Line 135...
-
 
135
		vue.rechercheAvancee.setVisible(false);
94
		valeursRecherche.put("taxon", vue.taxon.getText());
136
		this.observations = MockDatasource.getInstance().getObservations(champsRecherche);
-
 
137
		vue.recherchePrecedente.setText(getChaineRecherche(champsRecherche));
-
 
138
	}
95
		valeursRecherche.put("fam", vue.famille.getText());
139
 
Line 96... Line 140...
96
		valeursRecherche.put("gen", vue.genre.getText());
140
	public void afficherObservations() {
97
		valeursRecherche.put("tag", vue.tag.getText());
-
 
98
		valeursRecherche.put("motCle", vue.motCle.getText());
141
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
-
 
142
 
-
 
143
		for (Observation observation : observations) {
99
		valeursRecherche.put("auteur", vue.auteur.getText());
144
			ObservationPresenteur presenteur = new ObservationPresenteur(observation);
100
		valeursRecherche.put("date", vue.date.getText());
145
			presenteur.go(vue.zoneObservations);
101
 
146
		}
102
		vue.recherchePrecedente.setText(getChaineRecherche(valeursRecherche));
147
	}
103
	}
148
 
-
 
149
	private String getChaineRecherche(HashMap<String, String> valeursRecherche) {
104
 
150
		String chaineRecherche = "";
105
	private String getChaineRecherche(HashMap<String, String> valeursRecherche) {
151
		if (valeursRecherche != null) {
106
		Iterator<String> itCles = valeursRecherche.keySet().iterator();
152
			Iterator<String> itCles = valeursRecherche.keySet().iterator();
107
		String chaineRecherche = "";
153
			while (itCles.hasNext()) {
108
		while (itCles.hasNext()) {
154
				String cle = itCles.next();