Subversion Repositories eFlore/Applications.del

Rev

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

Rev 408 Rev 420
1
package org.tela_botanica.del.client.composants.moteurrecherche;
1
package org.tela_botanica.del.client.composants.moteurrecherche;
2
 
2
 
3
import org.tela_botanica.del.client.cache.CacheClient;
3
import org.tela_botanica.del.client.cache.CacheClient;
4
import org.tela_botanica.del.client.composants.formulaires.AutoCompletionComboBoxPresenteur;
4
import org.tela_botanica.del.client.composants.formulaires.AutoCompletionComboBoxPresenteur;
5
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
5
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
6
import org.tela_botanica.del.client.modeles.InformationsRecherche;
6
import org.tela_botanica.del.client.modeles.InformationsRecherche;
7
import org.tela_botanica.del.client.services.UtilitairesAutoCompletionService;
7
import org.tela_botanica.del.client.services.UtilitairesAutoCompletionService;
8
 
8
 
9
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.event.dom.client.ClickEvent;
10
import com.google.gwt.event.dom.client.ClickHandler;
10
import com.google.gwt.event.dom.client.ClickHandler;
11
import com.google.gwt.event.dom.client.HasClickHandlers;
11
import com.google.gwt.event.dom.client.HasClickHandlers;
12
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
12
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
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.http.client.Response;
16
import com.google.gwt.http.client.Response;
17
import com.google.gwt.json.client.JSONArray;
17
import com.google.gwt.json.client.JSONArray;
18
import com.google.gwt.json.client.JSONParser;
18
import com.google.gwt.json.client.JSONParser;
19
import com.google.gwt.json.client.JSONValue;
19
import com.google.gwt.json.client.JSONValue;
20
import com.google.gwt.user.client.ui.HasText;
20
import com.google.gwt.user.client.ui.HasText;
21
import com.google.gwt.user.client.ui.HasWidgets;
21
import com.google.gwt.user.client.ui.HasWidgets;
22
import com.google.gwt.user.client.ui.IsWidget;
22
import com.google.gwt.user.client.ui.IsWidget;
23
 
23
 
