Rev 27 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client;
import java.util.EventListener;
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.ResponseTextHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import org.tela_botanica.client.AutoCompleteAsyncTextBox;
/**
* Affiche une liste de nom pour selection. Son retournes le nom selectionne (gettext()) et un code associe (getvalue()).
*/
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler {
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
private HorizontalPanel panel = new HorizontalPanel();
private Mediator mediator = null;
public NameAssistant(Mediator med) {
mediator=med;
mediator.registerNameAssistant(this);
autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/");
panel.add(autoCompletebox);
autoCompletebox.setWidth("100%");
initWidget(panel);
autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator);
}
public void onCompletion(String str) {
JSONValue jsonValue= JSONParser.parse(str);
JSONArray jsonArray;
JSONArray jsonArrayNested;
if ((jsonArray = jsonValue.isArray()) != null) {
for (int i = 0; i < jsonArray.size(); ++i) {
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
autoCompletebox.addItem(Util.toCelString(((JSONString) jsonArrayNested.get(0)).toString()),Util.toCelString(((JSONString) jsonArrayNested.get(1)).toString()));
}
}
}
autoCompletebox.displayList();
}
public void setText(String str) {
autoCompletebox.setText(str);
}
public String getText() {
return autoCompletebox.getText();
}
public String getValue() {
return autoCompletebox.getValue();
}
public void setValue(String value) {
autoCompletebox.setValue(value);
}
}