Subversion Repositories eFlore/Applications.del

Rev

Rev 352 | Rev 360 | 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.ImageServiceResultat;
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.services.rest.async.ImagesParTaxonCallback;
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;

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

        public ComparaisonEflorePresenteur(Vue vue, VoteProtocoleService voteProtocoleService, ImageService imageService) {
                this.vue = vue;
                this.imagePrincipale = CacheClient.getInstance().getImageCourante();
                this.nomTaxonComparaison = CacheClient.getInstance().getTaxonPourRechercheEflore();
                this.imageService=imageService;
        }

        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() {
                
                ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
                        
                        @Override
                        public void surImagesRecues(ImageServiceResultat imagesRecues) {
                                //CacheClient.getInstance().setImages(imagesRecues.getImages());
                                vue.chargerImagesEflore(imagesRecues.getImages(), 0);
                        }
                };
                
                imageService.getImagesEfloreParTaxon(nomTaxonComparaison, callback);
                
        }

        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;
        }

}