Subversion Repositories eFlore/Applications.del

Rev

Rev 1995 | Rev 2171 | 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
 
1367 aurelien 3
import java.util.Iterator;
4
import java.util.Map;
5
 
335 benjamin 6
import org.tela_botanica.del.client.i18n.I18n;
7
import org.tela_botanica.del.client.modeles.InformationsRecherche;
322 gduche 8
 
9
import com.google.gwt.core.client.GWT;
10
import com.google.gwt.event.dom.client.HasClickHandlers;
11
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
12
import com.google.gwt.uibinder.client.UiBinder;
13
import com.google.gwt.uibinder.client.UiField;
1367 aurelien 14
import com.google.gwt.user.client.DOM;
322 gduche 15
import com.google.gwt.user.client.ui.Button;
16
import com.google.gwt.user.client.ui.Composite;
2140 mathias 17
import com.google.gwt.user.client.ui.CheckBox;
386 aurelien 18
import com.google.gwt.user.client.ui.HasWidgets;
322 gduche 19
import com.google.gwt.user.client.ui.Label;
1367 aurelien 20
import com.google.gwt.user.client.ui.ListBox;
322 gduche 21
import com.google.gwt.user.client.ui.Panel;
22
import com.google.gwt.user.client.ui.TextBox;
23
import com.google.gwt.user.client.ui.Widget;
24
 
