Subversion Repositories eFlore/Applications.del

Rev

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