Subversion Repositories eFlore/Applications.del

Rev

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

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