25
public class MoteurRechercheVue extends Composite implements MoteurRecherchePresenteur.Vue {
26
 
564 benjamin 27
	interface Binder extends UiBinder<Widget, MoteurRechercheVue> {
28
	}
335 benjamin 29
 
322 gduche 30
	private static Binder uiBinder = GWT.create(Binder.class);
31
	private String labelRecherche = "";
1986 aurelien 32
 
33
	private Map<String,String> listePays;
34
 
35
	private InformationsRecherche informationRecherche;
36
 
37
	// Si l'on charge une recherche précédente et que la liste des pays n'est
38
	// pas encore arrivée, on stocke le pays pour l'afficher quand la liste arrive
39
	private String paysEnAttente;
335 benjamin 40
 
41
	@UiField
1426 aurelien 42
	Panel rechercheAvancee, taxon, commune, zoneRss, conteneurMotCle, conteneurMotCleCel, conteneurMotCleDel  ;
335 benjamin 43
	@UiField
2140 mathias 44
	Label lienRechercheAvancee, recherchePrecedente, labelPnInscritsSeulement;
335 benjamin 45
	@UiField
419 gduche 46
	Button boutonRecherche, boutonRechercheAvancee, boutonFermer, boutonVider;
335 benjamin 47
	@UiField
1426 aurelien 48
	TextBox recherchePrincipale, contientMots, departement, famille, genre, motCle, motCleCel, motCleDel, auteur, date;
1367 aurelien 49
	@UiField
1986 aurelien 50
	ListBox referentiel, pays;
2140 mathias 51
	@UiField
52
	CheckBox casePnInscritsSeulement;
335 benjamin 53
 
322 gduche 54
	public MoteurRechercheVue(String labelRecherche) {
55
		initWidget(uiBinder.createAndBindUi(this));
56
		this.labelRecherche = labelRecherche;
57
		recherchePrincipale.setText(labelRecherche);
58
		rechercheAvancee.setVisible(false);
59
	}
1367 aurelien 60
 
61
	@Override
62
	public void remplirListeReferentiels(Map<String, String> listeReferentiels) {
63
		for (Iterator<String> iterator = listeReferentiels.keySet().iterator(); iterator.hasNext();) {
64
			String codeRef = iterator.next();
65
			referentiel.addItem(listeReferentiels.get(codeRef), codeRef);
66
		}
1792 mathias 67
		referentiel.setItemSelected(1, true);
1367 aurelien 68
	}
1986 aurelien 69
 
70
	@Override
71
	public void remplirListePays(Map<String, String> listePays) {
72
		this.listePays = listePays;
73
		pays.clear();
74
		// Pour pouvoir annuler la selection de pays, on ajoute un item vide
75
		pays.addItem("", "");
76
		int index = 1;
77
		for (Iterator<String> iterator = listePays.keySet().iterator(); iterator.hasNext();) {
78
			String codePays = iterator.next();
79
			pays.addItem(listePays.get(codePays), codePays);
80
 
81
			if(paysEnAttente != null && codePays.equals(paysEnAttente)) {
82
				pays.setItemSelected(index, true);
83
			}
84
			index++;
85
		}
86
 
87
		if(paysEnAttente != null) {
88
			afficherLigneInfoRecherche(informationRecherche);
89
		}
90
		paysEnAttente = null;
91
	}
322 gduche 92
 
93
	public String getLabelRecherche() {
94
		return labelRecherche;
95
	}
335 benjamin 96
 
322 gduche 97
	public HasClickHandlers getLienRechercheAvancee() {
98
		return lienRechercheAvancee;
99
	}
100
 
101
	public HasClickHandlers getBoutonRechercheSimple() {
102
		return boutonRecherche;
103
	}
445 benjamin 104
 
408 gduche 105
	public HasClickHandlers getBoutonFermer() {
106
		return boutonFermer;
107
	}
445 benjamin 108
 
419 gduche 109
	public HasClickHandlers getBoutonVider() {
110
		return boutonVider;
111
	}
335 benjamin 112
 
322 gduche 113
	public HasClickHandlers getBoutonRechercheAvancee() {
114
		return boutonRechercheAvancee;
115
	}
116
 
117
	public HasKeyPressHandlers getChampSaisie() {
118
		return recherchePrincipale;
119
	}
120
 
121
	public String getValeurRechercheSimple() {
122
		return recherchePrincipale.getText();
123
	}
564 benjamin 124
 
545 jpm 125
	public void setValeurRechercheSimple(String valeurRecherche) {
126
		recherchePrincipale.setText(valeurRecherche);
533 jpm 127
	}
564 benjamin 128
 
322 gduche 129
	public HasClickHandlers getChampSaisieCliquable() {
130
		return recherchePrincipale;
131
	}
564 benjamin 132
 
545 jpm 133
	public String getContientMots() {
134
		return contientMots.getText();
135
	}
335 benjamin 136
 
533 jpm 137
	public void setContientMots(String mots) {
138
		contientMots.setText(mots);
139
	}
2140 mathias 140
 
141
	public boolean getPnInscritsSeulement() {
142
		return casePnInscritsSeulement.getValue();
143
	}
144
 
145
	public void setPnInscritsSeulement(boolean valeur) {
146
		casePnInscritsSeulement.setValue(valeur);
147
	}
1986 aurelien 148
 
149
	public String getPays() {
150
		return pays.getValue(pays.getSelectedIndex());
151
	}
564 benjamin 152
 
545 jpm 153
	public String getDepartement() {
154
		return departement.getText();
155
	}
156
 
457 aurelien 157
	public void setValeurDepartement(String dpt) {
158
		departement.setValue(dpt);
159
	}
545 jpm 160
 
161
	public HasWidgets getCommune() {
162
		return commune;
163
	}
164
 
165
	public HasWidgets getTaxon() {
166
		return taxon;
167
	}
168
 
169
	public String getFamille() {
170
		return famille.getText();
171
	}
172
 
173
	public String getGenre() {
174
		return genre.getText();
175
	}
176
 
177
	public String getMotCle() {
178
		return motCle.getText();
179
	}
180
 
181
	public String getAuteur() {
182
		return auteur.getText();
183
	}
184
 
185
	public String getDate() {
186
		return date.getText();
187
	}
1367 aurelien 188
 
189
	public String getReferentiel() {
190
		return referentiel.getValue(referentiel.getSelectedIndex());
191
	}
564 benjamin 192
 
545 jpm 193
	public void focusSaisie() {
194
		this.recherchePrincipale.setFocus(true);
195
	}
322 gduche 196
 
545 jpm 197
	public void ajouterVue(HasWidgets composite) {
198
		composite.add(this.asWidget());
199
	}
564 benjamin 200
 
545 jpm 201
	public void basculerAffichageZoneCache() {
202
		rechercheAvancee.setVisible(!rechercheAvancee.isVisible());
203
		recherchePrincipale.setVisible(!recherchePrincipale.isVisible());
204
		boutonRecherche.setVisible(!boutonRecherche.isVisible());
205
	}
564 benjamin 206
 
545 jpm 207
	public void nettoyer() {
1995 aurelien 208
		pays.setSelectedIndex(0);
545 jpm 209
		chargerValeursRecherchePrecedente(new InformationsRecherche());
210
	}
564 benjamin 211
 
335 benjamin 212
	public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche) {
451 aurelien 213
		recherchePrincipale.setText(informationsRecherche.getRechercheLibre());
533 jpm 214
		contientMots.setText(informationsRecherche.getRechercheLibre());
451 aurelien 215
		departement.setText(informationsRecherche.getDepartement());
216
		famille.setText(informationsRecherche.getFamille());
217
		genre.setText(informationsRecherche.getGenre());
218
		motCle.setText(informationsRecherche.getMotClef());
1426 aurelien 219
		motCleCel.setText(informationsRecherche.getMotClefCel());
220
		motCleDel.setText(informationsRecherche.getMotClefDel());
451 aurelien 221
		auteur.setText(informationsRecherche.getAuteur());
222
		date.setText(informationsRecherche.getDate());
2140 mathias 223
		casePnInscritsSeulement.setValue(informationsRecherche.getPnInscritsSeulement());
1367 aurelien 224
 
225
		for(int i = 0; i < referentiel.getItemCount(); i++) {
226
			if(referentiel.getValue(i).equals(informationsRecherche.getReferentiel())) {
227
				referentiel.setSelectedIndex(i);
228
			}
229
		}
1986 aurelien 230
 
231
		// la liste des pays du champs de recherche est asynchrone
232
		// donc elle peut ne pas avoir encore été chargée
233
		if(listePays != null) {
234
			for(int i = 0; i < pays.getItemCount(); i++) {
235
				if(pays.getValue(i).equals(paysEnAttente)) {
236
					pays.setSelectedIndex(i);
237
				}
238
			}
239
		} else {
240
			paysEnAttente = informationsRecherche.getPays();
241
		}
445 benjamin 242
 
335 benjamin 243
		afficherLigneInfoRecherche(informationsRecherche);
244
	}
