445 |
benjamin |
1 |
package org.tela_botanica.del.client.vues.rechercheobservations.resultats;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.del.client.cache.CacheClient;
|
|
|
4 |
import org.tela_botanica.del.client.composants.pagination.PaginationPresenteur;
|
|
|
5 |
import org.tela_botanica.del.client.composants.pagination.PaginationVue;
|
|
|
6 |
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
|
459 |
benjamin |
7 |
import org.tela_botanica.del.client.modeles.InformationsRecherche;
|
|
|
8 |
import org.tela_botanica.del.client.modeles.ModeTri;
|
445 |
benjamin |
9 |
import org.tela_botanica.del.client.modeles.Observation;
|
|
|
10 |
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
|
|
|
11 |
import org.tela_botanica.del.client.services.rest.ObservationService;
|
|
|
12 |
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
|
480 |
benjamin |
13 |
import org.tela_botanica.del.client.vues.rechercheobservations.resultats.observations.ObservationPresenteur;
|
|
|
14 |
import org.tela_botanica.del.client.vues.rechercheobservations.resultats.observations.ObservationVue;
|
445 |
benjamin |
15 |
|
459 |
benjamin |
16 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
17 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
18 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
445 |
benjamin |
19 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
20 |
import com.google.gwt.user.client.ui.IsWidget;
|
592 |
gduche |
21 |
import com.google.gwt.user.client.ui.Label;
|
445 |
benjamin |
22 |
|
|
|
23 |
public class ResultatsRechercheObservationsPresenteur extends Presenteur {
|
|
|
24 |
|
903 |
gduche |
25 |
/**
|
|
|
26 |
* Interface vue : création des composants graphiques
|
|
|
27 |
* */
|
445 |
benjamin |
28 |
public abstract interface Vue extends IsWidget {
|
|
|
29 |
public HasWidgets getZoneObservations();
|
|
|
30 |
public HasWidgets getZonePaginationHaut();
|
|
|
31 |
public HasWidgets getZonePaginationBas();
|
|
|
32 |
public void startChargement();
|
|
|
33 |
public void stopChargement();
|
|
|
34 |
public void nettoyer();
|
459 |
benjamin |
35 |
public HasClickHandlers getTriParDateAscendant();
|
|
|
36 |
public HasClickHandlers getTriParDateDescendant();
|
564 |
benjamin |
37 |
public void afficherElementsAucunResultatTrouve();
|
652 |
aurelien |
38 |
public void afficherElementsResultatsTrouves();
|
677 |
gduche |
39 |
public HasClickHandlers getLabelDate();
|
903 |
gduche |
40 |
public void setModeTri(ModeTri mode);
|
445 |
benjamin |
41 |
}
|
|
|
42 |
|
|
|
43 |
private Vue vue;
|
903 |
gduche |
44 |
private ObservationService serviceObs;
|
677 |
gduche |
45 |
private ModeTri triCourantDate = ModeTri.TRI_DESCENDANT;
|
903 |
gduche |
46 |
private CacheClient cache = CacheClient.getInstance();
|
592 |
gduche |
47 |
|
903 |
gduche |
48 |
/**
|
|
|
49 |
* Constructeur de la classe
|
|
|
50 |
* @param ObservationService serviceObs le service pour récupérer les observations
|
|
|
51 |
* @Vue Vue l'objet implémentant l'interface
|
|
|
52 |
* */
|
445 |
benjamin |
53 |
public ResultatsRechercheObservationsPresenteur(ObservationService serviceObs, Vue vue) {
|
|
|
54 |
this.vue = vue;
|
903 |
gduche |
55 |
vue.setModeTri(triCourantDate);
|
445 |
benjamin |
56 |
this.serviceObs = serviceObs;
|
|
|
57 |
}
|
|
|
58 |
|
903 |
gduche |
59 |
/**
|
|
|
60 |
* Lancer l'affichage de la recherche dans le composant passé en paramètre
|
|
|
61 |
* @param HasWidgets composite le conteneur de widgets dans lequel ajouter la vue
|
|
|
62 |
* */
|
445 |
benjamin |
63 |
public void go(HasWidgets composite) {
|
|
|
64 |
composite.add(vue.asWidget());
|
|
|
65 |
lancerRechercheEtCreerWidgetPagination();
|
459 |
benjamin |
66 |
gererEvenements();
|
445 |
benjamin |
67 |
}
|
|
|
68 |
|
903 |
gduche |
69 |
/**
|
|
|
70 |
* Initier un callback pour créer le widget de pagination et afficher les observations recues
|
|
|
71 |
* et lancer la recherche avec le service
|
|
|
72 |
* */
|
|
|
73 |
public void lancerRechercheEtCreerWidgetPagination() {
|
595 |
gduche |
74 |
|
903 |
gduche |
75 |
int debut = (cache.getPageCouranteRechercheObservations() - 1) * cache.getPasPagination();
|
|
|
76 |
int fin = cache.getPageCouranteRechercheObservations() * cache.getPasPagination();
|
595 |
gduche |
77 |
|
445 |
benjamin |
78 |
ObservationsCallback callback = new ObservationsCallback() {
|
|
|
79 |
public void surObservationsRecues(ObservationServiceResultat observationsRecues) {
|
903 |
gduche |
80 |
creerWidgetPagination(observationsRecues.getNbTotalObservationsPourLaRecherche());
|
445 |
benjamin |
81 |
afficherObservations(observationsRecues);
|
|
|
82 |
}
|
|
|
83 |
};
|
903 |
gduche |
84 |
|
|
|
85 |
serviceObs.getObservations(cache.getInformationsRechercheObservation(), debut, fin, callback);
|
445 |
benjamin |
86 |
}
|
903 |
gduche |
87 |
|
|
|
88 |
/**
|
|
|
89 |
* Créer les widgets de pagination en fonction du nombre d'observation
|
|
|
90 |
* @param int nbObservations le nombre d'observations à afficher
|
|
|
91 |
* */
|
445 |
benjamin |
92 |
private void creerWidgetPagination(int nbObservations) {
|
|
|
93 |
vue.getZonePaginationHaut().clear();
|
903 |
gduche |
94 |
PaginationPresenteur paginationPresenteurHaut = creerPresenteurPagination(nbObservations);
|
|
|
95 |
paginationPresenteurHaut.setGroupePagination("pagination_observations");
|
|
|
96 |
paginationPresenteurHaut.go(vue.getZonePaginationHaut());
|
|
|
97 |
|
445 |
benjamin |
98 |
vue.getZonePaginationBas().clear();
|
|
|
99 |
PaginationPresenteur paginationPresenteurBas = creerPresenteurPagination(nbObservations);
|
446 |
aurelien |
100 |
paginationPresenteurBas.setGroupePagination("pagination_observations");
|
445 |
benjamin |
101 |
paginationPresenteurBas.go(vue.getZonePaginationBas());
|
|
|
102 |
}
|
903 |
gduche |
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Créer un présenteur du widget pagination
|
|
|
106 |
* @param int nbObservations le nombre total d'observation à afficher
|
|
|
107 |
* */
|
445 |
benjamin |
108 |
private PaginationPresenteur creerPresenteurPagination(int nbObservations) {
|
903 |
gduche |
109 |
PaginationPresenteur presenteur = new PaginationPresenteur(new PaginationVue(), nbObservations, cache.getPasPagination(), cache.getPageCouranteRechercheObservations()) {
|
445 |
benjamin |
110 |
|
|
|
111 |
@Override
|
|
|
112 |
public void chargerElements(int debut, int fin) {
|
|
|
113 |
chargerEtAfficherObservations(debut, fin);
|
903 |
gduche |
114 |
cache.setPageCouranteRechercheObservations(getPageCourante());
|
445 |
benjamin |
115 |
}
|
|
|
116 |
|
|
|
117 |
@Override
|
|
|
118 |
public void actualiserPasCache(int pas) {
|
903 |
gduche |
119 |
cache.setPasPagination(pas);
|
445 |
benjamin |
120 |
}
|
|
|
121 |
|
|
|
122 |
};
|
903 |
gduche |
123 |
return presenteur;
|
445 |
benjamin |
124 |
}
|
903 |
gduche |
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Gestion des évènements de la vue recherche Observation
|
|
|
128 |
* */
|
|
|
129 |
protected void gererEvenements() {
|
|
|
130 |
|
|
|
131 |
ClickHandler surClicDate = new ClickHandler() {
|
|
|
132 |
/**
|
|
|
133 |
* Gestion du clic sur l'option de tri par date d'observation
|
|
|
134 |
* Masque les éléments de tri qui sont en cours et affiche les autres
|
|
|
135 |
* */
|
|
|
136 |
public void onClick(ClickEvent event) {
|
|
|
137 |
toggleModeTri();
|
|
|
138 |
|
|
|
139 |
InformationsRecherche informationsRechercheObservations = cache.getInformationsRechercheObservation();
|
|
|
140 |
informationsRechercheObservations.setTriParDate(triCourantDate);
|
|
|
141 |
chercherEtAfficherObservationsPageEnCours();
|
|
|
142 |
}
|
|
|
143 |
};
|
|
|
144 |
|
|
|
145 |
vue.getLabelDate().addClickHandler(surClicDate);
|
|
|
146 |
vue.getTriParDateAscendant().addClickHandler(surClicDate);
|
|
|
147 |
vue.getTriParDateDescendant().addClickHandler(surClicDate);
|
|
|
148 |
}
|
445 |
benjamin |
149 |
|
903 |
gduche |
150 |
/**
|
|
|
151 |
* Inverser le mode de tri en fonction du précédent
|
|
|
152 |
* */
|
|
|
153 |
public void toggleModeTri() {
|
|
|
154 |
if (triCourantDate == ModeTri.TRI_ASCENDANT) {
|
|
|
155 |
triCourantDate = ModeTri.TRI_DESCENDANT;
|
|
|
156 |
} else {
|
|
|
157 |
triCourantDate = ModeTri.TRI_ASCENDANT;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
vue.setModeTri(triCourantDate);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
* Initialiser les variable de début et fin et lancer le chargement des observations
|
|
|
165 |
* */
|
|
|
166 |
public void chercherEtAfficherObservationsPageEnCours() {
|
|
|
167 |
int debut = (cache.getPageCouranteRechercheObservations() - 1) * cache.getPasPagination();
|
|
|
168 |
int fin = (cache.getPageCouranteRechercheObservations()) * cache.getPasPagination();
|
|
|
169 |
chargerEtAfficherObservations(debut, fin);
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/**
|
|
|
173 |
* Lancer le service pour charger les observations entre debut et fin et les afficher
|
|
|
174 |
* @param int debut l'entier de départ de la requete
|
|
|
175 |
* @param int fin l'entier de limite de la requete
|
|
|
176 |
* */
|
|
|
177 |
public void chargerEtAfficherObservations(int debut, int fin) {
|
|
|
178 |
vue.startChargement();
|
|
|
179 |
vue.nettoyer();
|
|
|
180 |
|
|
|
181 |
ObservationsCallback surReceptionObservation = new ObservationsCallback() {
|
|
|
182 |
|
445 |
benjamin |
183 |
@Override
|
|
|
184 |
public void surObservationsRecues(ObservationServiceResultat observationsRecues) {
|
|
|
185 |
afficherObservations(observationsRecues);
|
|
|
186 |
}
|
|
|
187 |
};
|
903 |
gduche |
188 |
serviceObs.getObservations(cache.getInformationsRechercheObservation(), debut, fin, surReceptionObservation);
|
445 |
benjamin |
189 |
}
|
|
|
190 |
|
903 |
gduche |
191 |
/**
|
|
|
192 |
* Parcrourir les résultats de la recherche pour initier l'affichage de chaque observation
|
|
|
193 |
* @param ObservationServiceResultat resultats les résultats issus de la requête
|
|
|
194 |
* */
|
|
|
195 |
private void afficherObservations(ObservationServiceResultat resultats) {
|
|
|
196 |
vue.nettoyer();
|
|
|
197 |
|
|
|
198 |
if (resultats.getObservations() == null || resultats.getObservations().size() == 0) {
|
|
|
199 |
vue.afficherElementsAucunResultatTrouve();
|
|
|
200 |
} else {
|
|
|
201 |
vue.afficherElementsResultatsTrouves();
|
|
|
202 |
for (Observation observation : resultats.getObservations()) {
|
|
|
203 |
ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation);
|
|
|
204 |
presenteur.go(vue.getZoneObservations());
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
vue.stopChargement();
|
459 |
benjamin |
208 |
}
|
445 |
benjamin |
209 |
}
|