Subversion Repositories eFlore/Applications.del

Rev

Rev 408 | Rev 436 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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