Subversion Repositories eFlore/Applications.del

Rev

Rev 161 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 161 Rev 166
1
package org.tela_botanica.del.client.vues.rechercheobservations;
1
package org.tela_botanica.del.client.vues.rechercheobservations;
2
 
2
 
3
import java.util.HashMap;
3
import java.util.HashMap;
4
import java.util.Iterator;
4
import java.util.Iterator;
-
 
5
import java.util.List;
5
 
6
 
-
 
7
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
-
 
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;
9
import com.google.gwt.event.dom.client.ClickHandler;
12
import com.google.gwt.event.dom.client.ClickHandler;
10
import com.google.gwt.event.dom.client.KeyCodes;
13
import com.google.gwt.event.dom.client.KeyCodes;
11
import com.google.gwt.event.dom.client.KeyPressEvent;
14
import com.google.gwt.event.dom.client.KeyPressEvent;
12
import com.google.gwt.event.dom.client.KeyPressHandler;
15
import com.google.gwt.event.dom.client.KeyPressHandler;
13
import com.google.gwt.user.client.ui.HasWidgets;
16
import com.google.gwt.user.client.ui.HasWidgets;
14
import com.google.gwt.user.client.ui.Panel;
17
import com.google.gwt.user.client.ui.Panel;
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;
17
 
20
 
18
public class RechercheObservationsPresenteur extends Presenteur {
21
public class RechercheObservationsPresenteur extends Presenteur {
-
 
22
 
-
 
23
	private List<Observation> observations;
19
 
24
 
20
	public RechercheObservationsPresenteur() {
25
	public RechercheObservationsPresenteur() {
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();
27
		}
32
		}
28
		composite.add(this.getVue());
33
		composite.add(this.getVue());
29
		handleEvents();
34
		handleEvents();
-
 
35
 
-
 
36
		// On commence par afficher la totalité des observations
-
 
37
		chercherObservations(null);
-
 
38
		afficherObservations();
30
	}
39
	}
31
 
40
 
32
	protected void handleEvents() {
41
	protected void handleEvents() {
33
 
42
 
34
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
43
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
35
 
44
 
36
		// Gestion du clic dans la zone de saisie
45
		// Gestion du clic dans la zone de saisie
37
		vue.recherchePrincipale.addClickHandler(new ClickHandler() {
46
		vue.recherchePrincipale.addClickHandler(new ClickHandler() {
38
 
47
 
39
			public void onClick(ClickEvent event) {
48
			public void onClick(ClickEvent event) {
40
				TextBox recherchePrincipale = (TextBox) event.getSource();
49
				TextBox recherchePrincipale = (TextBox) event.getSource();
41
				if (recherchePrincipale.getText().equals("Recherche libre")) {
50
				if (recherchePrincipale.getText().equals("Recherche libre")) {
42
					recherchePrincipale.setText("");
51
					recherchePrincipale.setText("");
43
				}
52
				}
44
			}
53
			}
45
		});
54
		});
46
 
55
 
47
		// Gestion de l'affichage de la recherche Avancée
56
		// Gestion de l'affichage de la recherche Avancée
48
		vue.lienRechercheAvancee.addClickHandler(new ClickHandler() {
57
		vue.lienRechercheAvancee.addClickHandler(new ClickHandler() {
49
 
58
 
50
			public void onClick(ClickEvent event) {
59
			public void onClick(ClickEvent event) {
51
				Panel rechercheAvancee = ((RechercheObservationsVue) getVue()).rechercheAvancee;
60
				Panel rechercheAvancee = ((RechercheObservationsVue) getVue()).rechercheAvancee;
52
				rechercheAvancee.setVisible(!rechercheAvancee.isVisible());
61
				rechercheAvancee.setVisible(!rechercheAvancee.isVisible());
53
			}
62
			}
54
		});
63
		});
55
 
64
 
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() {
59
 
68
 
60
			public void onClick(ClickEvent event) {
69
			public void onClick(ClickEvent event) {
-
 
70
				chercherObservations(collecterFormulaire());
61
				lancerRecherche();
71
				afficherObservations();
62
			}
72
			}
63
		});
73
		});
64
 
74
 
