Subversion Repositories eFlore/Applications.del

Rev

Rev 386 | Rev 408 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 386 Rev 407
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
 
33
 
34
		public abstract HasClickHandlers getBoutonRechercheAvancee();
34
		public abstract HasClickHandlers getBoutonRechercheAvancee();
35
 
35
 
36
		public abstract HasKeyPressHandlers getChampSaisie();
36
		public abstract HasKeyPressHandlers getChampSaisie();
37
 
37
 
38
		public abstract HasClickHandlers getChampSaisieCliquable();
38
		public abstract HasClickHandlers getChampSaisieCliquable();
39
 
39
 
40
		public abstract String getValeurRechercheSimple();
40
		public abstract String getValeurRechercheSimple();
41
 
41
 
42
		public void setValeurRechercheSimple(String valeurRecherche);
42
		public void setValeurRechercheSimple(String valeurRecherche);
43
 
43
 
44
		public String getLabelRecherche();
44
		public String getLabelRecherche();
45
 
45
 
46
		public HasText getRecherchePrincipale();
46
		public HasText getRecherchePrincipale();
47
 
47
 
48
		public HasText getDepartement();
48
		public HasText getDepartement();
49
 
49
 
50
		public HasText getCommune();
50
		public HasText getCommune();
51
 
51
 
52
		public HasWidgets getTaxon();
52
		public HasWidgets getTaxon();
53
 
53
 
54
		public HasText getFamille();
54
		public HasText getFamille();
55
 
55
 
56
		public HasText getGenre();
56
		public HasText getGenre();
57
 
57
 
58
		public HasText getTag();
58
		public HasText getTag();
59
 
59
 
60
		public HasText getMotCle();
60
		public HasText getMotCle();
61
 
61
 
62
		public HasText getAuteur();
62
		public HasText getAuteur();
63
 
63
 
64
		public HasText getDate();
64
		public HasText getDate();
65
 
65
 
66
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
66
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
-
 
67
		
-
 
68
		public void focusSaisie();
67
	}
69
	}
68
 
70
 
69
	private final Vue vue;
71
	private final Vue vue;
70
	private final boolean pourRechercheImages, pourRechercheObservations;
72
	private final boolean pourRechercheImages, pourRechercheObservations;
71
	
73
	
72
	private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
74
	private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
73
 
75
 
74
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) {
76
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) {
75
		this.vue = vue;
77
		this.vue = vue;
76
		this.pourRechercheImages = pourRechercheImages;
78
		this.pourRechercheImages = pourRechercheImages;
77
		this.pourRechercheObservations = pourRechercheObservations;
79
		this.pourRechercheObservations = pourRechercheObservations;
78
		
80
		
79
		autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(UtilitairesAutoCompletionService.urlServiceCompletionNomLocale) {	
81
		autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(UtilitairesAutoCompletionService.urlServiceCompletionNomLocale) {	
80
			
82
			
81
			protected String effectuerPreTraitementChaineRequete(String requete) {
83
			protected String effectuerPreTraitementChaineRequete(String requete) {
82
				return UtilitairesAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
84
				return UtilitairesAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
83
				// A décommenter lors de l'utilisation des web services eflore
85
				// A décommenter lors de l'utilisation des web services eflore
84
				//return RetourAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceEflore(requete);
86
				//return RetourAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceEflore(requete);
85
			}
87
			}
86
			
88
			
87
			@Override
89
			@Override
88
			protected String[] parserResultatRequete(Response response) {
90
			protected String[] parserResultatRequete(Response response) {
89
				return UtilitairesAutoCompletionService.parserRetourSimple(response);
91
				return UtilitairesAutoCompletionService.parserRetourSimple(response);
90
				// A décommenter lors de l'utilisation des web services eflore
92
				// A décommenter lors de l'utilisation des web services eflore
91
				//return RetourAutoCompletionService.parserRetourOss(response);
93
				//return RetourAutoCompletionService.parserRetourOss(response);
92
			}
94
			}
93
		};	
95
		};	
94
		gererEvenements();
96
		gererEvenements();
95
	}
97
	}
96
 
98
 
97
	@Override
99
	@Override
98
	public void go(HasWidgets composite) {
100
	public void go(HasWidgets composite) {
99
		afficherRequeteEtLancerRecherche();
101
		afficherRequeteEtLancerRecherche();
100
		autoCompletionNomTaxonsPresenteur.go(vue.getTaxon());
102
		autoCompletionNomTaxonsPresenteur.go(vue.getTaxon());
101
		composite.add(vue.asWidget());
103
		composite.add(vue.asWidget());
-
 
104
		vue.focusSaisie();
102
	}
105
	}
103
 
106
 
104
	@Override
107
	@Override
105
	protected void gererEvenements() {
108
	protected void gererEvenements() {
106
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
109
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
107
			public void onClick(ClickEvent event) {
110
			public void onClick(ClickEvent event) {
108
				vue.basculerAffichageZoneCache();
111
				vue.basculerAffichageZoneCache();
109
			}
112
			}
110
		});
113
		});
111
 
114
 
112
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
115
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
113
			public void onClick(ClickEvent event) {
116
			public void onClick(ClickEvent event) {
114
				collecterInfosRecherche();
117
				collecterInfosRecherche();
115
				afficherRequeteEtLancerRecherche();
118
				afficherRequeteEtLancerRecherche();
116
			}
119
			}
117
		});
