Subversion Repositories eFlore/Applications.del

Rev

Rev 322 | Rev 386 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
322 gduche 1
package org.tela_botanica.del.client.composants.moteurrecherche;
2
 
335 benjamin 3
import org.tela_botanica.del.client.cache.CacheClient;
322 gduche 4
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
335 benjamin 5
import org.tela_botanica.del.client.modeles.InformationsRecherche;
322 gduche 6
 
7
import com.google.gwt.event.dom.client.ClickEvent;
8
import com.google.gwt.event.dom.client.ClickHandler;
9
import com.google.gwt.event.dom.client.HasClickHandlers;
10
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
11
import com.google.gwt.event.dom.client.KeyCodes;
12
import com.google.gwt.event.dom.client.KeyPressEvent;
13
import com.google.gwt.event.dom.client.KeyPressHandler;
335 benjamin 14
import com.google.gwt.user.client.ui.HasText;
322 gduche 15
import com.google.gwt.user.client.ui.HasWidgets;
16
import com.google.gwt.user.client.ui.IsWidget;
17
 
18
public abstract class MoteurRecherchePresenteur extends Presenteur {
335 benjamin 19
 
322 gduche 20
	public abstract interface Vue extends IsWidget {
335 benjamin 21
 
322 gduche 22
		public abstract HasClickHandlers getLienRechercheAvancee();
335 benjamin 23
 
322 gduche 24
		public abstract void basculerAffichageZoneCache();
335 benjamin 25
 
322 gduche 26
		public abstract HasClickHandlers getBoutonRechercheSimple();
335 benjamin 27
 
322 gduche 28
		public abstract HasClickHandlers getBoutonRechercheAvancee();
335 benjamin 29
 
322 gduche 30
		public abstract HasKeyPressHandlers getChampSaisie();
335 benjamin 31
 
322 gduche 32
		public abstract HasClickHandlers getChampSaisieCliquable();
335 benjamin 33
 
322 gduche 34
		public abstract String getValeurRechercheSimple();
335 benjamin 35
 
322 gduche 36
		public void setValeurRechercheSimple(String valeurRecherche);
335 benjamin 37
 
322 gduche 38
		public String getLabelRecherche();
335 benjamin 39
 
40
		public HasText getRecherchePrincipale();
41
 
42
		public HasText getDepartement();
43
 
44
		public HasText getCommune();
45
 
46
		public HasText getTaxon();
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
 
58
		public HasText getDate();
59
 
60
		public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche);
322 gduche 61
	}
62
 
335 benjamin 63
	private final Vue vue;
64
	private final boolean pourRechercheImages, pourRechercheObservations;
65
 
66
	public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) {
322 gduche 67
		this.vue = vue;
335 benjamin 68
		this.pourRechercheImages = pourRechercheImages;
69
		this.pourRechercheObservations = pourRechercheObservations;
322 gduche 70
		gererEvenements();
71
	}
335 benjamin 72
 
322 gduche 73
	@Override
74
	public void go(HasWidgets composite) {
335 benjamin 75
		afficherRequeteEtLancerRecherche();
322 gduche 76
		composite.add(vue.asWidget());
77
	}
78
 
79
	@Override
80
	protected void gererEvenements() {
81
		vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() {
82
			public void onClick(ClickEvent event) {
83
				vue.basculerAffichageZoneCache();
84
			}
85
		});
335 benjamin 86
 
322 gduche 87
		vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() {
88
			public void onClick(ClickEvent event) {
335 benjamin 89
				collecterInfosRecherche();
90
				afficherRequeteEtLancerRecherche();
322 gduche 91
			}
92
		});
335 benjamin 93
 
322 gduche 94
		vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() {
95
			public void onClick(ClickEvent event) {
335 benjamin 96
				collecterInfosRecherche();
97
				vue.basculerAffichageZoneCache();
98
				afficherRequeteEtLancerRecherche();
322 gduche 99
			}
100
		});
335 benjamin 101
 
322 gduche 102
		vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() {
335 benjamin 103
 
322 gduche 104
			public void onKeyPress(KeyPressEvent event) {
105
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
335 benjamin 106
					collecterInfosRecherche();
107
					afficherRequeteEtLancerRecherche();
322 gduche 108
				}
109
			}
110
		});
335 benjamin 111
 
322 gduche 112
		vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() {
335 benjamin 113
 
322 gduche 114
			@Override
115
			public void onClick(ClickEvent event) {
116
				if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) {
117
					vue.setValeurRechercheSimple("");
118
				}
119
			}
120
		});
121
	}
335 benjamin 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
		}
322 gduche 141
	}
335 benjamin 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
 
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() {
163
		return pourRechercheImages;
164
	}
165
 
166
	public boolean isPourRechercheObservations() {
167
		return pourRechercheObservations;
168
	}
322 gduche 169
}