10 |
ddelon |
1 |
package org.tela_botanica.client;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
import java.util.EventListener;
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
import com.google.gwt.i18n.client.Dictionary;
|
|
|
9 |
import com.google.gwt.json.client.JSONArray;
|
|
|
10 |
import com.google.gwt.json.client.JSONParser;
|
|
|
11 |
import com.google.gwt.json.client.JSONString;
|
|
|
12 |
import com.google.gwt.json.client.JSONValue;
|
|
|
13 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
14 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
15 |
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
import org.tela_botanica.client.AutoCompleteAsyncTextBox;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* A composite that displays a list of locations that can be selected.
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
public class LocationAssistant extends Composite implements EventListener, ResponseTextHandler {
|
|
|
25 |
|
|
|
26 |
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
|
|
|
27 |
private HorizontalPanel panel = new HorizontalPanel();
|
|
|
28 |
|
|
|
29 |
public LocationAssistant(AutoCompleteAsyncTextBoxListener listener) {
|
|
|
30 |
|
|
|
31 |
// autoCompletebox.setFocus(true);
|
|
|
32 |
autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/LocationSearch/");
|
|
|
33 |
|
|
|
34 |
panel.add(autoCompletebox);
|
|
|
35 |
|
|
|
36 |
autoCompletebox.setWidth("100%");
|
|
|
37 |
initWidget(panel);
|
|
|
38 |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener);
|
|
|
39 |
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public void onCompletion(String str) {
|
|
|
43 |
|
|
|
44 |
JSONValue jsonValue= JSONParser.parse(str);
|
|
|
45 |
JSONArray jsonArray;
|
|
|
46 |
JSONArray jsonArrayNested;
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
50 |
for (int i = 0; i < jsonArray.size(); ++i) {
|
|
|
51 |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
|
|
|
52 |
autoCompletebox.addItem(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue());
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
autoCompletebox.displayList();
|
|
|
58 |
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public String getText() {
|
|
|
62 |
return autoCompletebox.getText();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
public String getValue() {
|
|
|
67 |
return autoCompletebox.getValue();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
public String getServiceBaseUrl() {
|
|
|
72 |
|
|
|
73 |
Dictionary theme = Dictionary.getDictionary("Parameters");
|
|
|
74 |
return theme.get("serviceBaseUrl");
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
}
|
|
|
81 |
|