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;
|
|
|
7 |
import org.tela_botanica.del.client.modeles.Observation;
|
|
|
8 |
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
|
|
|
9 |
import org.tela_botanica.del.client.services.rest.ObservationService;
|
|
|
10 |
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
|
|
|
11 |
import org.tela_botanica.del.client.vues.rechercheobservations.ObservationPresenteur;
|
|
|
12 |
import org.tela_botanica.del.client.vues.rechercheobservations.ObservationVue;
|
|
|
13 |
|
|
|
14 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
15 |
import com.google.gwt.user.client.ui.IsWidget;
|
|
|
16 |
|
|
|
17 |
public class ResultatsRechercheObservationsPresenteur extends Presenteur {
|
|
|
18 |
|
|
|
19 |
private ObservationService serviceObs;
|
|
|
20 |
|
|
|
21 |
public abstract interface Vue extends IsWidget {
|
|
|
22 |
|
|
|
23 |
public HasWidgets getZoneObservations();
|
|
|
24 |
|
|
|
25 |
public HasWidgets getZonePaginationHaut();
|
|
|
26 |
|
|
|
27 |
public HasWidgets getZonePaginationBas();
|
|
|
28 |
|
|
|
29 |
public void startChargement();
|
|
|
30 |
|
|
|
31 |
public void stopChargement();
|
|
|
32 |
|
|
|
33 |
public void nettoyer();
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
private Vue vue;
|
|
|
37 |
|
|
|
38 |
public ResultatsRechercheObservationsPresenteur(ObservationService serviceObs, Vue vue) {
|
|
|
39 |
|
|
|
40 |
this.vue = vue;
|
|
|
41 |
this.serviceObs = serviceObs;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public void go(HasWidgets composite) {
|
|
|
45 |
composite.add(vue.asWidget());
|
|
|
46 |
lancerRechercheEtCreerWidgetPagination();
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
protected void gererEvenements() {
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public void chargerEtAfficherObservations(int debut, int fin) {
|
|
|
53 |
vue.startChargement();
|
|
|
54 |
vue.nettoyer();
|
|
|
55 |
ObservationsCallback callback = new ObservationsCallback() {
|
|
|
56 |
|
|
|
57 |
@Override
|
|
|
58 |
public void surObservationsRecues(ObservationServiceResultat observationsRecues) {
|
|
|
59 |
afficherObservations(observationsRecues);
|
|
|
60 |
}
|
|
|
61 |
};
|
|
|
62 |
serviceObs.getObservations(CacheClient.getInstance().getInformationsRechercheObservation(), debut, fin, callback);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
private void afficherObservations(ObservationServiceResultat observationServiceResultat) {
|
|
|
66 |
vue.nettoyer();
|
|
|
67 |
for (Observation observation : observationServiceResultat.getObservations()) {
|
|
|
68 |
ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation);
|
|
|
69 |
presenteur.go(vue.getZoneObservations());
|
|
|
70 |
}
|
|
|
71 |
vue.stopChargement();
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
private void creerWidgetPagination(int nbObservations) {
|
|
|
75 |
vue.getZonePaginationHaut().clear();
|
|
|
76 |
vue.getZonePaginationBas().clear();
|
|
|
77 |
PaginationPresenteur paginationPresenteurHaut = creerPresenteurPagination(nbObservations);
|
|
|
78 |
PaginationPresenteur paginationPresenteurBas = creerPresenteurPagination(nbObservations);
|
446 |
aurelien |
79 |
paginationPresenteurHaut.setGroupePagination("pagination_observations");
|
|
|
80 |
paginationPresenteurBas.setGroupePagination("pagination_observations");
|
445 |
benjamin |
81 |
paginationPresenteurHaut.go(vue.getZonePaginationHaut());
|
|
|
82 |
paginationPresenteurBas.go(vue.getZonePaginationBas());
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
private PaginationPresenteur creerPresenteurPagination(int nbObservations) {
|
|
|
86 |
PaginationPresenteur paginationPresenteurHaut = new PaginationPresenteur(new PaginationVue(), nbObservations, CacheClient.getInstance().getPasPagination(), CacheClient.getInstance().getPageCouranteRechercheObservations()) {
|
|
|
87 |
|
|
|
88 |
@Override
|
|
|
89 |
public void chargerElements(int debut, int fin) {
|
|
|
90 |
chargerEtAfficherObservations(debut, fin);
|
|
|
91 |
CacheClient.getInstance().setPageCouranteRechercheObservations(getPageCourante());
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
@Override
|
|
|
95 |
public void actualiserPasCache(int pas) {
|
|
|
96 |
CacheClient.getInstance().setPasPagination(pas);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
};
|
|
|
100 |
return paginationPresenteurHaut;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
public void lancerRechercheEtCreerWidgetPagination() {
|
|
|
104 |
ObservationsCallback callback = new ObservationsCallback() {
|
|
|
105 |
@Override
|
|
|
106 |
public void surObservationsRecues(ObservationServiceResultat observationsRecues) {
|
|
|
107 |
creerWidgetPagination(observationsRecues.getNbTotalObservationsPourLaRecherche());
|
|
|
108 |
afficherObservations(observationsRecues);
|
|
|
109 |
}
|
|
|
110 |
};
|
|
|
111 |
|
|
|
112 |
int debut = (CacheClient.getInstance().getPageCouranteRechercheObservations() - 1) * CacheClient.getInstance().getPasPagination();
|
|
|
113 |
int fin = (CacheClient.getInstance().getPageCouranteRechercheObservations()) * CacheClient.getInstance().getPasPagination();
|
|
|
114 |
serviceObs.getObservations(CacheClient.getInstance().getInformationsRechercheObservation(), debut, fin, callback);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
}
|