24
public abstract class MoteurRecherchePresenteur extends Presenteur {
24
public abstract class MoteurRecherchePresenteur extends Presenteur {
25
 
25
 
26
	public abstract interface Vue extends IsWidget {
26
	public abstract interface Vue extends IsWidget {
27
 
27
 
28
		public abstract HasClickHandlers getLienRechercheAvancee();
28
		public abstract HasClickHandlers getLienRechercheAvancee();
29
 
29
 
30
		public abstract void basculerAffichageZoneCache();
30
		public abstract void basculerAffichageZoneCache();
31
 
31
 
32
		public abstract HasClickHandlers getBoutonRechercheSimple();
32
		public abstract HasClickHandlers getBoutonRechercheSimple();
33
		
33
 
34
		public abstract HasClickHandlers getBoutonFermer();
34
		public abstract HasClickHandlers getBoutonFermer();
-
 
35
 
-
 
36
		public abstract HasClickHandlers getBoutonVider();
35
 
37
 
36
		public abstract HasClickHandlers getBoutonRechercheAvancee();
38
		public abstract HasClickHandlers getBoutonRechercheAvancee();
37
 
39
 
38
		public abstract HasKeyPressHandlers getChampSaisie();
40
		public abstract HasKeyPressHandlers getChampSaisie();
39
 
41
 
40
		public abstract HasClickHandlers getChampSaisieCliquable();
42
		public abstract HasClickHandlers getChampSaisieCliquable();
41
 
43
 
42
		public abstract String getValeurRechercheSimple();
44
		public abstract String getValeurRechercheSimple();
43
 
45
 
44
		public void setValeurRechercheSimple(String valeurRecherche);
46
		public void setValeurRechercheSimple(String valeurRecherche);
45
 
47
 
46
		public String getLabelRecherche();
48
		public String getLabelRecherche();
47
 
49
 
48
		public HasText getRecherchePrincipale();
50
		public HasText getRecherchePrincipale();
49
 
51
 
50
		public HasText getDepartement();
52
		public HasText getDepartement();
51
 
53
 
52
		public HasText getCommune();
54
		public HasText getCommune();
53
 
55
 
54
		public HasWidgets getTaxon();
56
		public HasWidgets getTaxon();
55
 
57
 
56
		public HasText getFamille();
58
		public HasText getFamille();
57
 
59
 
58
		public HasText getGenre();
60
		public HasText getGenre();
59
 
61
 
60
		public HasText getTag();
62
		public HasText getTag();
61
 
63
 
62
		public HasText getMotCle();
64
		public HasText getMotCle();
63
 
65
 
64
		public HasText getAuteur();
66
		public HasText getAuteur();
65
 
67
 
66
		public HasText getDate();
68
		public HasText getDate();
67
 
69
 
68
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
70
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
-
 
71
		
-
 
72
		public void chargerValeursRechercheSimplePrecedente(InformationsRecherche informationsRecherche);
69
		
73
 
-
 
74
		public void focusSaisie();
-
 
75
		
70
		public void focusSaisie();
76
		public void nettoyer();
71
	}
77
	}
72
 
78
 
73
	private final Vue vue;
79
	private final Vue vue;
74
	private final boolean pourRechercheImages, pourRechercheObservations;
80
	private final boolean pourRechercheImages, pourRechercheObservations;
75
	
81
 
76
	private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
82
	private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
77
 
83
 
-
 
84
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages,
78
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) {
85
			boolean pourRechercheObservations) {
79
		this.vue = vue;
86
		this.vue = vue;
80
		this.pourRechercheImages = pourRechercheImages;
87
		this.pourRechercheImages = pourRechercheImages;
81
		this.pourRechercheObservations = pourRechercheObservations;
88
		this.pourRechercheObservations = pourRechercheObservations;
82
		
89
 
83
		autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(UtilitairesAutoCompletionService.urlServiceCompletionNomLocale) {	
90
		autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(
-
 
91
				UtilitairesAutoCompletionService.urlServiceCompletionNomLocale) {
84
			
92
 
85
			protected String effectuerPreTraitementChaineRequete(String requete) {
93
			protected String effectuerPreTraitementChaineRequete(String requete) {
-
 
94
				return UtilitairesAutoCompletionService
86
				return UtilitairesAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
95
						.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
87
				// A décommenter lors de l'utilisation des web services eflore
96
				// A décommenter lors de l'utilisation des web services eflore
-
 
97
				// return
88
				//return RetourAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceEflore(requete);
98
				// RetourAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceEflore(requete);
89
			}
99
			}
90
			
100
 
91
			@Override
101
			@Override
92
			protected String[] parserResultatRequete(Response response) {
102
			protected String[] parserResultatRequete(Response response) {
93
				return UtilitairesAutoCompletionService.parserRetourSimple(response);
103
				return UtilitairesAutoCompletionService
-
 
104
						.parserRetourSimple(response);
94
				// A décommenter lors de l'utilisation des web services eflore
105
				// A décommenter lors de l'utilisation des web services eflore
95
				//return RetourAutoCompletionService.parserRetourOss(response);
106
				// return RetourAutoCompletionService.parserRetourOss(response);
96
			}
107
			}
97
		};	
108
		};
98
		gererEvenements();
109
		gererEvenements();
99
	}
110
	}
100
 
111
 
101
	@Override
112
	@Override
102
	public void go(HasWidgets composite) {
113
	public void go(HasWidgets composite) {
103
		afficherRequeteEtLancerRecherche();
114
		afficherRequeteEtLancerRecherche();
104
		autoCompletionNomTaxonsPresenteur.go(vue.getTaxon());
115
		autoCompletionNomTaxonsPresenteur.go(vue.getTaxon());
105
		composite.add(vue.asWidget());
116
		composite.add(vue.asWidget());
106
		vue.focusSaisie();
117
		vue.focusSaisie();
107
	}
118
	}
108
 
119
 
109
	@Override
120
	@Override
