Subversion Repositories eFlore/Applications.del

Rev

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