Subversion Repositories eFlore/Applications.del

Rev

Rev 939 | Rev 1062 | 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.InformationsRecherche;
import org.tela_botanica.del.client.services.rest.ImageService;
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.Window;
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, 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();

                InformationsRecherche informationsRecherche = new InformationsRecherche();
                informationsRecherche.setTaxon(nomTaxonComparaison);

                ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {

                        @Override
                        public void surRetour(ImageServiceResultat imagesRecues) {
                                if (imagesRecues == null||imagesRecues.getImages()==null||imagesRecues.getImages().size()==0) {
                                        vue.stopChargement();
                                } else {
                                        setImagesEflore(imagesRecues.getImages());
                                        vue.chargerImagesEflore(imagesRecues.getImages(), 0);
                                        vue.stopChargement();
                                }
                        }

                        @Override
                        public void surErreur(String messageErreur) {
                                Window.alert(messageErreur);

                        }

                };

                imageService.getImagesParTaxon(informationsRecherche, 1, 100, 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;
        }

}