480 |
benjamin |
1 |
package org.tela_botanica.del.client.vues.rechercheobservations.resultats.observationdeterminations;
|
436 |
benjamin |
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
901 |
aurelien |
5 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlayDefilanteVue;
|
|
|
6 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlaySimplePresenteur;
|
|
|
7 |
import org.tela_botanica.del.client.composants.votes.details.DetailListeVotesDeterminationPresenteur;
|
|
|
8 |
import org.tela_botanica.del.client.composants.votes.details.DetailListeVotesDeterminationVue;
|
436 |
benjamin |
9 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
882 |
aurelien |
10 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
|
|
11 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
|
|
12 |
import org.tela_botanica.del.client.navigation.evenement.voteDetermination.EvenementVoteDetermination;
|
|
|
13 |
import org.tela_botanica.del.client.navigation.evenement.voteDetermination.GestionnaireEvenementVoteDetermination;
|
480 |
benjamin |
14 |
import org.tela_botanica.del.client.vues.rechercheobservations.resultats.votes.DetailVoteObservationPresenteur;
|
|
|
15 |
import org.tela_botanica.del.client.vues.rechercheobservations.resultats.votes.DetailVoteObservationVue;
|
436 |
benjamin |
16 |
|
901 |
aurelien |
17 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
18 |
import com.google.gwt.event.dom.client.ClickHandler;
|
436 |
benjamin |
19 |
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
20 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
21 |
import com.google.gwt.user.client.ui.IsWidget;
|
|
|
22 |
|
|
|
23 |
public class ObservationDeterminationPresenteur {
|
|
|
24 |
|
|
|
25 |
public abstract interface Vue extends IsWidget {
|
652 |
aurelien |
26 |
public void viderTableau();
|
901 |
aurelien |
27 |
public void ajouterElementAuTableauProposition(LignePropositionVue vue);
|
882 |
aurelien |
28 |
void setNbVotes(int index, int nbVotes);
|
|
|
29 |
void setNbCommentaires(int index, int nbCommentaires);
|
901 |
aurelien |
30 |
int getIndexLigneProposition(LignePropositionVue lignePropositionVue);
|
436 |
benjamin |
31 |
}
|
|
|
32 |
|
|
|
33 |
private Vue vue;
|
|
|
34 |
|
|
|
35 |
private List<PropositionDetermination> propositions;
|
901 |
aurelien |
36 |
FenetreOverlaySimplePresenteur fenetreOverlaySimplePresenteur;
|
436 |
benjamin |
37 |
|
|
|
38 |
public ObservationDeterminationPresenteur(Vue vue, List<PropositionDetermination> propositions) {
|
|
|
39 |
this.propositions = propositions;
|
|
|
40 |
this.vue = vue;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public void chargerPropositions() {
|
652 |
aurelien |
44 |
vue.viderTableau();
|
436 |
benjamin |
45 |
for (PropositionDetermination proposition : propositions) {
|
866 |
aurelien |
46 |
//TODO: afficher nombre de votes total et mettre à jour en cas de vote
|
436 |
benjamin |
47 |
HTMLPanel panneau = new HTMLPanel("");
|
|
|
48 |
DetailVoteObservationPresenteur presenteurVote = new DetailVoteObservationPresenteur(new DetailVoteObservationVue(), proposition);
|
|
|
49 |
presenteurVote.go(panneau);
|
882 |
aurelien |
50 |
int nbCommentaires = proposition.getListeCommentaires().size();
|
|
|
51 |
int nbVotes = proposition.getVotesDeterminations().size();
|
901 |
aurelien |
52 |
|
|
|
53 |
LignePropositionVue ligneProposition = new LignePropositionVue(panneau, nbVotes, nbCommentaires);
|
|
|
54 |
gererEvenementClicNbVotes(ligneProposition);
|
|
|
55 |
vue.ajouterElementAuTableauProposition(ligneProposition);
|
436 |
benjamin |
56 |
}
|
882 |
aurelien |
57 |
|
|
|
58 |
BusEvenementiel.getInstance().addHandler(EvenementVoteDetermination.TYPE, new GestionnaireEvenementVoteDetermination() {
|
|
|
59 |
@Override
|
|
|
60 |
public void onVoteDetermination(VoteDetermination event) {
|
|
|
61 |
surVoteDetermination(event);
|
|
|
62 |
}
|
|
|
63 |
});
|
436 |
benjamin |
64 |
}
|
602 |
aurelien |
65 |
|
901 |
aurelien |
66 |
public void gererEvenementClicNbVotes(final LignePropositionVue lignePropositionVue) {
|
|
|
67 |
lignePropositionVue.getZoneNbVotes().addClickHandler(new ClickHandler() {
|
|
|
68 |
@Override
|
|
|
69 |
public void onClick(ClickEvent event) {
|
|
|
70 |
fenetreOverlaySimplePresenteur = new FenetreOverlaySimplePresenteur(new FenetreOverlayDefilanteVue());
|
|
|
71 |
DetailListeVotesDeterminationPresenteur detailListeVotesDeterminationPresenteur = new DetailListeVotesDeterminationPresenteur(new DetailListeVotesDeterminationVue());
|
|
|
72 |
int indexProposition = vue.getIndexLigneProposition(lignePropositionVue);
|
|
|
73 |
fenetreOverlaySimplePresenteur.ouvrirFenetreModale(detailListeVotesDeterminationPresenteur);
|
|
|
74 |
detailListeVotesDeterminationPresenteur.afficherVotes(propositions.get(indexProposition));
|
|
|
75 |
}
|
|
|
76 |
});
|
|
|
77 |
}
|
|
|
78 |
|
602 |
aurelien |
79 |
public void setPropositions(List<PropositionDetermination> propositions) {
|
|
|
80 |
this.propositions = propositions;
|
|
|
81 |
chargerPropositions();
|
|
|
82 |
}
|
436 |
benjamin |
83 |
|
|
|
84 |
public void go(HasWidgets composite) {
|
|
|
85 |
composite.add(vue.asWidget());
|
|
|
86 |
chargerPropositions();
|
|
|
87 |
}
|
882 |
aurelien |
88 |
|
|
|
89 |
public void surVoteDetermination(VoteDetermination voteDetermination) {
|
|
|
90 |
int indexProposition = propositions.indexOf(voteDetermination.getPropositionDetermination());
|
|
|
91 |
if(indexProposition != -1) {
|
|
|
92 |
vue.setNbVotes(indexProposition, voteDetermination.getPropositionDetermination().getVotesDeterminations().size());
|
|
|
93 |
}
|
|
|
94 |
}
|
436 |
benjamin |
95 |
|
|
|
96 |
}
|