Subversion Repositories eFlore/Applications.del

Rev

Rev 407 | Rev 419 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.del.client.composants.moteurrecherche;

import org.tela_botanica.del.client.i18n.I18n;
import org.tela_botanica.del.client.modeles.InformationsRecherche;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
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.HasText;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class MoteurRechercheVue extends Composite implements MoteurRecherchePresenteur.Vue {

        interface Binder extends UiBinder<Widget, MoteurRechercheVue> {
        }

        private static Binder uiBinder = GWT.create(Binder.class);
        private String labelRecherche = "";

        @UiField
        Panel rechercheAvancee,taxon;
        @UiField
        Label lienRechercheAvancee, recherchePrecedente;
        @UiField
        Button boutonRecherche, boutonRechercheAvancee, boutonFermer;
        @UiField
        TextBox recherchePrincipale, departement, commune, famille, genre, tag, motCle, auteur, date;

        public MoteurRechercheVue(String labelRecherche) {
                initWidget(uiBinder.createAndBindUi(this));
                this.labelRecherche = labelRecherche;
                recherchePrincipale.setText(labelRecherche);
                rechercheAvancee.setVisible(false);
        }

        public String getLabelRecherche() {
                return labelRecherche;
        }

        @Override
        public HasClickHandlers getLienRechercheAvancee() {
                return lienRechercheAvancee;
        }

        @Override
        public void basculerAffichageZoneCache() {
                rechercheAvancee.setVisible(!rechercheAvancee.isVisible());
        }

        @Override
        public HasClickHandlers getBoutonRechercheSimple() {
                return boutonRecherche;
        }
        
        @Override
        public HasClickHandlers getBoutonFermer() {
                return boutonFermer;
        }

        @Override
        public HasClickHandlers getBoutonRechercheAvancee() {
                return boutonRechercheAvancee;
        }

        @Override
        public HasKeyPressHandlers getChampSaisie() {
                return recherchePrincipale;
        }

        @Override
        public String getValeurRechercheSimple() {
                return recherchePrincipale.getText();
        }

        @Override
        public HasClickHandlers getChampSaisieCliquable() {
                return recherchePrincipale;
        }

        @Override
        public void setValeurRechercheSimple(String valeurRecherche) {
                recherchePrincipale.setText(valeurRecherche);
        }

        public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche) {
                getAuteur().setText(informationsRecherche.getAuteur());
                getCommune().setText(informationsRecherche.getCommune());
                getDate().setText(informationsRecherche.getDate());
                getDepartement().setText(informationsRecherche.getDepartement());
                getFamille().setText(informationsRecherche.getFamille());
                getMotCle().setText(informationsRecherche.getMotClef());

                
                if (informationsRecherche.getRechercheLibre() != null && !informationsRecherche.getRechercheLibre().equals("")) {
                        getRecherchePrincipale().setText(informationsRecherche.getRechercheLibre());
                }

                afficherLigneInfoRecherche(informationsRecherche);
        }

        /**
         * Affiche la ligne d'en tête montrant les elements de la requête à
         * l'utilisateur
         * 
         * @param informationRecherche
         */
        private void afficherLigneInfoRecherche(InformationsRecherche informationRecherche) {

                StringBuffer texteRecherchePrecedente = new StringBuffer();
                if (informationRecherche.getRechercheLibre()!=null&&!informationRecherche.getRechercheLibre().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().rechercheLibre() + ":" + informationRecherche.getRechercheLibre() + " ");
                }
                if (!informationRecherche.getAuteur().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().auteur() + ":" + informationRecherche.getAuteur() + " ");
                }
                if (!informationRecherche.getCommune().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().commune() + ":" + informationRecherche.getCommune() + " ");
                }
                if (!informationRecherche.getDate().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().date() + ":" + informationRecherche.getDate() + " ");
                }
                if (!informationRecherche.getDepartement().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().departement() + ":" + informationRecherche.getDepartement() + " ");
                }
                if (!informationRecherche.getFamille().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().famille() + ":" + informationRecherche.getFamille() + " ");
                }
                if (!informationRecherche.getGenre().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().genre() + ":" + informationRecherche.getGenre() + " ");
                }
                if (!informationRecherche.getMotClef().equals("")) {
                        texteRecherchePrecedente.append(I18n.getVocabulary().mot_clef() + ":" + informationRecherche.getMotClef() + " ");
                }
                recherchePrecedente.setText(texteRecherchePrecedente.toString());
        }

        public HasText getRecherchePrincipale() {
                return recherchePrincipale;
        }

        public HasText getDepartement() {
                return departement;
        }

        public HasText getCommune() {
                return commune;
        }

        public HasWidgets getTaxon() {
                return taxon;
        }

        public HasText getFamille() {
                return famille;
        }

        public HasText getGenre() {
                return genre;
        }

        public HasText getTag() {
                return tag;
        }

        public HasText getMotCle() {
                return motCle;
        }

        public HasText getAuteur() {
                return auteur;
        }

        public HasText getDate() {
                return date;
        }

        public void focusSaisie() {
                this.recherchePrincipale.setFocus(true);
        }
}