Subversion Repositories eFlore/Applications.del

Rev

Rev 210 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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