245
 
246
	/**
247
	 * Affiche la ligne d'en tête montrant les elements de la requête à
248
	 * l'utilisateur
249
	 *
250
	 * @param informationRecherche
251
	 */
252
	private void afficherLigneInfoRecherche(InformationsRecherche informationRecherche) {
1986 aurelien 253
 
254
		this.informationRecherche = informationRecherche;
255
 
445 benjamin 256
		// tax dep com fam gen ta mo au date
335 benjamin 257
		StringBuffer texteRecherchePrecedente = new StringBuffer();
445 benjamin 258
 
259
		if (informationRecherche.getRechercheLibre() != null && !informationRecherche.getRechercheLibre().equals("")) {
335 benjamin 260
			texteRecherchePrecedente.append(I18n.getVocabulary().rechercheLibre() + ":" + informationRecherche.getRechercheLibre() + " ");
322 gduche 261
		}
445 benjamin 262
		if (informationRecherche.getTaxon() != null && !informationRecherche.getTaxon().equals("")) {
419 gduche 263
			texteRecherchePrecedente.append(I18n.getVocabulary().taxon() + ":" + informationRecherche.getTaxon() + " ");
322 gduche 264
		}
445 benjamin 265
		if (informationRecherche.getDepartement() != null && !informationRecherche.getDepartement().equals("")) {
419 gduche 266
			texteRecherchePrecedente.append(I18n.getVocabulary().departement() + ":" + informationRecherche.getDepartement() + " ");
267
		}
1986 aurelien 268
		if (listePays != null && informationRecherche.getPays() != null && !informationRecherche.getPays().equals("")) {
269
			texteRecherchePrecedente.append(I18n.getVocabulary().pays() + ":" + listePays.get(informationRecherche.getPays()) + " ");
270
		}
445 benjamin 271
		if (informationRecherche.getCommune() != null && !informationRecherche.getCommune().equals("")) {
335 benjamin 272
			texteRecherchePrecedente.append(I18n.getVocabulary().commune() + ":" + informationRecherche.getCommune() + " ");
322 gduche 273
		}
445 benjamin 274
		if (informationRecherche.getFamille() != null && !informationRecherche.getFamille().equals("")) {
335 benjamin 275
			texteRecherchePrecedente.append(I18n.getVocabulary().famille() + ":" + informationRecherche.getFamille() + " ");
322 gduche 276
		}
445 benjamin 277
		if (informationRecherche.getGenre() != null && !informationRecherche.getGenre().equals("")) {
335 benjamin 278
			texteRecherchePrecedente.append(I18n.getVocabulary().genre() + ":" + informationRecherche.getGenre() + " ");
322 gduche 279
		}
445 benjamin 280
		if (informationRecherche.getTag() != null && !informationRecherche.getTag().equals("")) {
419 gduche 281
			texteRecherchePrecedente.append(I18n.getVocabulary().tag() + ":" + informationRecherche.getTag() + " ");
282
		}
445 benjamin 283
		if (informationRecherche.getMotClef() != null && !informationRecherche.getMotClef().equals("")) {
335 benjamin 284
			texteRecherchePrecedente.append(I18n.getVocabulary().mot_clef() + ":" + informationRecherche.getMotClef() + " ");
322 gduche 285
		}
1426 aurelien 286
		if (informationRecherche.getMotClefCel() != null && !informationRecherche.getMotClefCel().equals("")) {
287
			texteRecherchePrecedente.append(I18n.getVocabulary().tagCel() + ":" + informationRecherche.getMotClefCel() + " ");
288
		}
289
		if (informationRecherche.getMotClefDel() != null && !informationRecherche.getMotClefDel().equals("")) {
290
			texteRecherchePrecedente.append(I18n.getVocabulary().tagDel() + ":" + informationRecherche.getMotClefDel() + " ");
291
		}
445 benjamin 292
		if (informationRecherche.getAuteur() != null && !informationRecherche.getAuteur().equals("")) {
419 gduche 293
			texteRecherchePrecedente.append(I18n.getVocabulary().auteur() + ":" + informationRecherche.getAuteur() + " ");
294
		}
445 benjamin 295
		if (informationRecherche.getDate() != null && !informationRecherche.getDate().equals("")) {
419 gduche 296
			texteRecherchePrecedente.append(I18n.getVocabulary().date() + ":" + informationRecherche.getDate() + " ");
297
		}
1367 aurelien 298
		if (informationRecherche.getReferentiel() != null && !informationRecherche.getReferentiel().equals("")) {
299
			texteRecherchePrecedente.append(I18n.getVocabulary().referentiel() + ":" + informationRecherche.getReferentiel() + " ");
300
		}
2140 mathias 301
		if (informationRecherche.getPnInscritsSeulement()) {
302
			texteRecherchePrecedente.append(I18n.getVocabulary().pnISCourt() + ":non");
303
		}
1986 aurelien 304
 
335 benjamin 305
		recherchePrecedente.setText(texteRecherchePrecedente.toString());
322 gduche 306
	}
