Subversion Repositories eFlore/Applications.del

Rev

Rev 335 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
322 gduche 1
package org.tela_botanica.del.client.composants.moteurrecherche;
2
 
3
import java.util.HashMap;
4
import java.util.Iterator;
5
 
6
import com.google.gwt.core.client.GWT;
7
import com.google.gwt.event.dom.client.HasClickHandlers;
8
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
9
import com.google.gwt.uibinder.client.UiBinder;
10
import com.google.gwt.uibinder.client.UiField;
11
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.ui.Button;
13
import com.google.gwt.user.client.ui.Composite;
14
import com.google.gwt.user.client.ui.IsWidget;
15
import com.google.gwt.user.client.ui.Label;
16
import com.google.gwt.user.client.ui.Panel;
17
import com.google.gwt.user.client.ui.TextBox;
18
import com.google.gwt.user.client.ui.Widget;
19
 
20
public class MoteurRechercheVue extends Composite implements MoteurRecherchePresenteur.Vue {
21
 
22
	interface Binder extends UiBinder<Widget, MoteurRechercheVue> {}
23
	private static Binder uiBinder = GWT.create(Binder.class);
24
	private String labelRecherche = "";
25
 
26
	@UiField Panel rechercheAvancee;
27
	@UiField Label lienRechercheAvancee, recherchePrecedente;
28
	@UiField Button boutonRecherche, boutonRechercheAvancee;
29
	@UiField TextBox recherchePrincipale, departement, commune, taxon, famille, genre, tag, motCle, auteur, date;
30
 
31
	public MoteurRechercheVue(String labelRecherche) {
32
		initWidget(uiBinder.createAndBindUi(this));
33
		this.labelRecherche = labelRecherche;
34
		recherchePrincipale.setText(labelRecherche);
35
		rechercheAvancee.setVisible(false);
36
	}
37
 
38
	public String getLabelRecherche() {
39
		return labelRecherche;
40
	}
41
 
42
	@Override
43
	public HasClickHandlers getLienRechercheAvancee() {
44
		return lienRechercheAvancee;
45
	}
46
 
47
	@Override
48
	public void basculerAffichageZoneCache() {
49
		rechercheAvancee.setVisible(!rechercheAvancee.isVisible());
50
	}
51
 
52
	@Override
53
	public HasClickHandlers getBoutonRechercheSimple() {
54
		return boutonRecherche;
55
	}
56
 
57
	@Override
58
	public HasClickHandlers getBoutonRechercheAvancee() {
59
		return boutonRechercheAvancee;
60
	}
61
 
62
	@Override
63
	public HasKeyPressHandlers getChampSaisie() {
64
		return recherchePrincipale;
65
	}
66
 
67
	@Override
68
	public String getValeurRechercheSimple() {
69
		return recherchePrincipale.getText();
70
	}
71
 
72
	@Override
73
	public HasClickHandlers getChampSaisieCliquable() {
74
		return recherchePrincipale;
75
	}
76
 
77
	@Override
78
	public void setValeurRechercheSimple(String valeurRecherche) {
79
		recherchePrincipale.setText(valeurRecherche);
80
	}
81
 
82
	@Override
83
	public HashMap<String, String> collecterFormulaire() {
84
 
85
		HashMap<String, String> champsRecherche = new HashMap<String, String>();
86
		if (!recherchePrincipale.getText().equals("")) {
87
			champsRecherche.put("search", recherchePrincipale.getText());
88
		}
89
 
90
		if (!departement.getText().equals("")) {
91
			champsRecherche.put("dept", departement.getText());
92
		}
93
		if (!commune.getText().equals("")) {
94
			champsRecherche.put("com", commune.getText());
95
		}
96
		if (!taxon.getText().equals("")) {
97
			champsRecherche.put("taxon", taxon.getText());
98
		}
99
		if (!famille.getText().equals("")) {
100
			champsRecherche.put("fam", famille.getText());
101
		}
102
		if (!genre.getText().equals("")) {
103
			champsRecherche.put("gen", genre.getText());
104
		}
105
		if (!tag.getText().equals("")) {
106
			champsRecherche.put("tag", tag.getText());
107
		}
108
		if (!motCle.getText().equals("")) {
109
			champsRecherche.put("motCle", motCle.getText());
110
		}
111
		if (!auteur.getText().equals("")) {
112
			champsRecherche.put("auteur", auteur.getText());
113
		}
114
		if (!date.getText().equals("")) {
115
			champsRecherche.put("date", date.getText());
116
		}
117
 
118
		return champsRecherche;
119
	}
120
 
121
	@Override
122
	public String getChaineRecherche() {
123
		HashMap<String, String> valeursRecherche = collecterFormulaire();
124
		String chaineRecherche = "";
125
		if (valeursRecherche != null) {
126
			Iterator<String> itCles = valeursRecherche.keySet().iterator();
127
			while (itCles.hasNext()) {
128
				String cle = itCles.next();
129
				String valeur = valeursRecherche.get(cle);
130
				if (valeur != "") {
131
					chaineRecherche += cle + ":=" + valeur + " ";
132
				}
133
			}
134
		}
135
		return chaineRecherche;
136
	}
137
 
138
	@Override
139
	public void setRecherchePrecedente() {
140
		recherchePrecedente.setText(getChaineRecherche());
141
	}
142
}