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);
|
407 |
gduche |
68 |
|
420 |
gduche |
69 |
public void chargerValeursRechercheSimplePrecedente(InformationsRecherche informationsRecherche);
|
|
|
70 |
|
407 |
gduche |
71 |
public void focusSaisie();
|
420 |
gduche |
72 |
|
|
|
73 |
public void nettoyer();
|
322 |
gduche |
74 |
}
|
|
|
75 |
|
335 |
benjamin |
76 |
private final Vue vue;
|
|
|
77 |
private final boolean pourRechercheImages, pourRechercheObservations;
|
420 |
gduche |
78 |
|
386 |
aurelien |
79 |
private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
|
335 |
benjamin |
80 |
|
420 |
gduche |
81 |
public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages,
|
|
|
82 |
boolean pourRechercheObservations) {
|
322 |
gduche |
83 |
this.vue = vue;
|
335 |
benjamin |
84 |
this.pourRechercheImages = pourRechercheImages;
|
|
|
85 |
this.pourRechercheObservations = pourRechercheObservations;
|
420 |
gduche |
86 |
|
|
|
87 |
autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(
|
|
|
88 |
UtilitairesAutoCompletionService.urlServiceCompletionNomLocale) {
|
|
|
89 |
|
386 |
aurelien |
90 |
protected String effectuerPreTraitementChaineRequete(String requete) {
|
420 |
gduche |
91 |
return UtilitairesAutoCompletionService
|
|
|
92 |
.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
|
386 |
aurelien |
93 |
// A décommenter lors de l'utilisation des web services eflore
|
420 |
gduche |
94 |
// return
|
|
|
95 |
// RetourAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceEflore(requete);
|
386 |
aurelien |
96 |
}
|
420 |
gduche |
97 |
|
386 |
aurelien |
98 |
@Override
|
|
|
99 |
protected String[] parserResultatRequete(Response response) {
|
420 |
gduche |
100 |
return UtilitairesAutoCompletionService
|
|
|
101 |
.parserRetourSimple(response);
|
386 |
aurelien |
102 |
// A décommenter lors de l'utilisation des web services eflore
|
420 |
gduche |
103 |
// return RetourAutoCompletionService.parserRetourOss(response);
|
386 |
aurelien |
104 |
}
|
420 |
gduche |
105 |
};
|
322 |
gduche |
106 |
gererEvenements();
|
|
|
107 |
}
|
335 |
benjamin |
108 |
|
322 |
gduche |
109 |
@Override
|
|
|
110 |
public void go(HasWidgets composite) {
|
335 |
benjamin |
111 |
afficherRequeteEtLancerRecherche();
|
386 |
aurelien |
112 |
autoCompletionNomTaxonsPresenteur.go(vue.getTaxon());
|
322 |
gduche |
113 |
composite.add(vue.asWidget());
|
407 |
gduche |
114 |
vue.focusSaisie();
|
322 |
gduche |
115 |
}
|
|
|
116 |
|
|
|
117 |
@Override
|
|
|
118 |
protected void gererEvenements() {
|
|
|
119 |
vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
|
|
|
120 |
public void onClick(ClickEvent event) {
|
|
|
121 |
vue.basculerAffichageZoneCache();
|
|
|
122 |
}
|
|
|
123 |
});
|
335 |
benjamin |
124 |
|
322 |
gduche |
125 |
vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
|
|
|
126 |
public void onClick(ClickEvent event) {
|
335 |
benjamin |
127 |
collecterInfosRecherche();
|
420 |
gduche |
128 |
afficherRequeteEtLancerRechercheSimple();
|
322 |
gduche |
129 |
}
|
|
|
130 |
});
|
335 |
benjamin |
131 |
|
408 |
gduche |
132 |
vue.getBoutonFermer().addClickHandler(new ClickHandler() {
|
420 |
gduche |
133 |
|
408 |
gduche |
134 |
@Override
|
|
|
135 |
public void onClick(ClickEvent event) {
|
|
|
136 |
vue.basculerAffichageZoneCache();
|
|
|
137 |
}
|
|
|
138 |
});
|
420 |
gduche |
139 |
|
|
|
140 |
vue.getBoutonVider().addClickHandler(new ClickHandler() {
|
|
|
141 |
|
|
|
142 |
@Override
|
|
|
143 |
public void onClick(ClickEvent event) {
|
|
|
144 |
|
|
|
145 |
autoCompletionNomTaxonsPresenteur.nettoyer();
|
|
|
146 |
vue.nettoyer();
|
|
|
147 |
|
|
|
148 |
InformationsRecherche infosRecherche = new InformationsRecherche();
|
|
|
149 |
if (isPourRechercheImages()) {
|
|
|
150 |
CacheClient.getInstance().setInformationsRechercheImage(infosRecherche);
|
|
|
151 |
} else if (isPourRechercheObservations()) {
|
|
|
152 |
CacheClient.getInstance().setInformationsRechercheObservation(infosRecherche);
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
});
|
|
|
156 |
|
322 |
gduche |
157 |
vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
|
|
|
158 |
public void onClick(ClickEvent event) {
|
335 |
benjamin |
159 |
collecterInfosRecherche();
|
|
|
160 |
vue.basculerAffichageZoneCache();
|
|
|
161 |
afficherRequeteEtLancerRecherche();
|
322 |
gduche |
162 |
}
|
|
|
163 |
});
|
335 |
benjamin |
164 |
|
322 |
gduche |
165 |
vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
|
335 |
benjamin |
166 |
|
322 |
gduche |
167 |
public void onKeyPress(KeyPressEvent event) {
|
|
|
168 |
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
|
335 |
benjamin |
169 |
collecterInfosRecherche();
|
420 |
gduche |
170 |
afficherRequeteEtLancerRechercheSimple();
|
322 |
gduche |
171 |
}
|
|
|
172 |
}
|
|
|
173 |
});
|
335 |
benjamin |
174 |
|
322 |
gduche |
175 |
vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
|
335 |
benjamin |
176 |
|
322 |
gduche |
177 |
@Override
|
|
|
178 |
public void onClick(ClickEvent event) {
|
420 |
gduche |
179 |
if (vue.getValeurRechercheSimple().equals(
|
|
|
180 |
vue.getLabelRecherche())) {
|
322 |
gduche |
181 |
vue.setValeurRechercheSimple("");
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
});
|
|
|
185 |
}
|
335 |
benjamin |
186 |
|
|
|
187 |
private void collecterInfosRecherche() {
|
|
|
188 |
InformationsRecherche informationRecherche = new InformationsRecherche();
|
420 |
gduche |
189 |
informationRecherche.setTaxon(autoCompletionNomTaxonsPresenteur.getValeur());
|
|
|
190 |
informationRecherche.setDepartement(vue.getDepartement().getText());
|
335 |
benjamin |
191 |
informationRecherche.setCommune(vue.getCommune().getText());
|
|
|
192 |
informationRecherche.setFamille(vue.getFamille().getText());
|
|
|
193 |
informationRecherche.setGenre(vue.getGenre().getText());
|
420 |
gduche |
194 |
informationRecherche.setTag(vue.getTag().getText());
|
335 |
benjamin |
195 |
informationRecherche.setMotClef(vue.getMotCle().getText());
|
420 |
gduche |
196 |
informationRecherche.setAuteur(vue.getAuteur().getText());
|
|
|
197 |
informationRecherche.setDate(vue.getDate().getText());
|
|
|
198 |
|
|
|
199 |
if (!vue.getRecherchePrincipale().getText()
|
|
|
200 |
.equals(vue.getLabelRecherche())) {
|
|
|
201 |
informationRecherche.setRechercheLibre(vue.getRecherchePrincipale()
|
|
|
202 |
.getText());
|
335 |
benjamin |
203 |
}
|
|
|
204 |
if (isPourRechercheImages()) {
|
420 |
gduche |
205 |
CacheClient.getInstance().setInformationsRechercheImage(
|
|
|
206 |
informationRecherche);
|
335 |
benjamin |
207 |
} else if (isPourRechercheObservations()) {
|
420 |
gduche |
208 |
CacheClient.getInstance().setInformationsRechercheObservation(
|
|
|
209 |
informationRecherche);
|
335 |
benjamin |
210 |
}
|
322 |
gduche |
211 |
}
|
335 |
benjamin |
212 |
|
|
|
213 |
private InformationsRecherche getInformationsRechercheEnCache() {
|
|
|
214 |
if (isPourRechercheImages()) {
|
|
|
215 |
return CacheClient.getInstance().getInformationsRechercheImage();
|
|
|
216 |
} else if (isPourRechercheObservations()) {
|
420 |
gduche |
217 |
return CacheClient.getInstance()
|
|
|
218 |
.getInformationsRechercheObservation();
|
335 |
benjamin |
219 |
}
|
|
|
220 |
return null;
|
|
|
221 |
}
|
|
|
222 |
|
420 |
gduche |
223 |
public void afficherRequeteEtLancerRechercheSimple() {
|
|
|
224 |
InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
|
|
|
225 |
if (informationsRecherche != null) {
|
|
|
226 |
vue.chargerValeursRechercheSimplePrecedente(informationsRecherche);
|
|
|
227 |
}
|
|
|
228 |
lancerRecherche();
|
|
|
229 |
}
|
|
|
230 |
|
335 |
benjamin |
231 |
public void afficherRequeteEtLancerRecherche() {
|
|
|
232 |
InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
|
|
|
233 |
if (informationsRecherche != null) {
|
420 |
gduche |
234 |
autoCompletionNomTaxonsPresenteur.setValeur(informationsRecherche.getTaxon());
|
335 |
benjamin |
235 |
vue.chargerValeursRecherchePrecedente(informationsRecherche);
|
|
|
236 |
}
|
|
|
237 |
lancerRecherche();
|
|
|
238 |
}
|
|
|
239 |
|
420 |
gduche |
240 |
public abstract void lancerRecherche();
|
335 |
benjamin |
241 |
|
|
|
242 |
public boolean isPourRechercheImages() {
|
|
|
243 |
return pourRechercheImages;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
public boolean isPourRechercheObservations() {
|
|
|
247 |
return pourRechercheObservations;
|
|
|
248 |
}
|
322 |
gduche |
249 |
}
|