Subversion Repositories eFlore/Applications.del

Rev

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

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