Subversion Repositories eFlore/Applications.del

Rev

Rev 407 | Rev 420 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 407 Rev 408
1
package org.tela_botanica.del.client.composants.moteurrecherche;
1
package org.tela_botanica.del.client.composants.moteurrecherche;
2
 
2
 
3
import org.tela_botanica.del.client.cache.CacheClient;
3
import org.tela_botanica.del.client.cache.CacheClient;
4
import org.tela_botanica.del.client.composants.formulaires.AutoCompletionComboBoxPresenteur;
4
import org.tela_botanica.del.client.composants.formulaires.AutoCompletionComboBoxPresenteur;
5
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
5
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
6
import org.tela_botanica.del.client.modeles.InformationsRecherche;
6
import org.tela_botanica.del.client.modeles.InformationsRecherche;
7
import org.tela_botanica.del.client.services.UtilitairesAutoCompletionService;
7
import org.tela_botanica.del.client.services.UtilitairesAutoCompletionService;
8
 
8
 
9
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.event.dom.client.ClickEvent;
10
import com.google.gwt.event.dom.client.ClickHandler;
10
import com.google.gwt.event.dom.client.ClickHandler;
11
import com.google.gwt.event.dom.client.HasClickHandlers;
11
import com.google.gwt.event.dom.client.HasClickHandlers;
12
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
12
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
13
import com.google.gwt.event.dom.client.KeyCodes;
13
import com.google.gwt.event.dom.client.KeyCodes;
14
import com.google.gwt.event.dom.client.KeyPressEvent;
14
import com.google.gwt.event.dom.client.KeyPressEvent;
15
import com.google.gwt.event.dom.client.KeyPressHandler;
15
import com.google.gwt.event.dom.client.KeyPressHandler;
16
import com.google.gwt.http.client.Response;
16
import com.google.gwt.http.client.Response;
17
import com.google.gwt.json.client.JSONArray;
17
import com.google.gwt.json.client.JSONArray;
18
import com.google.gwt.json.client.JSONParser;
18
import com.google.gwt.json.client.JSONParser;
19
import com.google.gwt.json.client.JSONValue;
19
import com.google.gwt.json.client.JSONValue;
20
import com.google.gwt.user.client.ui.HasText;
20
import com.google.gwt.user.client.ui.HasText;
21
import com.google.gwt.user.client.ui.HasWidgets;
21
import com.google.gwt.user.client.ui.HasWidgets;
22
import com.google.gwt.user.client.ui.IsWidget;
22
import com.google.gwt.user.client.ui.IsWidget;
23
 
23
 