110
	protected void gererEvenements() {
121
	protected void gererEvenements() {
111
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
122
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
112
			public void onClick(ClickEvent event) {
123
			public void onClick(ClickEvent event) {
113
				vue.basculerAffichageZoneCache();
124
				vue.basculerAffichageZoneCache();
114
			}
125
			}
115
		});
126
		});
116
 
127
 
117
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
128
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
118
			public void onClick(ClickEvent event) {
129
			public void onClick(ClickEvent event) {
119
				collecterInfosRecherche();
130
				collecterInfosRecherche();
120
				afficherRequeteEtLancerRecherche();
131
				afficherRequeteEtLancerRechercheSimple();
121
			}
132
			}
122
		});
133
		});
123
 
134
 
124
		vue.getBoutonFermer().addClickHandler(new ClickHandler() {
135
		vue.getBoutonFermer().addClickHandler(new ClickHandler() {
125
			
136
 
126
			@Override
137
			@Override
127
			public void onClick(ClickEvent event) {
138
			public void onClick(ClickEvent event) {
128
				vue.basculerAffichageZoneCache();
139
				vue.basculerAffichageZoneCache();
129
			}
140
			}
130
		});
141
		});
-
 
142
 
-
 
143
		vue.getBoutonVider().addClickHandler(new ClickHandler() {
-
 
144
 
-
 
145
			@Override
-
 
146
			public void onClick(ClickEvent event) {
-
 
147
				
-
 
148
				autoCompletionNomTaxonsPresenteur.nettoyer();
-
 
149
				vue.nettoyer();
-
 
150
				
-
 
151
				InformationsRecherche infosRecherche = new InformationsRecherche();
-
 
152
				if (isPourRechercheImages()) {
-
 
153
					CacheClient.getInstance().setInformationsRechercheImage(infosRecherche);
-
 
154
				} else if (isPourRechercheObservations()) {
-
 
155
					CacheClient.getInstance().setInformationsRechercheObservation(infosRecherche);
-
 
156
				}
-
 
157
			}
-
 
158
		});
-
 
159
 
131
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
160
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
132
			public void onClick(ClickEvent event) {
161
			public void onClick(ClickEvent event) {
133
				collecterInfosRecherche();
162
				collecterInfosRecherche();
134
				vue.basculerAffichageZoneCache();
163
				vue.basculerAffichageZoneCache();
135
				afficherRequeteEtLancerRecherche();
164
				afficherRequeteEtLancerRecherche();
136
			}
165
			}
137
		});
166
		});
138
 
167
 
139
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
168
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
140
 
169
 
141
			public void onKeyPress(KeyPressEvent event) {
170
			public void onKeyPress(KeyPressEvent event) {
142
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
171
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
143
					collecterInfosRecherche();
172
					collecterInfosRecherche();
144
					afficherRequeteEtLancerRecherche();
173
					afficherRequeteEtLancerRechercheSimple();
145
				}
174
				}
146
			}
175
			}
147
		});
176
		});
148
 
177
 
149
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
178
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
150
 
179
 
151
			@Override
180
			@Override
152
			public void onClick(ClickEvent event) {
181
			public void onClick(ClickEvent event) {
153
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
182
				if (vue.getValeurRechercheSimple().equals(
-
 
183
						vue.getLabelRecherche())) {
154
					vue.setValeurRechercheSimple("");
184
					vue.setValeurRechercheSimple("");
155
				}
185
				}
156
			}
186
			}
157
		});
187
		});
158
	}
188
	}
159
 
189
 
