Subversion Repositories eFlore/Applications.del

Rev

Rev 1886 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.del.client.composants.formulaires.autocompletion;

import org.tela_botanica.del.client.utils.InfosNomPourAutocompletion;
import org.tela_botanica.del.client.utils.TBSuggestOracle;

import com.google.gwt.core.client.Callback;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;

public class AutoCompletionComboBoxVue extends LayoutPanel implements AutoCompletionComboBoxPresenteur.Vue {

        TBSuggestOracle msu = new TBSuggestOracle();
        SuggestBox suggestions = new SuggestBox(msu);
        Callback<String, String> surCopierColler = null;

        public AutoCompletionComboBoxVue() {
                add(suggestions);
                setHeight("25px");
                setWidth("100%");
                sinkEvents(Event.ONPASTE);
        }
        
        @Override
        public SuggestBox getSuggestBox() {
                return suggestions;
        }
        
        public void remplirListe(InfosNomPourAutocompletion[] listePropositions) {
                
                msu.clear();
                for (int i = 0; i < listePropositions.length; i++) {
                        msu.add(listePropositions[i]);
                }
        }
        
        @Override
        public void afficherSuggestions(SuggestOracle.Request requeteOracle, SuggestOracle.Callback callBackOracle) {
                msu.requestSuggestions(requeteOracle, callBackOracle);
        }
        
        @Override 
        public void afficherListeDeroulante() {
                suggestions.showSuggestionList();
        }
        
        public void nettoyer() {
                suggestions.setText("");
        }
        
        public void setValeur(String taxon) {
                suggestions.setValue(taxon);
        }

        @Override
        public HasKeyPressHandlers getSuggestBoxHasKeyPressHandlers() {
                return suggestions;
        }
        
        @Override
        public HasSelectionHandlers<Suggestion> getSuggestBoxHasSelectionChangeHandlers() {
                return suggestions;
        }

        @Override
        public String getValeur() {
                return suggestions.getText();
        }

        @Override
        public void ajouterVue(HasWidgets composite) {
                composite.add(this.asWidget());
        }

        @Override
        public void afficherStyleErreur(String styleErreur) {
                suggestions.addStyleName(styleErreur);
        }

        @Override
        public void supprimerStyleErreur(String styleErreur) {
                suggestions.removeStyleName(styleErreur);
        }
        
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            switch (event.getTypeInt()) {
                case Event.ONPASTE: {
                        if(surCopierColler != null) {
                                surCopierColler.onSuccess(suggestions.getValueBox().getValue());
                        }
                }
            }
        }

        @Override
        public void setHandlerCopierColler(Callback<String, String> cb) {
                surCopierColler = cb;
        }
}