Subversion Repositories eFlore/Applications.del

Rev

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

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