Subversion Repositories eFlore/Applications.del

Rev

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