Subversion Repositories eFlore/Applications.del

Rev

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

Rev 322 Rev 335
Line 1... Line 1...
1
package org.tela_botanica.del.client.composants.moteurrecherche;
1
package org.tela_botanica.del.client.composants.moteurrecherche;
Line 2... Line 2...
2
 
2
 
3
import java.util.HashMap;
-
 
4
 
3
import org.tela_botanica.del.client.cache.CacheClient;
5
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
4
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
Line 6... Line 5...
6
import org.tela_botanica.del.client.i18n.I18n;
5
import org.tela_botanica.del.client.modeles.InformationsRecherche;
7
 
6
 
8
import com.google.gwt.event.dom.client.ClickEvent;
7
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.event.dom.client.ClickHandler;
8
import com.google.gwt.event.dom.client.ClickHandler;
10
import com.google.gwt.event.dom.client.HasClickHandlers;
9
import com.google.gwt.event.dom.client.HasClickHandlers;
11
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
10
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
12
import com.google.gwt.event.dom.client.KeyCodes;
11
import com.google.gwt.event.dom.client.KeyCodes;
13
import com.google.gwt.event.dom.client.KeyPressEvent;
12
import com.google.gwt.event.dom.client.KeyPressEvent;
14
import com.google.gwt.event.dom.client.KeyPressHandler;
13
import com.google.gwt.event.dom.client.KeyPressHandler;
15
import com.google.gwt.user.client.Window;
14
import com.google.gwt.user.client.ui.HasText;
Line 16... Line 15...
16
import com.google.gwt.user.client.ui.HasWidgets;
15
import com.google.gwt.user.client.ui.HasWidgets;
17
import com.google.gwt.user.client.ui.IsWidget;
16
import com.google.gwt.user.client.ui.IsWidget;
18
 
17
 
-
 
18
public abstract class MoteurRecherchePresenteur extends Presenteur {
19
public abstract class MoteurRecherchePresenteur extends Presenteur {
19
 
-
 
20
	public abstract interface Vue extends IsWidget {
20
	
21
 
-
 
22
		public abstract HasClickHandlers getLienRechercheAvancee();
21
	public abstract interface Vue extends IsWidget {
23
 
-
 
24
		public abstract void basculerAffichageZoneCache();
22
		public abstract HasClickHandlers getLienRechercheAvancee();
25
 
-
 
26
		public abstract HasClickHandlers getBoutonRechercheSimple();
23
		public abstract void basculerAffichageZoneCache();
27
 
-
 
28
		public abstract HasClickHandlers getBoutonRechercheAvancee();
24
		public abstract HasClickHandlers getBoutonRechercheSimple();
29
 
-
 
30
		public abstract HasKeyPressHandlers getChampSaisie();
25
		public abstract HasClickHandlers getBoutonRechercheAvancee();
31
 
-
 
32
		public abstract HasClickHandlers getChampSaisieCliquable();
26
		public abstract HasKeyPressHandlers getChampSaisie();
33
 
-
 
34
		public abstract String getValeurRechercheSimple();
27
		public abstract HasClickHandlers getChampSaisieCliquable();
35
 
-
 
36
		public void setValeurRechercheSimple(String valeurRecherche);
28
		public abstract String getValeurRechercheSimple();
37
 
-
 
38
		public String getLabelRecherche();
29
		public void setValeurRechercheSimple(String valeurRecherche);
39
 
-
 
40
		public HasText getRecherchePrincipale();
-
 
41
 
-
 
42
		public HasText getDepartement();
-
 
43
 
-
 
44
		public HasText getCommune();
-
 
45
 
-
 
46
		public HasText getTaxon();
30
		public String getLabelRecherche();
47
 
-
 
48
		public HasText getFamille();
-
 
49
 
-
 
50
		public HasText getGenre();
-
 
51
 
-
 
52
		public HasText getTag();
-
 
53
 
-
 
54
		public HasText getMotCle();
-
 
55
 
-
 
56
		public HasText getAuteur();
-
 
57
 
31
		public abstract HashMap<String, String> collecterFormulaire(); 
58
		public HasText getDate();
Line 32... Line 59...
32
		public String getChaineRecherche();
59
 
-
 
60
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
33
		public abstract void setRecherchePrecedente();
61
	}
34
	}
62
 
35
 
63
	private final Vue vue;
-
 
64
	private final boolean pourRechercheImages, pourRechercheObservations;
-
 
65
 
36
	private Vue vue;
66
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) {
37
	
67
		this.vue = vue;
38
	public MoteurRecherchePresenteur(Vue vue) {
68
		this.pourRechercheImages = pourRechercheImages;
39
		this.vue = vue;
69
		this.pourRechercheObservations = pourRechercheObservations;
40
		gererEvenements();
70
		gererEvenements();
-
 
71
	}
41
	}
72
 
42
	
73
	@Override
Line 43... Line 74...
43
	@Override
74
	public void go(HasWidgets composite) {
44
	public void go(HasWidgets composite) {
75
		afficherRequeteEtLancerRecherche();
45
		composite.add(vue.asWidget());
76
		composite.add(vue.asWidget());
46
	}
77
	}
47
 
78
 
48
	@Override
79
	@Override
49
	protected void gererEvenements() {
80
	protected void gererEvenements() {
50
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
81
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
51
			public void onClick(ClickEvent event) {
82
			public void onClick(ClickEvent event) {
52
				vue.basculerAffichageZoneCache();
83
				vue.basculerAffichageZoneCache();
53
			}
84
			}
54
		});
85
		});
