Subversion Repositories eFlore/Applications.del

Rev

Rev 14 | Blame | Last modification | View Log | RSS feed

package org.tela_botanica.del.client.vues.rechercheobservations.vote;

import java.util.List;

import org.cobogw.gwt.user.client.ui.Rating;
import org.tela_botanica.del.client.modeles.ObservationValidation;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MoyenneVoteVue extends Composite {

        // Annotation can be used to change the name of the associated xml file
        // @UiTemplate("MoyenneVoteVue.ui.xml")
        interface MyUiBinder extends UiBinder<Widget, MoyenneVoteVue> {
        }

        private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

        private Panel mainPanel = new VerticalPanel();

        @UiField
        FocusPanel voter;

        @UiField
        Label nbVotes;

        protected MoyenneVoteVue(List<ObservationValidation> validationDatas) {
                initWidget(uiBinder.createAndBindUi(this));

                int meanVote = 0;
                int nbVote = 0;
                for (ObservationValidation imageCelValidationData : validationDatas) {

                        meanVote += imageCelValidationData.getVote();
                        nbVote++;
                }
                if (nbVote > 0)
                        meanVote /= nbVote;
                Rating rating = new Rating(meanVote, 5);
                rating.setReadOnly(true);
                voter.add(rating);

                nbVotes.setText(String.valueOf(validationDatas.size()));

        }
}