Subversion Repositories eFlore/Applications.del

Rev

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

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