Subversion Repositories eFlore/Archives.cel-v1

Compare Revisions

Ignore whitespace Rev 3 → Rev 4

/trunk/src/org/tela_botanica/client/AutoCompleteAsyncTextBox.java
23,11 → 23,8
// TODO : traiter latence (augmenter en fonction rapidité saisie + texte vide)
// TODO : traiter Tab (selection)
// TODO : revoir traitement keyup, keydown
// TODO : reactiver le cache (du design à revoir dans ce cas la)
 
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;
import com.google.gwt.user.client.ui.ChangeListener;
51,6 → 48,7
private HashMap cache = new HashMap();
private boolean searching = false;
private ResponseTextHandler responseTextHandler=null;
protected PopupPanel choicesPopup = new PopupPanel(true);
protected ListBox choices = new ListBox();
57,14 → 55,17
protected Vector items = new Vector();
protected boolean popupAdded = false;
protected boolean visible = false;
protected int current = -1;
/**
* Default Constructor
*
*/
public AutoCompleteAsyncTextBox()
public AutoCompleteAsyncTextBox(ResponseTextHandler rsp)
{
super();
responseTextHandler=rsp;
this.addKeyboardListener(this);
choices.addChangeListener(this);
this.setStyleName("AutoCompleteAsyncTextBox");
96,35 → 97,13
/*
* Here we fetch the URL and call the handler
*/
String rematch=match.replaceFirst(" ","/");
if (this.searchUrl!=null && searching==false) {
searching=true;
HTTPRequest.asyncGet(this.searchUrl + match,
new ResponseTextHandler(){
public void onCompletion(String str) {
JSONValue jsonValue= JSONParser.parse(str);
JSONArray jsonArray;
JSONString jsonString;
HTTPRequest.asyncGet(this.searchUrl + rematch, responseTextHandler );
 
if ((jsonArray = jsonValue.isArray()) != null) {
for (int i = 0; i < jsonArray.size(); ++i) {
if ((jsonString = (jsonArray.get(i)).isString()) != null) {
addItem(jsonString.stringValue());
}
}
}
 
displayList();
 
}
 
});
 
}
}
 
197,9 → 176,9
else {
// Validation de l'entree :
if (autoCompleteAsyncTextBoxListeners!= null) {
autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this, this.getText());
autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this,current, this.getText());
}
current=-1;
this.setText("");
}
224,13 → 203,13
{
items.clear();
if (getFromCache(text)!=null) {
/* if (getFromCache(text)!=null) {
items=getFromCache(text);
displayList();
}
else {
else {*/
this.doFetchURL(text);
}
//}
}
}
243,7 → 222,7
if(this.items.size() > 0)
{
addToCache(this.getText(),(Vector) items.clone());
//addToCache(this.getText(),(Vector) items.clone());
choices.clear();
298,6 → 277,7
if(choices.getItemCount() > 0)
{
this.setText(choices.getItemText(choices.getSelectedIndex()));
current=choices.getSelectedIndex();
}
 
visible=false;