Subversion Repositories eFlore/Applications.del

Rev

Rev 309 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 309 Rev 330
Line 2... Line 2...
2
 
2
 
3
import java.util.HashMap;
3
import java.util.HashMap;
4
import java.util.Iterator;
4
import java.util.Iterator;
Line -... Line 5...
-
 
5
import java.util.List;
-
 
6
 
5
import java.util.List;
7
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRecherchePresenteur;
6
 
8
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRechercheVue;
7
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
9
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
Line 8... Line 10...
8
import org.tela_botanica.del.client.modeles.Observation;
10
import org.tela_botanica.del.client.modeles.Observation;
Line 26... Line 28...
26
import com.google.gwt.user.client.ui.TextBox;
28
import com.google.gwt.user.client.ui.TextBox;
Line 27... Line 29...
27
 
29
 
Line 28... Line 30...
28
public class RechercheObservationsPresenteur extends Presenteur {
30
public class RechercheObservationsPresenteur extends Presenteur {
29
 
-
 
30
	public abstract interface Vue extends IsWidget {
-
 
31
		public HasClickHandlers getRecherchePrincipaleHasClickHandler();
-
 
32
		public HasKeyPressHandlers getRecherchePrincipaleHasKeyPressHandlers();
-
 
33
		public HasText getRecherchePrincipaleHasText();
-
 
34
		public HasText getDepartement();
-
 
35
		public HasText getCommune();
-
 
36
		public HasText getTaxon();
-
 
37
		public HasText getFamille();
-
 
38
		public HasText getGenre();
-
 
39
		public HasText getTag();
-
 
40
		public HasText getMotCle();
-
 
41
		public HasText getAuteur();
31
 
42
		public HasText getDate();
-
 
43
		public HasClickHandlers getBoutonRecherche();
-
 
44
		public HasClickHandlers getBoutonRechercheAvancee();
-
 
45
		public HasClickHandlers getLienRechercheAvancee();
-
 
46
		public HasText getRecherchePrecedente();
-
 
47
		public HasWidgets getRechercheAvanceeHasWidget();
32
	public abstract interface Vue extends IsWidget {
48
		public HasVisibility getRechercheAvanceeHasVisibility();
33
		public HasWidgets getZoneRecherche();
49
		public HasWidgets getZoneObservations();
34
		public HasWidgets getZoneObservations();
50
		public HasWidgets getZonePagination();
35
		public HasWidgets getZonePagination();
Line 60... Line 45...
60
	public void go(HasWidgets composite) {
45
	public void go(HasWidgets composite) {
61
		if (composite == null) {
46
		if (composite == null) {
62
			composite = RootPanel.get();
47
			composite = RootPanel.get();
63
		}
48
		}
64
		composite.add(vue.asWidget());
49
		composite.add(vue.asWidget());
-
 
50
		ajouterMoteurRechercheAvancee();
65
		gererEvenements();
51
		gererEvenements();
Line 66... Line 52...
66
 
52
 
67
		// On commence par afficher la totalité des observations
53
		// On commence par afficher la totalité des observations
68
		chercherObservations(null);
54
		chercherObservations(null);
69
		afficherObservations();
55
		afficherObservations();
70
	}
56
	}
71
 
57
	
72
	protected void gererEvenements() {
-
 
73
 
-
 
74
		// Gestion du clic dans la zone de saisie
-
 
75
		vue.getRecherchePrincipaleHasClickHandler().addClickHandler(new ClickHandler() {
-
 
76
 
-
 
77
			public void onClick(ClickEvent event) {
-
 
78
				HasText recherchePrincipale = (HasText) event.getSource();
58
	protected void ajouterMoteurRechercheAvancee() {
79
				if (recherchePrincipale.getText().equals("Recherche libre")) {
-
 
80
					recherchePrincipale.setText("");
-
 
81
				}
-
 
82
			}
-
 
83
		});
-
 
84
 
-
 
85
		// Gestion de l'affichage de la recherche Avancée
-
 
86
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
-
 
87
 
-
 
88
			public void onClick(ClickEvent event) {
-
 
89
				HasVisibility rechercheAvancee = vue.getRechercheAvanceeHasVisibility();
-
 
90
				rechercheAvancee.setVisible(!rechercheAvancee.isVisible());
-
 
91
			}
-
 
92
		});
59
		MoteurRecherchePresenteur presenteur = new MoteurRecherchePresenteur(new MoteurRechercheVue("Rechercher une observation"){}) {
93
 
-
 
94
		// Gestion de l'évènement recherche sur le clic ou sur l'appui de la
60
			
95
		// touche Entrée
-
 
96
		vue.getBoutonRecherche().addClickHandler(new ClickHandler() {
-
 
97
 
61
			@Override
98
			public void onClick(ClickEvent event) {
-
 
99
				chercherObservations(collecterFormulaire());
62
			public void lancerRecherche(String termeRecherche) {
100
				afficherObservations();
-
 
101
			}
-
 
102
		});
-
 
103
 
-
 
104
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
-
 
105
			public void onClick(ClickEvent event) {
-
 
106
				chercherObservations(collecterFormulaire());
63
				chercherObservations(null);
107
				afficherObservations();
64
				afficherObservations();
108
			}
65
			}
109
		});
-
 
110
 
-
 
111
		vue.getRecherchePrincipaleHasKeyPressHandlers().addKeyPressHandler(new KeyPressHandler() {
-
 
112
 
-
 
113
			public void onKeyPress(KeyPressEvent event) {
-
 
114
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
66
		};
115
					chercherObservations(collecterFormulaire());
-
 
116
					afficherObservations();
-
 
117
				}
-
 
118
			}
-
 
119
		});
67
		presenteur.go(vue.getZoneRecherche());
Line 120... Line -...
120
	}
