Subversion Repositories eFlore/Applications.del

Rev

Rev 237 | Rev 359 | 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.List;

import org.tela_botanica.del.client.cache.CacheClient;
import org.tela_botanica.del.client.modeles.Image;
import org.tela_botanica.del.client.modeles.VoteProtocole;
import org.tela_botanica.del.client.services.rest.ImageService;
import org.tela_botanica.del.client.services.rest.VoteProtocoleService;
import org.tela_botanica.del.client.utils.MockDatasource;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.IsWidget;

public class ComparaisonEflorePresenteur {

        public interface Vue extends IsWidget {
                public void chargerImagePrincipale(org.tela_botanica.del.client.modeles.Image image);

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

                public HasClickHandlers getScrollLeftImage();

                public HasClickHandlers getScrollRightImage();

                public int getCurrentIndexImages();
        }

        private Vue vue;
        private final VoteProtocoleService validationService = MockDatasource.getInstance();
        private final ImageService imageService = MockDatasource.getInstance();

        private Image imagePrincipale;
        private String nomTaxonComparaison;
        private List<org.tela_botanica.del.client.modeles.Image> imagesEflore;

        public ComparaisonEflorePresenteur(Vue vue) {
                this.vue = vue;
                this.imagePrincipale = CacheClient.getInstance().getImageCourante();
                this.nomTaxonComparaison = CacheClient.getInstance().getTaxonPourRechercheEflore();
        }

        public void go(HasWidgets composite) {
                composite.add(vue.asWidget());
                chargerValidationObservationPrincipale();
                vue.chargerImagePrincipale(imagePrincipale);
                chargerObservationsEflore();
                gererEvenements();
        }

        public void chargerValidationObservationPrincipale() {
                List<VoteProtocole> observationValidations = validationService.getVote(imagePrincipale.getIdImage());
                imagePrincipale.setVoteProtocoles(observationValidations);
        }

        public void chargerObservationsEflore() {
                imagesEflore = imageService.getImagesEfloreParTaxon(nomTaxonComparaison);
                vue.chargerImagesEflore(imagesEflore, 0);
        }

        private void gererEvenements() {
                vue.getScrollLeftImage().addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                                vue.chargerImagesEflore(imagesEflore, vue.getCurrentIndexImages() - 1);
                        }
                });

                vue.getScrollRightImage().addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                                vue.chargerImagesEflore(imagesEflore, vue.getCurrentIndexImages() + 1);
                        }
                });
        }

        public List<org.tela_botanica.del.client.modeles.Image> getImagesEflore() {
                return imagesEflore;
        }

}