120
		});
118
 
121
 
119
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
122
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
120
			public void onClick(ClickEvent event) {
123
			public void onClick(ClickEvent event) {
121
				collecterInfosRecherche();
124
				collecterInfosRecherche();
122
				vue.basculerAffichageZoneCache();
125
				vue.basculerAffichageZoneCache();
123
				afficherRequeteEtLancerRecherche();
126
				afficherRequeteEtLancerRecherche();
124
			}
127
			}
125
		});
128
		});
126
 
129
 
127
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
130
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
128
 
131
 
129
			public void onKeyPress(KeyPressEvent event) {
132
			public void onKeyPress(KeyPressEvent event) {
130
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
133
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
131
					collecterInfosRecherche();
134
					collecterInfosRecherche();
132
					afficherRequeteEtLancerRecherche();
135
					afficherRequeteEtLancerRecherche();
133
				}
136
				}
134
			}
137
			}
135
		});
138
		});
136
 
139
 
137
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
140
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
138
 
141
 
139
			@Override
142
			@Override
140
			public void onClick(ClickEvent event) {
143
			public void onClick(ClickEvent event) {
141
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
144
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
142
					vue.setValeurRechercheSimple("");
145
					vue.setValeurRechercheSimple("");
143
				}
146
				}
144
			}
147
			}
145
		});
148
		});
146
	}
149
	}
147
 
150
 
148
	private void collecterInfosRecherche() {
151
	private void collecterInfosRecherche() {
149
		InformationsRecherche informationRecherche = new InformationsRecherche();
152
		InformationsRecherche informationRecherche = new InformationsRecherche();
150
		informationRecherche.setAuteur(vue.getAuteur().getText());
153
		informationRecherche.setAuteur(vue.getAuteur().getText());
151
		informationRecherche.setCommune(vue.getCommune().getText());
154
		informationRecherche.setCommune(vue.getCommune().getText());
152
		informationRecherche.setDate(vue.getDate().getText());
155
		informationRecherche.setDate(vue.getDate().getText());
153
		informationRecherche.setDepartement(vue.getDepartement().getText());
156
		informationRecherche.setDepartement(vue.getDepartement().getText());
154
		informationRecherche.setFamille(vue.getFamille().getText());
157
		informationRecherche.setFamille(vue.getFamille().getText());
155
		informationRecherche.setGenre(vue.getGenre().getText());
158
		informationRecherche.setGenre(vue.getGenre().getText());
156
		informationRecherche.setMotClef(vue.getMotCle().getText());
159
		informationRecherche.setMotClef(vue.getMotCle().getText());
157
 
160
 
158
		if (!vue.getRecherchePrincipale().getText().equals(vue.getLabelRecherche())) {
161
		if (!vue.getRecherchePrincipale().getText().equals(vue.getLabelRecherche())) {
159
			informationRecherche.setRechercheLibre(vue.getRecherchePrincipale().getText());
162
			informationRecherche.setRechercheLibre(vue.getRecherchePrincipale().getText());
160
		}
163
		}
161
		if (isPourRechercheImages()) {
164
		if (isPourRechercheImages()) {
162
			CacheClient.getInstance().setInformationsRechercheImage(informationRecherche);
165
			CacheClient.getInstance().setInformationsRechercheImage(informationRecherche);
163
		} else if (isPourRechercheObservations()) {
166
		} else if (isPourRechercheObservations()) {
164
			CacheClient.getInstance().setInformationsRechercheObservation(informationRecherche);
167
			CacheClient.getInstance().setInformationsRechercheObservation(informationRecherche);
165
		}
168
		}
166
	}
169
	}
167
 
170
 
168
	private InformationsRecherche getInformationsRechercheEnCache() {
171
	private InformationsRecherche getInformationsRechercheEnCache() {
169
		if (isPourRechercheImages()) {
172
		if (isPourRechercheImages()) {
170
			return CacheClient.getInstance().getInformationsRechercheImage();
173
			return CacheClient.getInstance().getInformationsRechercheImage();
171
		} else if (isPourRechercheObservations()) {
174
		} else if (isPourRechercheObservations()) {
172
			return CacheClient.getInstance().getInformationsRechercheObservation();
175
			return CacheClient.getInstance().getInformationsRechercheObservation();
173
		}
176
		}
174
		return null;
177
		return null;
175
	}
178
	}
176
 
179
 
177
	public void afficherRequeteEtLancerRecherche() {
180
	public void afficherRequeteEtLancerRecherche() {
178
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
181
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
179
		if (informationsRecherche != null) {
182
		if (informationsRecherche != null) {
180
			vue.chargerValeursRecherchePrecedente(informationsRecherche);
183
			vue.chargerValeursRecherchePrecedente(informationsRecherche);
181
		}
184
		}
182
		lancerRecherche();
185
		lancerRecherche();
183
	}
186
	}
184
 
187
 
185
	public abstract void lancerRecherche();
188
	public abstract void lancerRecherche();
186
 
189
 
187
	public boolean isPourRechercheImages() {
190
	public boolean isPourRechercheImages() {
188
		return pourRechercheImages;
191
		return pourRechercheImages;
189
	}
192
	}
190
 
193
 
191
	public boolean isPourRechercheObservations() {
194
	public boolean isPourRechercheObservations() {
192
		return pourRechercheObservations;
195
		return pourRechercheObservations;
193
	}
196
	}
194
}
197
}