-
 
121
 
-
 
122
	// Gestion de la recherche d'observations :
-
 
123
	public HashMap<String, String> collecterFormulaire() {
-
 
124
 
-
 
125
		HashMap<String, String> champsRecherche = new HashMap<String, String>();
-
 
126
 
-
 
127
		if (!vue.getRecherchePrincipaleHasText().getText().equals("")) {
-
 
128
			champsRecherche.put("search", vue.getRecherchePrincipaleHasText().getText());
-
 
129
		}
-
 
130
		if (!vue.getDepartement().getText().equals("")) {
-
 
131
			champsRecherche.put("dept", vue.getDepartement().getText());
-
 
132
		}
-
 
133
		if (!vue.getCommune().getText().equals("")) {
-
 
134
			champsRecherche.put("com", vue.getCommune().getText());
-
 
135
		}
-
 
136
		if (!vue.getTaxon().getText().equals("")) {
-
 
137
			champsRecherche.put("taxon", vue.getTaxon().getText());
-
 
138
		}
-
 
139
		if (!vue.getFamille().getText().equals("")) {
-
 
140
			champsRecherche.put("fam", vue.getFamille().getText());
-
 
141
		}
-
 
142
		if (!vue.getGenre().getText().equals("")) {
-
 
143
			champsRecherche.put("gen", vue.getGenre().getText());
68
	}
144
		}
-
 
145
		if (!vue.getTag().getText().equals("")) {
-
 
146
			champsRecherche.put("tag", vue.getTag().getText());
-
 
147
		}
-
 
148
		if (!vue.getMotCle().getText().equals("")) {
-
 
149
			champsRecherche.put("motCle", vue.getMotCle().getText());
-
 
150
		}
-
 
151
		if (!vue.getAuteur().getText().equals("")) {
-
 
152
			champsRecherche.put("auteur", vue.getAuteur().getText());
-
 
153
		}
-
 
154
		if (!vue.getDate().getText().equals("")) {
-
 
155
			champsRecherche.put("date", vue.getDate().getText());
-
 
156
		}
-
 
Line 157... Line 69...
157
		return champsRecherche;
69
 
158
	}
-
 
159
 
-
 
160
	public void chercherObservations(HashMap<String, String> champsRecherche) {
70
	protected void gererEvenements() {}
161
 
-
 
162
		vue.getRechercheAvanceeHasVisibility().setVisible(false);
71
 
Line 163... Line 72...
163
		this.observations = MockDatasource.getInstance().getObservations(champsRecherche);
72
	public void chercherObservations(HashMap<String, String> champsRecherche) {
164
		vue.getRecherchePrecedente().setText(getChaineRecherche(champsRecherche));
-
 
165
	}
73
		this.observations = MockDatasource.getInstance().getObservations(champsRecherche);
166
 
74
	}
167
	public void afficherObservations() {
75
 
168
 
76
	public void afficherObservations() {
169
		vue.getZoneObservations().clear();
77
		vue.getZoneObservations().clear();
170
		for (Observation observation : observations) {
78
		for (Observation observation : observations) {
Line 171... Line -...
171
			ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation);
-
 
172
			presenteur.go(vue.getZoneObservations());
-
 
173
		}
-
 
174
	}
-
 
175
 
-
 
176
	private String getChaineRecherche(HashMap<String, String> valeursRecherche) {
-
 
177
		String chaineRecherche = "";
-
 
178
		if (valeursRecherche != null) {
-
 
179
			Iterator<String> itCles = valeursRecherche.keySet().iterator();
-
 
180
			while (itCles.hasNext()) {
-
 
181
				String cle = itCles.next();
-
 
182
				String valeur = valeursRecherche.get(cle);
-
 
183
				if (valeur != "") {
-
 
184
					chaineRecherche += cle + ":=" + valeur + " ";
-
 
185
				}
79
			ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation);