23,8 → 23,11 |
// 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; |
48,7 → 51,6 |
|
private HashMap cache = new HashMap(); |
private boolean searching = false; |
private ResponseTextHandler responseTextHandler=null; |
|
protected PopupPanel choicesPopup = new PopupPanel(true); |
protected ListBox choices = new ListBox(); |
55,17 → 57,14 |
protected Vector items = new Vector(); |
protected boolean popupAdded = false; |
protected boolean visible = false; |
protected int current = -1; |
|
|
/** |
* Default Constructor |
* |
*/ |
public AutoCompleteAsyncTextBox(ResponseTextHandler rsp) |
public AutoCompleteAsyncTextBox() |
{ |
super(); |
responseTextHandler=rsp; |
this.addKeyboardListener(this); |
choices.addChangeListener(this); |
this.setStyleName("AutoCompleteAsyncTextBox"); |
97,13 → 96,35 |
/* |
* 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 + rematch, responseTextHandler ); |
HTTPRequest.asyncGet(this.searchUrl + match, |
new ResponseTextHandler(){ |
public void onCompletion(String str) { |
|
JSONValue jsonValue= JSONParser.parse(str); |
JSONArray jsonArray; |
JSONString jsonString; |
|
if ((jsonArray = jsonValue.isArray()) != null) { |
for (int i = 0; i < jsonArray.size(); ++i) { |
if ((jsonString = (jsonArray.get(i)).isString()) != null) { |
addItem(jsonString.stringValue()); |
} |
} |
} |
|
displayList(); |
|
|
|
} |
|
|
|
}); |
|
} |
} |
|
176,9 → 197,9 |
else { |
// Validation de l'entree : |
if (autoCompleteAsyncTextBoxListeners!= null) { |
autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this,current, this.getText()); |
autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this, this.getText()); |
} |
current=-1; |
|
this.setText(""); |
} |
|
203,13 → 224,13 |
{ |
items.clear(); |
|
/* if (getFromCache(text)!=null) { |
if (getFromCache(text)!=null) { |
items=getFromCache(text); |
displayList(); |
} |
else {*/ |
else { |
this.doFetchURL(text); |
//} |
} |
} |
} |
|
222,7 → 243,7 |
if(this.items.size() > 0) |
{ |
|
//addToCache(this.getText(),(Vector) items.clone()); |
addToCache(this.getText(),(Vector) items.clone()); |
|
choices.clear(); |
|
277,7 → 298,6 |
if(choices.getItemCount() > 0) |
{ |
this.setText(choices.getItemText(choices.getSelectedIndex())); |
current=choices.getSelectedIndex(); |
} |
|
visible=false; |