New file |
0,0 → 1,81 |
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 locations that can be selected. |
*/ |
|
public class LocationAssistant extends Composite implements EventListener, ResponseTextHandler { |
|
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this); |
private HorizontalPanel panel = new HorizontalPanel(); |
|
public LocationAssistant(AutoCompleteAsyncTextBoxListener listener) { |
|
// autoCompletebox.setFocus(true); |
autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/LocationSearch/"); |
|
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"); |
|
|
} |
|
|
} |
|