24
public abstract class MoteurRecherchePresenteur extends Presenteur {
24
public abstract class MoteurRecherchePresenteur extends Presenteur {
25
 
25
 
26
	public abstract interface Vue extends IsWidget {
26
	public abstract interface Vue extends IsWidget {
27
 
27
 
28
		public abstract HasClickHandlers getLienRechercheAvancee();
28
		public abstract HasClickHandlers getLienRechercheAvancee();
29
 
29
 
30
		public abstract void basculerAffichageZoneCache();
30
		public abstract void basculerAffichageZoneCache();
31
 
31
 
32
		public abstract HasClickHandlers getBoutonRechercheSimple();
32
		public abstract HasClickHandlers getBoutonRechercheSimple();
-
 
33
		
-
 
34
		public abstract HasClickHandlers getBoutonFermer();
33
 
35
 
34
		public abstract HasClickHandlers getBoutonRechercheAvancee();
36
		public abstract HasClickHandlers getBoutonRechercheAvancee();
35
 
37
 
36
		public abstract HasKeyPressHandlers getChampSaisie();
38
		public abstract HasKeyPressHandlers getChampSaisie();
37
 
39
 
38
		public abstract HasClickHandlers getChampSaisieCliquable();
40
		public abstract HasClickHandlers getChampSaisieCliquable();
39
 
41
 
40
		public abstract String getValeurRechercheSimple();
42
		public abstract String getValeurRechercheSimple();
41
 
43
 
42
		public void setValeurRechercheSimple(String valeurRecherche);
44
		public void setValeurRechercheSimple(String valeurRecherche);
43
 
45
 
44
		public String getLabelRecherche();
46
		public String getLabelRecherche();
45
 
47
 
46
		public HasText getRecherchePrincipale();
48
		public HasText getRecherchePrincipale();
47
 
49
 
48
		public HasText getDepartement();
50
		public HasText getDepartement();
49
 
51
 
50
		public HasText getCommune();
52
		public HasText getCommune();
51
 
53
 
52
		public HasWidgets getTaxon();
54
		public HasWidgets getTaxon();
53
 
55
 
54
		public HasText getFamille();
56
		public HasText getFamille();
55
 
57
 
56
		public HasText getGenre();
58
		public HasText getGenre();
57
 
59
 
58
		public HasText getTag();
60
		public HasText getTag();
59
 
61
 
60
		public HasText getMotCle();
62
		public HasText getMotCle();
61
 
63
 
62
		public HasText getAuteur();
64
		public HasText getAuteur();
63
 
65
 
64
		public HasText getDate();
66
		public HasText getDate();
65
 
67
 
66
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
68
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
67
		
69
		
68
		public void focusSaisie();
70
		public void focusSaisie();
69
	}
71
	}
70
 
72
 
71
	private final Vue vue;
73
	private final Vue vue;
72
	private final boolean pourRechercheImages, pourRechercheObservations;
74
	private final boolean pourRechercheImages, pourRechercheObservations;
73
	
75
	
74
	private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
76
	private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
75
 
77
 
76
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) {
78
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) {
77
		this.vue = vue;
79
		this.vue = vue;
78
		this.pourRechercheImages = pourRechercheImages;
80
		this.pourRechercheImages = pourRechercheImages;
79
		this.pourRechercheObservations = pourRechercheObservations;
81
		this.pourRechercheObservations = pourRechercheObservations;
80
		
82
		
81
		autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(UtilitairesAutoCompletionService.urlServiceCompletionNomLocale) {	
83
		autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(UtilitairesAutoCompletionService.urlServiceCompletionNomLocale) {	
82
			
84
			
83
			protected String effectuerPreTraitementChaineRequete(String requete) {
85
			protected String effectuerPreTraitementChaineRequete(String requete) {
84
				return UtilitairesAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
86
				return UtilitairesAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
85
				// A décommenter lors de l'utilisation des web services eflore
87
				// A décommenter lors de l'utilisation des web services eflore
86
				//return RetourAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceEflore(requete);
88
				//return RetourAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceEflore(requete);
87
			}
89
			}
88
			
90
			
89
			@Override
91
			@Override
90
			protected String[] parserResultatRequete(Response response) {
92
			protected String[] parserResultatRequete(Response response) {
91
				return UtilitairesAutoCompletionService.parserRetourSimple(response);
93
				return UtilitairesAutoCompletionService.parserRetourSimple(response);
92
				// A décommenter lors de l'utilisation des web services eflore
94
				// A décommenter lors de l'utilisation des web services eflore
93
				//return RetourAutoCompletionService.parserRetourOss(response);
95
				//return RetourAutoCompletionService.parserRetourOss(response);
94
			}
96
			}
95
		};	
97
		};	
96
		gererEvenements();
98
		gererEvenements();
97
	}
99
	}
98
 
100
 
99
	@Override
101
	@Override
100
	public void go(HasWidgets composite) {
102
	public void go(HasWidgets composite) {
101
		afficherRequeteEtLancerRecherche();
103
		afficherRequeteEtLancerRecherche();
102
		autoCompletionNomTaxonsPresenteur.go(vue.getTaxon());
104
		autoCompletionNomTaxonsPresenteur.go(vue.getTaxon());
103
		composite.add(vue.asWidget());
105
		composite.add(vue.asWidget());
104
		vue.focusSaisie();
106
		vue.focusSaisie();
105
	}
107
	}
106
 
108
 
107
	@Override
109
	@Override
108
	protected void gererEvenements() {
110
	protected void gererEvenements() {
109
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
111
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
110
			public void onClick(ClickEvent event) {
112
			public void onClick(ClickEvent event) {
111
				vue.basculerAffichageZoneCache();
113
				vue.basculerAffichageZoneCache();
112
			}
114
			}
113
		});
115
		});
114
 
116
 
115
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
117
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
116
			public void onClick(ClickEvent event) {
118
			public void onClick(ClickEvent event) {
117
				collecterInfosRecherche();
119
				collecterInfosRecherche();
118
				afficherRequeteEtLancerRecherche();
120
				afficherRequeteEtLancerRecherche();
119
			}
121
			}
120
		});
122
		});
-
 
123
 
-
 
124
		vue.getBoutonFermer().addClickHandler(new ClickHandler() {
-
 
125
			
-
 
126
			@Override
-
 
127
			public void onClick(ClickEvent event) {
-
 
128
				vue.basculerAffichageZoneCache();
-
 
129
			}
121
 
130
		});
122
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
131
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
123
			public void onClick(ClickEvent event) {
132
			public void onClick(ClickEvent event) {
124
				collecterInfosRecherche();
133
				collecterInfosRecherche();
125
				vue.basculerAffichageZoneCache();
134
				vue.basculerAffichageZoneCache();
126
				afficherRequeteEtLancerRecherche();
135
				afficherRequeteEtLancerRecherche();
127
			}
136
			}
128
		});
137
		});
129
 
138
 
130
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
139
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
131
 
140
 
