Subversion Repositories eFlore/Applications.del

Rev

Rev 86 | Blame | Last modification | View Log | RSS feed

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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

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

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ObservationRechercheVue extends Composite {

        private final VerticalPanel mainPanel = new VerticalPanel();
        private final Panel panneauChargement = new FlowPanel();
        private final Panel taxaPanel = new FlowPanel();
        private final List<Panel> panneauxImages = new ArrayList<Panel>();
        private final HTML labelChargement = new HTML("<img src='img/wait.gif' />Contact du serveur du CEL...");
        private final HTML labelChercher = new HTML("<img src='img/search_icon.gif' />Search &nbsp;&nbsp;      taxon:");
        private int nbCol = 5;
        private final int nbImagesPerPage = 10;
        private int numImage = 0;
        private final TextBox textBox = new TextBox();

        // Annotation can be used to change the name of the associated xml file
        // @UiTemplate("ObservationRechercheVue.ui.xml")
        interface MyUiBinder extends UiBinder<Widget, ObservationRechercheVue> {
        }

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

        @UiField
        TextBox nomEspece;

        @UiField
        Panel panneauPagination;

        @UiField
        Button boutonChercher;

        @UiField
        FlexTable imageTable;

        // Constructeur
        protected ObservationRechercheVue() {

                initWidget(uiBinder.createAndBindUi(this));
                nomEspece.setFocus(true);
        }

        /**
         * Nettoie et remet à zéro les composants du panneau qui doivent l'être
         * */
        protected void nettoyer() {
                panneauPagination.clear();
                setNumImage(0);
                imageTable.clear();
                panneauxImages.clear();
        }

        protected void creerPanneauxObservation(List<Observation> observations) {

                for (int i = 0; i < observations.size(); i++) {
                        Panel imagePanel = new VerticalPanel();
                        panneauxImages.add(imagePanel);
                }

        }

        protected void afficherPanneauxImage(int first, int last) {
                imageTable.clear();

                int positionImage = 0;
                for (int numImage = first; numImage < last; numImage++) {
                        try {
                                Panel panel = panneauxImages.get(numImage);
                                imageTable.setWidget((positionImage) / nbCol, (positionImage) % nbCol, panel);
                        } catch (Exception e) {
                                break;
                        }

                        positionImage++;
                }
        }

        public void setNumImage(int numImage) {
                this.numImage = numImage;
        }

        protected void startChargement() {
                panneauChargement.setVisible(true);
        }

        protected void stopChargement() {
                panneauChargement.setVisible(false);
        }

        public FlexTable getImageTable() {
                return imageTable;
        }

        public int getNumImage() {
                return numImage;
        }

        public Panel getPanneauChargement() {
                return panneauChargement;
        }

        public HTML getLabelChercher() {
                return labelChercher;
        }

        public Panel getPanneauPagination() {
                return panneauPagination;
        }

        public int getNbImagesPerPage() {
                return nbImagesPerPage;
        }

        public TextBox getTextBox() {
                return nomEspece;
        }

        public Panel getPanel() {
                return mainPanel;
        }

        public List<Panel> getPanneauxImages() {
                return panneauxImages;
        }
        
        public Button getBoutonChercher() {
                return boutonChercher;
        }
}