Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
602 aurelien 1
package org.tela_botanica.del.client.composants.formulaires.autocompletion;
261 aurelien 2
 
1886 mathias 3
import org.tela_botanica.del.client.utils.InfosNomPourAutocompletion;
1782 mathias 4
import org.tela_botanica.del.client.utils.TBSuggestOracle;
5
 
1957 aurelien 6
import com.google.gwt.core.client.Callback;
450 aurelien 7
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
457 aurelien 8
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
1957 aurelien 9
import com.google.gwt.user.client.Event;
450 aurelien 10
import com.google.gwt.user.client.ui.HasWidgets;
261 aurelien 11
import com.google.gwt.user.client.ui.LayoutPanel;
12
import com.google.gwt.user.client.ui.SuggestBox;
13
import com.google.gwt.user.client.ui.SuggestOracle;
457 aurelien 14
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
261 aurelien 15
 
450 aurelien 16
public class AutoCompletionComboBoxVue extends LayoutPanel implements AutoCompletionComboBoxPresenteur.Vue {
261 aurelien 17
 
1782 mathias 18
	TBSuggestOracle msu = new TBSuggestOracle();
261 aurelien 19
	SuggestBox suggestions = new SuggestBox(msu);
1957 aurelien 20
	Callback<String, String> surCopierColler = null;
261 aurelien 21
 
22
	public AutoCompletionComboBoxVue() {
23
		add(suggestions);
386 aurelien 24
		setHeight("25px");
261 aurelien 25
		setWidth("100%");
1957 aurelien 26
		sinkEvents(Event.ONPASTE);
261 aurelien 27
	}
28
 
1099 aurelien 29
	@Override
261 aurelien 30
	public SuggestBox getSuggestBox() {
31
		return suggestions;
32
	}
33
 
1886 mathias 34
	public void remplirListe(InfosNomPourAutocompletion[] listePropositions) {
261 aurelien 35
 
36
		msu.clear();
37
		for (int i = 0; i < listePropositions.length; i++) {
38
			msu.add(listePropositions[i]);
39
		}
40
	}
41
 
450 aurelien 42
	@Override
261 aurelien 43
	public void afficherSuggestions(SuggestOracle.Request requeteOracle, SuggestOracle.Callback callBackOracle) {
44
		msu.requestSuggestions(requeteOracle, callBackOracle);
45
	}
416 gduche 46
 
450 aurelien 47
	@Override
48
	public void afficherListeDeroulante() {
49
		suggestions.showSuggestionList();
50
	}
51
 
416 gduche 52
	public void nettoyer() {
53
		suggestions.setText("");
54
	}
55
 
56
	public void setValeur(String taxon) {
457 aurelien 57
		suggestions.setValue(taxon);
416 gduche 58
	}
450 aurelien 59
 
60
	@Override
61
	public HasKeyPressHandlers getSuggestBoxHasKeyPressHandlers() {
62
		return suggestions;
63
	}
457 aurelien 64
 
65
	@Override
66
	public HasSelectionHandlers<Suggestion> getSuggestBoxHasSelectionChangeHandlers() {
67
		return suggestions;
68
	}
450 aurelien 69
 
70
	@Override
71
	public String getValeur() {
72
		return suggestions.getText();
73
	}
74
 
75
	@Override
76
	public void ajouterVue(HasWidgets composite) {
77
		composite.add(this.asWidget());
78
	}
1099 aurelien 79
 
80
	@Override
81
	public void afficherStyleErreur(String styleErreur) {
82
		suggestions.addStyleName(styleErreur);
83
	}
84
 
85
	@Override
86
	public void supprimerStyleErreur(String styleErreur) {
87
		suggestions.removeStyleName(styleErreur);
88
	}
1957 aurelien 89
 
90
	public void onBrowserEvent(Event event) {
91
	    super.onBrowserEvent(event);
92
	    switch (event.getTypeInt()) {
93
	        case Event.ONPASTE: {
94
	        	if(surCopierColler != null) {
95
	        		surCopierColler.onSuccess(suggestions.getValueBox().getValue());
96
	        	}
97
	        }
98
	    }
99
	}
100
 
101
	@Override
102
	public void setHandlerCopierColler(Callback<String, String> cb) {
103
		surCopierColler = cb;
104
	}
261 aurelien 105
}