Subversion Repositories eFlore/Applications.del

Rev

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

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