901 |
aurelien |
1 |
package org.tela_botanica.del.client.composants.votes.details;
|
|
|
2 |
|
|
|
3 |
import java.util.Iterator;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
import java.util.Map;
|
|
|
6 |
|
|
|
7 |
import org.tela_botanica.del.client.i18n.I18n;
|
1102 |
gduche |
8 |
import org.tela_botanica.del.client.modeles.MoyenneVote;
|
901 |
aurelien |
9 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
|
|
10 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
1102 |
gduche |
11 |
import org.tela_botanica.del.client.services.CalculVoteDeterminationService;
|
901 |
aurelien |
12 |
|
|
|
13 |
import com.google.gwt.core.client.GWT;
|
|
|
14 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
15 |
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
|
|
16 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
17 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
18 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
19 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
20 |
import com.google.gwt.user.client.ui.HTML;
|
|
|
21 |
import com.google.gwt.user.client.ui.HTMLPanel;
|
1102 |
gduche |
22 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
23 |
import com.google.gwt.user.client.ui.Label;
|
901 |
aurelien |
24 |
import com.google.gwt.user.client.ui.Panel;
|
|
|
25 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
26 |
|
|
|
27 |
public class DetailListeVotesDeterminationVue extends Composite implements DetailListeVotesDeterminationPresenteur.Vue {
|
|
|
28 |
|
|
|
29 |
private static DetailListeVotesDeterminationVueUIiBinder uiBinder = GWT.create(DetailListeVotesDeterminationVueUIiBinder.class);
|
|
|
30 |
|
|
|
31 |
interface DetailListeVotesDeterminationVueUIiBinder extends UiBinder<Widget, DetailListeVotesDeterminationVue> {
|
|
|
32 |
};
|
|
|
33 |
|
|
|
34 |
@UiField
|
1102 |
gduche |
35 |
HTMLPanel titre, auteur, aucuneDonnees, detailVotePour, detailVoteContre;
|
901 |
aurelien |
36 |
|
|
|
37 |
@UiField
|
1102 |
gduche |
38 |
Label scorePour, scoreContre;
|
|
|
39 |
|
|
|
40 |
@UiField
|
901 |
aurelien |
41 |
Panel panneauChargement;
|
|
|
42 |
|
|
|
43 |
public DetailListeVotesDeterminationVue() {
|
|
|
44 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
@Override
|
|
|
48 |
public void afficherVotes(PropositionDetermination propositionDetermination) {
|
|
|
49 |
|
|
|
50 |
HTML htmlTitre = new HTML(propositionDetermination.getEspece());
|
|
|
51 |
titre.add(htmlTitre);
|
|
|
52 |
|
973 |
aurelien |
53 |
HTML htmlAuteur = new HTML(I18n.getVocabulary().proposePar()+propositionDetermination.getAuteur());
|
|
|
54 |
auteur.add(htmlAuteur);
|
|
|
55 |
|
901 |
aurelien |
56 |
Map<String, VoteDetermination> listeVotes = propositionDetermination.getVotesDeterminations();
|
|
|
57 |
|
1102 |
gduche |
58 |
int votesAnonymesPour = 0;
|
|
|
59 |
int votesAnonymesContre = 0;
|
|
|
60 |
MoyenneVote moyenne = CalculVoteDeterminationService.calculerVoteDetermination(propositionDetermination);
|
|
|
61 |
scorePour.setText(String.valueOf(moyenne.getScore()) + '%');
|
|
|
62 |
scoreContre.setText(String.valueOf(100 - moyenne.getScore()) + '%');
|
|
|
63 |
|
901 |
aurelien |
64 |
for (Iterator<String> iterator = listeVotes.keySet().iterator(); iterator.hasNext();) {
|
1102 |
gduche |
65 |
VoteDetermination voteDetermination = listeVotes.get(iterator.next());
|
|
|
66 |
if (voteDetermination.getVote() == 1) {
|
|
|
67 |
//Votes pour
|
|
|
68 |
if (voteDetermination.getAuteur() != null) {
|
|
|
69 |
ajouterVote(voteDetermination, detailVotePour);
|
|
|
70 |
} else {
|
|
|
71 |
votesAnonymesPour++;
|
|
|
72 |
}
|
|
|
73 |
} else {
|
|
|
74 |
//Votes contre
|
|
|
75 |
if (voteDetermination.getAuteur() != null) {
|
|
|
76 |
ajouterVote(voteDetermination, detailVoteContre);
|
|
|
77 |
} else {
|
|
|
78 |
votesAnonymesContre++;
|
|
|
79 |
}
|
|
|
80 |
}
|
901 |
aurelien |
81 |
}
|
|
|
82 |
|
1102 |
gduche |
83 |
if (votesAnonymesPour > 0) {
|
|
|
84 |
LigneVotePresenteur presenteurVote= new LigneVotePresenteur(new LigneVoteVue(), votesAnonymesPour);
|
|
|
85 |
presenteurVote.go(detailVotePour);
|
901 |
aurelien |
86 |
}
|
|
|
87 |
|
1102 |
gduche |
88 |
if (votesAnonymesContre > 0) {
|
|
|
89 |
LigneVotePresenteur presenteurVote= new LigneVotePresenteur(new LigneVoteVue(), votesAnonymesContre);
|
|
|
90 |
presenteurVote.go(detailVoteContre);
|
901 |
aurelien |
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
1102 |
gduche |
94 |
public void ajouterVote(VoteDetermination vote, HasWidgets panel) {
|
|
|
95 |
LigneVotePresenteur presenteurVote = new LigneVotePresenteur(new LigneVoteVue(), vote);
|
|
|
96 |
presenteurVote.go(panel);
|
|
|
97 |
}
|
|
|
98 |
|
901 |
aurelien |
99 |
@Override
|
|
|
100 |
public void startChargement() {
|
|
|
101 |
panneauChargement.setHeight((this.getOffsetHeight()/2)+"px");
|
|
|
102 |
panneauChargement.setWidth((this.getOffsetWidth()/2)+"px");
|
|
|
103 |
panneauChargement.setVisible(true);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
@Override
|
|
|
107 |
public void stopChargement() {
|
|
|
108 |
panneauChargement.setVisible(false);
|
|
|
109 |
}
|
909 |
aurelien |
110 |
|
|
|
111 |
@Override
|
|
|
112 |
public void afficherAucuneDonnees() {
|
|
|
113 |
aucuneDonnees.setVisible(true);
|
|
|
114 |
}
|
901 |
aurelien |
115 |
}
|