132
			public void onKeyPress(KeyPressEvent event) {
141
			public void onKeyPress(KeyPressEvent event) {
133
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
142
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
134
					collecterInfosRecherche();
143
					collecterInfosRecherche();
135
					afficherRequeteEtLancerRecherche();
144
					afficherRequeteEtLancerRecherche();
136
				}
145
				}
137
			}
146
			}
138
		});
147
		});
139
 
148
 
140
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
149
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
141
 
150
 
142
			@Override
151
			@Override
143
			public void onClick(ClickEvent event) {
152
			public void onClick(ClickEvent event) {
144
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
153
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
145
					vue.setValeurRechercheSimple("");
154
					vue.setValeurRechercheSimple("");
146
				}
155
				}
147
			}
156
			}
148
		});
157
		});
149
	}
158
	}
150
 
159
 
151
	private void collecterInfosRecherche() {
160
	private void collecterInfosRecherche() {
152
		InformationsRecherche informationRecherche = new InformationsRecherche();
161
		InformationsRecherche informationRecherche = new InformationsRecherche();
153
		informationRecherche.setAuteur(vue.getAuteur().getText());
162
		informationRecherche.setAuteur(vue.getAuteur().getText());
154
		informationRecherche.setCommune(vue.getCommune().getText());
163
		informationRecherche.setCommune(vue.getCommune().getText());
155
		informationRecherche.setDate(vue.getDate().getText());
164
		informationRecherche.setDate(vue.getDate().getText());
156
		informationRecherche.setDepartement(vue.getDepartement().getText());
165
		informationRecherche.setDepartement(vue.getDepartement().getText());
157
		informationRecherche.setFamille(vue.getFamille().getText());
166
		informationRecherche.setFamille(vue.getFamille().getText());
158
		informationRecherche.setGenre(vue.getGenre().getText());
167
		informationRecherche.setGenre(vue.getGenre().getText());
159
		informationRecherche.setMotClef(vue.getMotCle().getText());
168
		informationRecherche.setMotClef(vue.getMotCle().getText());
160
 
169
 
161
		if (!vue.getRecherchePrincipale().getText().equals(vue.getLabelRecherche())) {
170
		if (!vue.getRecherchePrincipale().getText().equals(vue.getLabelRecherche())) {
162
			informationRecherche.setRechercheLibre(vue.getRecherchePrincipale().getText());
171
			informationRecherche.setRechercheLibre(vue.getRecherchePrincipale().getText());
163
		}
172
		}
164
		if (isPourRechercheImages()) {
173
		if (isPourRechercheImages()) {
165
			CacheClient.getInstance().setInformationsRechercheImage(informationRecherche);
174
			CacheClient.getInstance().setInformationsRechercheImage(informationRecherche);
166
		} else if (isPourRechercheObservations()) {
175
		} else if (isPourRechercheObservations()) {
167
			CacheClient.getInstance().setInformationsRechercheObservation(informationRecherche);
176
			CacheClient.getInstance().setInformationsRechercheObservation(informationRecherche);
168
		}
177
		}
169
	}
178
	}
170
 
179
 
171
	private InformationsRecherche getInformationsRechercheEnCache() {
180
	private InformationsRecherche getInformationsRechercheEnCache() {
172
		if (isPourRechercheImages()) {
181
		if (isPourRechercheImages()) {
173
			return CacheClient.getInstance().getInformationsRechercheImage();
182
			return CacheClient.getInstance().getInformationsRechercheImage();
174
		} else if (isPourRechercheObservations()) {
183
		} else if (isPourRechercheObservations()) {
175
			return CacheClient.getInstance().getInformationsRechercheObservation();
184
			return CacheClient.getInstance().getInformationsRechercheObservation();
176
		}
185
		}
177
		return null;
186
		return null;
178
	}
187
	}
179
 
188
 
180
	public void afficherRequeteEtLancerRecherche() {
189
	public void afficherRequeteEtLancerRecherche() {
181
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
190
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
182
		if (informationsRecherche != null) {
191
		if (informationsRecherche != null) {
183
			vue.chargerValeursRecherchePrecedente(informationsRecherche);
192
			vue.chargerValeursRecherchePrecedente(informationsRecherche);
184
		}
193
		}
185
		lancerRecherche();
194
		lancerRecherche();
186
	}
195
	}
187
 
196
 
188
	public abstract void lancerRecherche();
197
	public abstract void lancerRecherche();
189
 
198
 
190
	public boolean isPourRechercheImages() {
199
	public boolean isPourRechercheImages() {
191
		return pourRechercheImages;
200
		return pourRechercheImages;
192
	}
201
	}
193
 
202
 
194
	public boolean isPourRechercheObservations() {
203
	public boolean isPourRechercheObservations() {
195
		return pourRechercheObservations;
204
		return pourRechercheObservations;
196
	}
205
	}
197
}
206
}