Subversion Repositories eFlore/Applications.del

Compare Revisions

Regard whitespace Rev 1781 → Rev 1782

/trunk/src/org/tela_botanica/del/client/composants/formulaires/autocompletion/AutoCompletionComboBoxPresenteur.java
1,5 → 1,6
package org.tela_botanica.del.client.composants.formulaires.autocompletion;
 
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
13,6 → 14,7
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.IsWidget;
148,7 → 150,6
public void surReponseRequete(String requete, Response response) {
String[] valeurs = parserResultatRequete(response);
autoCompletionComboBoxVue.remplirListe(valeurs);
requeteOracle.setQuery(requete);
autoCompletionComboBoxVue.afficherSuggestions(requeteOracle, callBackOracle);
/trunk/src/org/tela_botanica/del/client/composants/formulaires/autocompletion/AutoCompletionComboBoxVue.java
1,10 → 1,11
package org.tela_botanica.del.client.composants.formulaires.autocompletion;
 
import org.tela_botanica.del.client.utils.TBSuggestOracle;
 
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
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;
11,7 → 12,7
 
public class AutoCompletionComboBoxVue extends LayoutPanel implements AutoCompletionComboBoxPresenteur.Vue {
 
MultiWordSuggestOracle msu = new MultiWordSuggestOracle();
TBSuggestOracle msu = new TBSuggestOracle();
SuggestBox suggestions = new SuggestBox(msu);
 
public AutoCompletionComboBoxVue() {
/trunk/src/org/tela_botanica/del/client/utils/TBSuggestOracle.java
New file
0,0 → 1,53
package org.tela_botanica.del.client.utils;
 
import java.util.ArrayList;
import java.util.List;
 
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle.MultiWordSuggestion;
import com.google.gwt.user.client.ui.SuggestOracle;
 
/**
* Un Oracle à suggestions qui retourne les résultats en respectant au mieux l'ordre de la
* liste de suggestions fournies
*
* @author mathias
*/
public class TBSuggestOracle extends SuggestOracle {
 
// On devrait gérer des objets qui contiennent le nn plutôt que de se baser uniquement sur des Strings
protected ArrayList<String> possibilites;
 
public TBSuggestOracle() {
this.possibilites = new ArrayList<String>();
}
 
public void clear() {
this.possibilites.clear();
}
 
public void add(String suggestion) {
this.possibilites.add(suggestion);
}
 
public void requestSuggestions(Request request, Callback callback) {
String query = request.getQuery().toLowerCase();
int limit = request.getLimit();
List<MultiWordSuggestion> retenus = new ArrayList<MultiWordSuggestion>();
 
for (String possibilite : this.possibilites) {
String possibiliteHtml = possibilite;
if (possibilite.toLowerCase().startsWith(query)) {
MultiWordSuggestion muWoSug = new MultiWordSuggestion(possibilite, possibiliteHtml);
retenus.add(muWoSug);
}
}
 
while (retenus.size() > limit) {
retenus.remove(retenus.size() - 1);
}
 
Response reponse = new Response(retenus);
callback.onSuggestionsReady(request, reponse);
}
}