Subversion Repositories eFlore/Applications.del

Rev

Rev 361 | Rev 939 | 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.services.rest.ImageService;
import org.tela_botanica.del.client.services.rest.VoteProtocoleService;
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;

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();
                
                public void startChargement() ;

                public void stopChargement();
        }

        private Vue vue;
        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());
                vue.chargerImagePrincipale(imagePrincipale);
                chargerObservationsEflore();
                gererEvenements();
        }

        public void chargerObservationsEflore() {
                
                vue.startChargement();

                ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {

                        @Override
                        public void surImagesRecues(ImageServiceResultat imagesRecues) {
                                setImagesEflore(imagesRecues.getImages());
                                vue.chargerImagesEflore(imagesRecues.getImages(), 0);
                                vue.stopChargement();
                        }
                };

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

        public void setImagesEflore(List<org.tela_botanica.del.client.modeles.Image> imagesEflore) {
                this.imagesEflore = imagesEflore;
        }

}