Subversion Repositories eFlore/Applications.del

Rev

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