65
		vue.boutonRechercheAvancee.addClickHandler(new ClickHandler() {
75
		vue.boutonRechercheAvancee.addClickHandler(new ClickHandler() {
66
			public void onClick(ClickEvent event) {
76
			public void onClick(ClickEvent event) {
-
 
77
				chercherObservations(collecterFormulaire());
67
				lancerRecherche();
78
				afficherObservations();
68
			}
79
			}
69
		});
80
		});
70
 
81
 
71
		vue.recherchePrincipale.addKeyPressHandler(new KeyPressHandler() {
82
		vue.recherchePrincipale.addKeyPressHandler(new KeyPressHandler() {
72
 
83
 
73
			public void onKeyPress(KeyPressEvent event) {
84
			public void onKeyPress(KeyPressEvent event) {
74
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
85
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
-
 
86
					chercherObservations(collecterFormulaire());
75
					lancerRecherche();
87
					afficherObservations();
76
				}
88
				}
77
			}
89
			}
78
		});
90
		});
79
	}
91
	}
80
 
92
 
81
	// Lancer la recherche
93
	// Gestion de la recherche d'observations :
82
	public void lancerRecherche() {
-
 
83
 
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
		}
-
 
123
		if (!vue.auteur.getText().equals("")) {
-
 
124
			champsRecherche.put("auteur", vue.auteur.getText());
-
 
125
		}
-
 
126
		if (!vue.date.getText().equals("")) {
84
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
127
			champsRecherche.put("date", vue.date.getText());
-
 
128
		}
-
 
129
		return champsRecherche;
-
 
130
	}
-
 
131
 
-
 
132
	public void chercherObservations(HashMap<String, String> champsRecherche) {
85
 
133
 
-
 
134
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
-
 
135
		vue.rechercheAvancee.setVisible(false);
-
 
136
		this.observations = MockDatasource.getInstance().getObservations(champsRecherche);
86
		// Masquer la recherche Avancée
137
		vue.recherchePrecedente.setText(getChaineRecherche(champsRecherche));
87
		vue.rechercheAvancee.setVisible(false);
-
 
88
 
138
	}
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());
-
 
94
		valeursRecherche.put("taxon", vue.taxon.getText());
-
 
95
		valeursRecherche.put("fam", vue.famille.getText());
-
 
96
		valeursRecherche.put("gen", vue.genre.getText());
-
 
97
		valeursRecherche.put("tag", vue.tag.getText());
-
 
-
 
139
 
98
		valeursRecherche.put("motCle", vue.motCle.getText());
140
	public void afficherObservations() {
-
 
141
		RechercheObservationsVue vue = (RechercheObservationsVue) getVue();
-
 
142
 
99
		valeursRecherche.put("auteur", vue.auteur.getText());
143
		for (Observation observation : observations) {
100
		valeursRecherche.put("date", vue.date.getText());
144
			ObservationPresenteur presenteur = new ObservationPresenteur(observation);
101
 
145
			presenteur.go(vue.zoneObservations);
102
		vue.recherchePrecedente.setText(getChaineRecherche(valeursRecherche));
146
		}
103
	}
147
	}
104
 
148
 
105
	private String getChaineRecherche(HashMap<String, String> valeursRecherche) {
149
	private String getChaineRecherche(HashMap<String, String> valeursRecherche) {
106
		Iterator<String> itCles = valeursRecherche.keySet().iterator();
-
 
107
		String chaineRecherche = "";
150
		String chaineRecherche = "";
-
 
151
		if (valeursRecherche != null) {
-
 
152
			Iterator<String> itCles = valeursRecherche.keySet().iterator();
108
		while (itCles.hasNext()) {
153
			while (itCles.hasNext()) {
109
			String cle = itCles.next();
154
				String cle = itCles.next();
110
			String valeur = valeursRecherche.get(cle);
155
				String valeur = valeursRecherche.get(cle);
111
			if (valeur != "") {
156
				if (valeur != "") {
112
				chaineRecherche += cle + ":=" + valeur + " ";
157
					chaineRecherche += cle + ":=" + valeur + " ";
-
 
158
				}
113
			}
159
			}
114
		}
160
		}
115
		return chaineRecherche;
161
		return chaineRecherche;
116
	}
162
	}
117
}
163
}