Subversion Repositories eFlore/Applications.del

Rev

Rev 284 | Rev 361 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.del.client.vues.comparaisoneflore;

import java.util.Date;
import java.util.List;

import org.tela_botanica.del.client.modeles.VoteProtocole;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
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.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ComparaisonEfloreVue extends Composite implements ComparaisonEflorePresenteur.Vue {

        interface MyUiBinder extends UiBinder<Widget, ComparaisonEfloreVue> {
        }

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

        @UiField
        Label nomAuteur, dateObservation, famille, motsClefs, validateurs, dateValidation, nomEspeceEflore, nomAuteurEflore, localiteEflore, dateObservationEflore;

        @UiField
        Image imagePrincipale, imageEflore, scrollLeftImage, scrollRightImage;

        public ComparaisonEfloreVue() {
                initWidget(uiBinder.createAndBindUi(this));
        }

        public void chargerImagePrincipale(org.tela_botanica.del.client.modeles.Image image) {

                // mots clefs
                String motsClefsConcatenes = "";
                for (String motClef : image.getObservation().getMotsClefs()) {
                        motsClefsConcatenes += motClef + ",";
                }
                motsClefsConcatenes = motsClefsConcatenes.subSequence(0, motsClefsConcatenes.lastIndexOf(",")).toString();

                // validateurs
                String validateursConcatenes = "";
                for (VoteProtocole observationValidation : image.getVoteProtocoles()) {
                        validateursConcatenes += observationValidation.getContributeur() + ", ";
                }
                try {
                        validateursConcatenes = validateursConcatenes.subSequence(0, validateursConcatenes.lastIndexOf(",")).toString();
                } catch (Exception e) {

                }

                // date derniere validation
                Date dateDerniereValidation = null;
                for (VoteProtocole observationValidation : image.getVoteProtocoles()) {
                        if (dateDerniereValidation == null) {
                                dateDerniereValidation = observationValidation.getDate();
                        } else if (dateDerniereValidation.before(observationValidation.getDate())) {
                                dateDerniereValidation = observationValidation.getDate();
                        }
                }

                motsClefs.setText(motsClefsConcatenes);
                nomAuteur.setText(image.getObservation().getAuteur());
                imagePrincipale.setUrl(image.getUrl());
                dateObservation.setText(image.getObservation().getDate());
                famille.setText(image.getObservation().getFamille());
                validateurs.setText(validateursConcatenes);

                if (dateDerniereValidation != null) {
                        dateValidation.setText(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).format(dateDerniereValidation));
                }

        }

        public void chargerImagesEflore(List<org.tela_botanica.del.client.modeles.Image> observationsEflore, int indexImage) {

                if (indexImage >= 0 && indexImage < observationsEflore.size()) {
                        currentIndexImages = indexImage;
                }

                org.tela_botanica.del.client.modeles.Image observationEflore = observationsEflore.get(currentIndexImages);

                nomEspeceEflore.setText(observationEflore.getObservation().getNomRetenu());
                nomAuteurEflore.setText(observationEflore.getObservation().getAuteur());
                imageEflore.setUrl(observationEflore.getUrl());
                dateObservationEflore.setText(observationEflore.getObservation().getDate());
                localiteEflore.setText(observationEflore.getObservation().getLocalite());

        }

        public void setScrollLeftImage(Image scrollLeftImage) {
                this.scrollLeftImage = scrollLeftImage;
        }

        public int getCurrentIndexImages() {
                return currentIndexImages;
        }

        @Override
        public HasClickHandlers getScrollLeftImage() {
                return scrollLeftImage;
        }

        @Override
        public HasClickHandlers getScrollRightImage() {
                return scrollRightImage;
        }

}