Subversion Repositories eFlore/Applications.del

Rev

Rev 148 | 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;
148 benjamin 6
import org.tela_botanica.del.client.modeles.VoteProtocole;
9 benjamin 7
 
66 gduche 8
import com.google.gwt.core.client.GWT;
9
import com.google.gwt.uibinder.client.UiBinder;
10
import com.google.gwt.uibinder.client.UiField;
9 benjamin 11
import com.google.gwt.user.client.ui.Composite;
66 gduche 12
import com.google.gwt.user.client.ui.FocusPanel;
13
import com.google.gwt.user.client.ui.Label;
14
import com.google.gwt.user.client.ui.Widget;
9 benjamin 15
 
14 benjamin 16
public class MoyenneVoteVue extends Composite {
9 benjamin 17
 
66 gduche 18
	// Annotation can be used to change the name of the associated xml file
19
	// @UiTemplate("MoyenneVoteVue.ui.xml")
20
	interface MyUiBinder extends UiBinder<Widget, MoyenneVoteVue> {
21
	}
22
 
23
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
24
 
25
	@UiField
26
	FocusPanel voter;
27
 
28
	@UiField
29
	Label nbVotes;
30
 
148 benjamin 31
	protected MoyenneVoteVue(List<VoteProtocole> validationDatas) {
66 gduche 32
		initWidget(uiBinder.createAndBindUi(this));
9 benjamin 33
 
34
		int meanVote = 0;
35
		int nbVote = 0;
148 benjamin 36
		for (VoteProtocole imageCelValidationData : validationDatas) {
9 benjamin 37
 
38
			meanVote += imageCelValidationData.getVote();
39
			nbVote++;
40
		}
41
		if (nbVote > 0)
42
			meanVote /= nbVote;
43
		Rating rating = new Rating(meanVote, 5);
44
		rating.setReadOnly(true);
66 gduche 45
		voter.add(rating);
9 benjamin 46
 
66 gduche 47
		nbVotes.setText(String.valueOf(validationDatas.size()));
9 benjamin 48
 
49
	}
50
}