55
		
86
 
56
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
87
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
57
			public void onClick(ClickEvent event) {
88
			public void onClick(ClickEvent event) {
58
				afficherInfoRecherche();
89
				collecterInfosRecherche();
59
				lancerRecherche(vue.getChaineRecherche());
90
				afficherRequeteEtLancerRecherche();
60
			}
91
			}
-
 
92
		});
61
		});
93
 
62
		
94
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
63
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
95
			public void onClick(ClickEvent event) {
64
			public void onClick(ClickEvent event) {
96
				collecterInfosRecherche();
65
				afficherInfoRecherche();
97
				vue.basculerAffichageZoneCache();
66
				lancerRecherche(vue.getChaineRecherche());
98
				afficherRequeteEtLancerRecherche();
67
			}
99
			}
68
		});
100
		});
69
		
101
 
70
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
102
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
71
			
103
 
72
			public void onKeyPress(KeyPressEvent event) {
104
			public void onKeyPress(KeyPressEvent event) {
73
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
105
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
74
					afficherInfoRecherche();
106
					collecterInfosRecherche();
75
					lancerRecherche(vue.getChaineRecherche());
107
					afficherRequeteEtLancerRecherche();
76
				}
108
				}
77
			}
109
			}
78
		});
110
		});
79
		
111
 
80
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
112
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
81
			
113
 
82
			@Override
114
			@Override
83
			public void onClick(ClickEvent event) {
115
			public void onClick(ClickEvent event) {
84
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
-
 
85
					vue.setValeurRechercheSimple("");
116
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
86
				}
117
					vue.setValeurRechercheSimple("");
87
			}
118
				}
-
 
119
			}
-
 
120
		});
-
 
121
	}
-
 
122
 
-
 
123
	private void collecterInfosRecherche() {
-
 
124
		InformationsRecherche informationRecherche = new InformationsRecherche();
-
 
125
		informationRecherche.setAuteur(vue.getAuteur().getText());
-
 
126
		informationRecherche.setCommune(vue.getCommune().getText());
-
 
127
		informationRecherche.setDate(vue.getDate().getText());
-
 
128
		informationRecherche.setDepartement(vue.getDepartement().getText());
-
 
129
		informationRecherche.setFamille(vue.getFamille().getText());
-
 
130
		informationRecherche.setGenre(vue.getGenre().getText());
-
 
131
		informationRecherche.setMotClef(vue.getMotCle().getText());
-
 
132
 
-
 
133
		if (!vue.getRecherchePrincipale().getText().equals(vue.getLabelRecherche())) {
-
 
134
			informationRecherche.setRechercheLibre(vue.getRecherchePrincipale().getText());
-
 
135
		}
-
 
136
		if (isPourRechercheImages()) {
-
 
137
			CacheClient.getInstance().setInformationsRechercheImage(informationRecherche);
-
 
138
		} else if (isPourRechercheObservations()) {
-
 
139
			CacheClient.getInstance().setInformationsRechercheObservation(informationRecherche);
-
 
140
		}
-
 
141
	}
-
 
142
 
-
 
143
	private InformationsRecherche getInformationsRechercheEnCache() {
-
 
144
		if (isPourRechercheImages()) {
-
 
145
			return CacheClient.getInstance().getInformationsRechercheImage();
-
 
146
		} else if (isPourRechercheObservations()) {
-
 
147
			return CacheClient.getInstance().getInformationsRechercheObservation();
-
 
148
		}
-
 
149
		return null;
-
 
150
	}
-
 
151
 
88
		});
152
	public void afficherRequeteEtLancerRecherche() {
-
 
153
		InformationsRecherche informationsRecherche = getInformationsRechercheEnCache();
-
 
154
		if (informationsRecherche != null) {
-
 
155
			vue.chargerValeursRecherchePrecedente(informationsRecherche);
-
 
156
		}
-
 
157
		lancerRecherche();
-
 
158
	}
-
 
159
 
-
 
160
	public abstract void lancerRecherche();
-
 
161
 
-
 
162
	public boolean isPourRechercheImages() {
89
			
163
		return pourRechercheImages;
90
	}
-
 
91
	
-
 
92
	private void afficherInfoRecherche() {
164
	}