Rev 8 | Rev 11 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client;
import java.util.EventListener;
import com.google.gwt.i18n.client.Dictionary;
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;
/**
* A composite that displays a list of names that can be selected.
*/
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler {
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
private HorizontalPanel panel = new HorizontalPanel();
public NameAssistant(AutoCompleteAsyncTextBoxListener listener) {
// autoCompletebox.setFocus(true);
autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/NameSearch/");
panel.add(autoCompletebox);
autoCompletebox.setWidth("100%");
initWidget(panel);
autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener);
}
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(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue());
}
}
}
autoCompletebox.displayList();
}
public String getText() {
return autoCompletebox.getText();
}
public String getValue() {
return autoCompletebox.getValue();
}
public String getServiceBaseUrl() {
Dictionary theme = Dictionary.getDictionary("Parameters");
return theme.get("serviceBaseUrl");
}
}