Subversion Repositories eFlore/Applications.del

Rev

Rev 210 | Rev 478 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
148 benjamin 1
package org.tela_botanica.del.client.vues.rechercheimages.vote;
9 benjamin 2
 
3
import java.util.List;
4
 
5
import org.cobogw.gwt.user.client.ui.Rating;
423 gduche 6
import org.tela_botanica.del.client.i18n.I18n;
148 benjamin 7
import org.tela_botanica.del.client.modeles.VoteProtocole;
9 benjamin 8
 
66 gduche 9
import com.google.gwt.core.client.GWT;
423 gduche 10
import com.google.gwt.event.dom.client.ClickEvent;
11
import com.google.gwt.event.dom.client.ClickHandler;
12
import com.google.gwt.event.dom.client.HasClickHandlers;
66 gduche 13
import com.google.gwt.uibinder.client.UiBinder;
14
import com.google.gwt.uibinder.client.UiField;
423 gduche 15
import com.google.gwt.user.client.Window;
16
import com.google.gwt.user.client.ui.Button;
9 benjamin 17
import com.google.gwt.user.client.ui.Composite;
66 gduche 18
import com.google.gwt.user.client.ui.FocusPanel;
423 gduche 19
import com.google.gwt.user.client.ui.HasText;
66 gduche 20
import com.google.gwt.user.client.ui.Label;
21
import com.google.gwt.user.client.ui.Widget;
9 benjamin 22
 
14 benjamin 23
public class MoyenneVoteVue extends Composite {
9 benjamin 24
 
66 gduche 25
	// Annotation can be used to change the name of the associated xml file
26
	// @UiTemplate("MoyenneVoteVue.ui.xml")
27
	interface MyUiBinder extends UiBinder<Widget, MoyenneVoteVue> {
28
	}
29
 
30
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
423 gduche 31
	private Rating votes;
32
	private int valeurOrigine;
33
 
66 gduche 34
	@UiField
35
	FocusPanel voter;
36
 
37
	@UiField
38
	Label nbVotes;
39
 
423 gduche 40
	@UiField
41
	Button boutonVoter, boutonAnnuler;
42
 
148 benjamin 43
	protected MoyenneVoteVue(List<VoteProtocole> validationDatas) {
66 gduche 44
		initWidget(uiBinder.createAndBindUi(this));
423 gduche 45
 
46
		votes = new Rating(0, 5);
47
		votes.setReadOnly(false);
48
		voter.add(votes);
9 benjamin 49
 
423 gduche 50
		masquerBoutonAnnuler();
51
		masquerBoutonVoter();
52
		rafraichir(validationDatas);
53
	}
54
 
55
	public HasClickHandlers getBoutonVoter() {
56
		return boutonVoter;
57
	}
58
 
59
	public HasClickHandlers getBoutonAnnuler() {
60
		return boutonAnnuler;
61
	}
62
 
63
	public HasText getNbVotes() {
64
		return nbVotes;
65
	}
66
 
67
	public HasClickHandlers getVotes() {
68
		return votes;
69
	}
70
 
71
	public void afficherBoutonVoter() {
72
		boutonVoter.setVisible(true);
73
	}
74
 
75
	public void afficherBoutonAnnuler() {
76
		boutonAnnuler.setVisible(true);
77
	}
78
 
79
	public void masquerBoutonVoter() {
80
		boutonVoter.setVisible(false);
81
	}
82
 
83
	public void masquerBoutonAnnuler() {
84
		boutonAnnuler.setVisible(false);
85
	}
86
 
87
	public void afficherNbVotes () {
88
		nbVotes.setVisible(true);
89
	}
90
 
91
	public void masquerNbVotes () {
92
		nbVotes.setVisible(false);
93
	}
94
 
95
	public void reinitialiserVotes() {
96
		votes.setValue(valeurOrigine);
97
	}
98
 
99
	public void rafraichir(List<VoteProtocole> validationDatas) {
100
 
9 benjamin 101
		int meanVote = 0;
102
		int nbVote = 0;
148 benjamin 103
		for (VoteProtocole imageCelValidationData : validationDatas) {
9 benjamin 104
			meanVote += imageCelValidationData.getVote();
105
			nbVote++;
106
		}
423 gduche 107
		if (nbVote > 0) {
9 benjamin 108
			meanVote /= nbVote;
423 gduche 109
		}
110
		votes.setValue(nbVote);
111
		valeurOrigine = nbVote;
112
		nbVotes.setText(String.valueOf(validationDatas.size()) + " " +I18n.getVocabulary().nbVotes());
9 benjamin 113
	}
114
}