Subversion Repositories eFlore/Applications.del

Rev

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

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

import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
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 {

        MultiWordSuggestOracle msu = new MultiWordSuggestOracle();
        SuggestBox suggestions = new SuggestBox(msu);

        public AutoCompletionComboBoxVue() {
                add(suggestions);
                //TODO: voir avec greg si la taille doit être définie ici
                setHeight("25px");
                setWidth("100%");
        }
        
        @Override
        public SuggestBox getSuggestBox() {
                return suggestions;
        }
        
        public void remplirListe(String[] 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);
        }
}