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;
|
|
|
13 |
import org.tela_botanica.del.client.vues.rechercheobservations.ObservationPresenteur;
|
|
|
14 |
import org.tela_botanica.del.client.vues.rechercheobservations.ObservationVue;
|
|
|
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;
|
|
|
21 |
|
|
|
22 |
public class ResultatsRechercheObservationsPresenteur extends Presenteur {
|
|
|
23 |
|
|
|
24 |
private ObservationService serviceObs;
|
|
|
25 |
|
|
|
26 |
public abstract interface Vue extends IsWidget {
|
|
|
27 |
|
|
|
28 |
public HasWidgets getZoneObservations();
|
|
|
29 |
|
|
|
30 |
public HasWidgets getZonePaginationHaut();
|
|
|
31 |
|
|
|
32 |
public HasWidgets getZonePaginationBas();
|
|
|
33 |
|
|
|
34 |
public void startChargement();
|
|
|
35 |
|
|
|
36 |
public void stopChargement();
|
|
|
37 |
|
|
|
38 |
public void nettoyer();
|
459 |
benjamin |
39 |
|
|
|
40 |
public HasClickHandlers getTriParNbVotesAscendant();
|
|
|
41 |
|
|
|
42 |
public HasClickHandlers getTriParNbVotesDescendant();
|
|
|
43 |
|
|
|
44 |
public HasClickHandlers getTriParDateAscendant();
|
|
|
45 |
|
|
|
46 |
public HasClickHandlers getTriParDateDescendant();
|
445 |
benjamin |
47 |
}
|
|
|
48 |
|
|
|
49 |
private Vue vue;
|
|
|
50 |
|
|
|
51 |
public ResultatsRechercheObservationsPresenteur(ObservationService serviceObs, Vue vue) {
|
|
|
52 |
|
|
|
53 |
this.vue = vue;
|
|
|
54 |
this.serviceObs = serviceObs;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public void go(HasWidgets composite) {
|
|
|
58 |
composite.add(vue.asWidget());
|
|
|
59 |
lancerRechercheEtCreerWidgetPagination();
|
459 |
benjamin |
60 |
gererEvenements();
|
445 |
benjamin |
61 |
}
|
|
|
62 |
|
|
|
63 |
protected void gererEvenements() {
|
459 |
benjamin |
64 |
|
|
|
65 |
vue.getTriParNbVotesAscendant().addClickHandler(new ClickHandler() {
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
public void onClick(ClickEvent arg0) {
|
|
|
69 |
InformationsRecherche informationsRechercheObservations = CacheClient.getInstance().getInformationsRechercheObservation();
|
|
|
70 |
informationsRechercheObservations.setTriParNbVotes(ModeTri.TRI_ASCENDANT);
|
|
|
71 |
chercherEtAfficherObservationsPageEnCours();
|
|
|
72 |
}
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
vue.getTriParNbVotesDescendant().addClickHandler(new ClickHandler() {
|
|
|
76 |
|
|
|
77 |
@Override
|
|
|
78 |
public void onClick(ClickEvent arg0) {
|
|
|
79 |
InformationsRecherche informationsRechercheObservations = CacheClient.getInstance().getInformationsRechercheObservation();
|
|
|
80 |
informationsRechercheObservations.setTriParNbVotes(ModeTri.TRI_DESCENDANT);
|
|
|
81 |
chercherEtAfficherObservationsPageEnCours();
|
|
|
82 |
}
|
|
|
83 |
});
|
|
|
84 |
|
|
|
85 |
vue.getTriParDateAscendant().addClickHandler(new ClickHandler() {
|
|
|
86 |
|
|
|
87 |
@Override
|
|
|
88 |
public void onClick(ClickEvent arg0) {
|
|
|
89 |
InformationsRecherche informationsRechercheObservations = CacheClient.getInstance().getInformationsRechercheObservation();
|
|
|
90 |
informationsRechercheObservations.setTriParDate(ModeTri.TRI_ASCENDANT);
|
|
|
91 |
chercherEtAfficherObservationsPageEnCours();
|
|
|
92 |
}
|
|
|
93 |
});
|
|
|
94 |
|
|
|
95 |
vue.getTriParDateDescendant().addClickHandler(new ClickHandler() {
|
|
|
96 |
|
|
|
97 |
@Override
|
|
|
98 |
public void onClick(ClickEvent arg0) {
|
|
|
99 |
InformationsRecherche informationsRechercheObservations = CacheClient.getInstance().getInformationsRechercheObservation();
|
|
|
100 |
informationsRechercheObservations.setTriParDate(ModeTri.TRI_DESCENDANT);
|
|
|
101 |
chercherEtAfficherObservationsPageEnCours();
|
|
|
102 |
}
|
|
|
103 |
});
|
445 |
benjamin |
104 |
}
|
|
|
105 |
|
|
|
106 |
public void chargerEtAfficherObservations(int debut, int fin) {
|
|
|
107 |
vue.startChargement();
|
|
|
108 |
vue.nettoyer();
|
|
|
109 |
ObservationsCallback callback = new ObservationsCallback() {
|
|
|
110 |
|
|
|
111 |
@Override
|
|
|
112 |
public void surObservationsRecues(ObservationServiceResultat observationsRecues) {
|
|
|
113 |
afficherObservations(observationsRecues);
|
|
|
114 |
}
|
|
|
115 |
};
|
|
|
116 |
serviceObs.getObservations(CacheClient.getInstance().getInformationsRechercheObservation(), debut, fin, callback);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
private void afficherObservations(ObservationServiceResultat observationServiceResultat) {
|
|
|
120 |
vue.nettoyer();
|
|
|
121 |
for (Observation observation : observationServiceResultat.getObservations()) {
|
|
|
122 |
ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation);
|
|
|
123 |
presenteur.go(vue.getZoneObservations());
|
|
|
124 |
}
|
|
|
125 |
vue.stopChargement();
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
private void creerWidgetPagination(int nbObservations) {
|
|
|
129 |
vue.getZonePaginationHaut().clear();
|
|
|
130 |
vue.getZonePaginationBas().clear();
|
|
|
131 |
PaginationPresenteur paginationPresenteurHaut = creerPresenteurPagination(nbObservations);
|
|
|
132 |
PaginationPresenteur paginationPresenteurBas = creerPresenteurPagination(nbObservations);
|
446 |
aurelien |
133 |
paginationPresenteurHaut.setGroupePagination("pagination_observations");
|
|
|
134 |
paginationPresenteurBas.setGroupePagination("pagination_observations");
|
445 |
benjamin |
135 |
paginationPresenteurHaut.go(vue.getZonePaginationHaut());
|
|
|
136 |
paginationPresenteurBas.go(vue.getZonePaginationBas());
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
private PaginationPresenteur creerPresenteurPagination(int nbObservations) {
|
|
|
140 |
PaginationPresenteur paginationPresenteurHaut = new PaginationPresenteur(new PaginationVue(), nbObservations, CacheClient.getInstance().getPasPagination(), CacheClient.getInstance().getPageCouranteRechercheObservations()) {
|
|
|
141 |
|
|
|
142 |
@Override
|
|
|
143 |
public void chargerElements(int debut, int fin) {
|
|
|
144 |
chargerEtAfficherObservations(debut, fin);
|
|
|
145 |
CacheClient.getInstance().setPageCouranteRechercheObservations(getPageCourante());
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
@Override
|
|
|
149 |
public void actualiserPasCache(int pas) {
|
|
|
150 |
CacheClient.getInstance().setPasPagination(pas);
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
};
|
|
|
154 |
return paginationPresenteurHaut;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
public void lancerRechercheEtCreerWidgetPagination() {
|
|
|
158 |
ObservationsCallback callback = new ObservationsCallback() {
|
|
|
159 |
@Override
|
|
|
160 |
public void surObservationsRecues(ObservationServiceResultat observationsRecues) {
|
|
|
161 |
creerWidgetPagination(observationsRecues.getNbTotalObservationsPourLaRecherche());
|
|
|
162 |
afficherObservations(observationsRecues);
|
|
|
163 |
}
|
|
|
164 |
};
|
|
|
165 |
|
|
|
166 |
int debut = (CacheClient.getInstance().getPageCouranteRechercheObservations() - 1) * CacheClient.getInstance().getPasPagination();
|
|
|
167 |
int fin = (CacheClient.getInstance().getPageCouranteRechercheObservations()) * CacheClient.getInstance().getPasPagination();
|
|
|
168 |
serviceObs.getObservations(CacheClient.getInstance().getInformationsRechercheObservation(), debut, fin, callback);
|
|
|
169 |
}
|
|
|
170 |
|
459 |
benjamin |
171 |
public void chercherEtAfficherObservationsPageEnCours() {
|
|
|
172 |
int debut = (CacheClient.getInstance().getPageCouranteRechercheObservations() - 1) * CacheClient.getInstance().getPasPagination();
|
|
|
173 |
int fin = (CacheClient.getInstance().getPageCouranteRechercheObservations()) * CacheClient.getInstance().getPasPagination();
|
|
|
174 |
chargerEtAfficherObservations(debut, fin);
|
|
|
175 |
}
|
|
|
176 |
|
445 |
benjamin |
177 |
}
|