564 benjamin 307
 
308
	@Override
309
	public HasKeyPressHandlers getChampsFamille() {
310
		return famille;
311
	}
312
 
313
	@Override
314
	public HasKeyPressHandlers getChampsGenre() {
315
		return genre;
316
	}
317
 
318
	@Override
319
	public HasKeyPressHandlers getChampsMotCle() {
320
		return motCle;
321
	}
322
 
323
	@Override
324
	public HasKeyPressHandlers getChampsAuteur() {
325
		return auteur;
326
	}
327
 
328
	@Override
329
	public HasKeyPressHandlers getChampsDate() {
330
		return date;
331
	}
671 aurelien 332
 
333
	@Override
334
	public HasKeyPressHandlers getChampsDepartement() {
335
		return departement;
336
	}
337
 
338
	@Override
339
	public HasKeyPressHandlers getChampsContientMots() {
340
		return contientMots;
341
	}
1120 gduche 342
 
343
	public HasWidgets getZoneRss() {
344
		return zoneRss;
345
	}
1367 aurelien 346
 
347
	@Override
348
	public void setReferentielLectureSeule(boolean lectureSeule) {
1792 mathias 349
		// la listbox ne possède aucun méthode directe pour être désactivée
1367 aurelien 350
		DOM.setElementProperty(referentiel.getElement(), "disabled", "disabled");
351
	}
1426 aurelien 352
 
353
	@Override
354
	public HasKeyPressHandlers getChampsMotCleDel() {
355
		return motCleDel;
356
	}
357
 
358
	@Override
359
	public HasKeyPressHandlers getChampsMotCleCel() {
360
		return motCleCel;
361
	}
362
 
363
	@Override
364
	public String getMotCleDel() {
365
		return motCleDel.getText();
366
	}
367
 
368
	@Override
369
	public String getMotCleCel() {
370
		return motCleCel.getText();
371
	}
372
 
373
	@Override
374
	public void cacherChampsTagsImage() {
375
		conteneurMotCleCel.setVisible(false);
376
		conteneurMotCleDel.setVisible(false);
377
	}
378
 
379
	@Override
380
	public void cacherChampsTagsObs() {
381
		conteneurMotCle.setVisible(false);
382
	}
545 jpm 383
}