160
	private void collecterInfosRecherche() {
190
	private void collecterInfosRecherche() {
161
		InformationsRecherche informationRecherche = new InformationsRecherche();
191
		InformationsRecherche informationRecherche = new InformationsRecherche();
162
		informationRecherche.setAuteur(vue.getAuteur().getText());
-
 
163
		informationRecherche.setCommune(vue.getCommune().getText());
192
		informationRecherche.setTaxon(autoCompletionNomTaxonsPresenteur.getValeur());
164
		informationRecherche.setDate(vue.getDate().getText());
-
 
165
		informationRecherche.setDepartement(vue.getDepartement().getText());
193
		informationRecherche.setDepartement(vue.getDepartement().getText());
-
 
194
		informationRecherche.setCommune(vue.getCommune().getText());
166
		informationRecherche.setFamille(vue.getFamille().getText());
195
		informationRecherche.setFamille(vue.getFamille().getText());
167
		informationRecherche.setGenre(vue.getGenre().getText());
196
		informationRecherche.setGenre(vue.getGenre().getText());
-
 
197
		informationRecherche.setTag(vue.getTag().getText());
168
		informationRecherche.setMotClef(vue.getMotCle().getText());
198
		informationRecherche.setMotClef(vue.getMotCle().getText());
-
 
199
		informationRecherche.setAuteur(vue.getAuteur().getText());
-
 
200
		informationRecherche.setDate(vue.getDate().getText());
169
 
201
		
170
		if (!vue.getRecherchePrincipale().getText().equals(vue.getLabelRecherche())) {
202
		if (!vue.getRecherchePrincipale().getText()
-
 
203
				.equals(vue.getLabelRecherche())) {
171
			informationRecherche.setRechercheLibre(vue.getRecherchePrincipale().getText());
204
			informationRecherche.setRechercheLibre(vue.getRecherchePrincipale()
-
 
205
					.getText());
172
		}
206
		}
173
		if (isPourRechercheImages()) {
207
		if (isPourRechercheImages()) {
174
			CacheClient.getInstance().setInformationsRechercheImage(informationRecherche);
208
			CacheClient.getInstance().setInformationsRechercheImage(
-
 
209
					informationRecherche);
175
		} else if (isPourRechercheObservations()) {
210
		} else if (isPourRechercheObservations()) {
176
			CacheClient.getInstance().setInformationsRechercheObservation(informationRecherche);
211
			CacheClient.getInstance().setInformationsRechercheObservation(
-
 
212
					informationRecherche);
177
		}
213
		}
178
	}
214
	}
179
 
215
 
180
	private InformationsRecherche getInformationsRechercheEnCache() {
216
	private InformationsRecherche getInformationsRechercheEnCache() {
181
		if (isPourRechercheImages()) {
217
		if (isPourRechercheImages()) {
182
			return CacheClient.getInstance().getInformationsRechercheImage();
218
			return CacheClient.getInstance().getInformationsRechercheImage();
183
		} else if (isPourRechercheObservations()) {
219
		} else if (isPourRechercheObservations()) {
-
 
220
			return CacheClient.getInstance()
184
			return CacheClient.getInstance().getInformationsRechercheObservation();
221
					.getInformationsRechercheObservation();
185
		}
222
		}
186
		return null;
223
		return null;
187
	}
224
	}
-
 
225
 
-
 
226
	public void afficherRequeteEtLancerRechercheSimple() {
-
 
227
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
-
 
228
		if (informationsRecherche != null) {
-
 
229
			vue.chargerValeursRechercheSimplePrecedente(informationsRecherche);
-
 
230
		}
-
 
231
		lancerRecherche();
-
 
232
	}
188
 
233
	
189
	public void afficherRequeteEtLancerRecherche() {
234
	public void afficherRequeteEtLancerRecherche() {
190
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
235
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
191
		if (informationsRecherche != null) {
236
		if (informationsRecherche != null) {
-
 
237
			autoCompletionNomTaxonsPresenteur.setValeur(informationsRecherche.getTaxon());
192
			vue.chargerValeursRecherchePrecedente(informationsRecherche);
238
			vue.chargerValeursRecherchePrecedente(informationsRecherche);
193
		}
239
		}
194
		lancerRecherche();
240
		lancerRecherche();
195
	}
241
	}
196
 
242
 
197
	public abstract void lancerRecherche();
243
	public abstract void lancerRecherche();	
198
 
244
 
199
	public boolean isPourRechercheImages() {
245
	public boolean isPourRechercheImages() {
200
		return pourRechercheImages;
246
		return pourRechercheImages;
201
	}
247
	}
202
 
248
 
203
	public boolean isPourRechercheObservations() {
249
	public boolean isPourRechercheObservations() {
204
		return pourRechercheObservations;
250
		return pourRechercheObservations;
205
	}
251
	}
206
}
252
}