| 2 |
ddelon |
1 |
package org.tela_botanica.client;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
import java.util.EventListener;
|
|
|
6 |
|
|
|
7 |
|
| 4 |
ddelon |
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;
|
| 2 |
ddelon |
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 names that can be selected.
|
|
|
22 |
*/
|
|
|
23 |
|
| 4 |
ddelon |
24 |
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler {
|
| 2 |
ddelon |
25 |
|
| 4 |
ddelon |
26 |
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
|
| 2 |
ddelon |
27 |
private HorizontalPanel panel = new HorizontalPanel();
|
|
|
28 |
|
| 6 |
ddelon |
29 |
public NameAssistant(AutoCompleteAsyncTextBoxListener listener) {
|
| 2 |
ddelon |
30 |
|
| 4 |
ddelon |
31 |
autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/NameSearch/");
|
|
|
32 |
|
| 2 |
ddelon |
33 |
panel.add(autoCompletebox);
|
|
|
34 |
|
|
|
35 |
autoCompletebox.setWidth("100%");
|
|
|
36 |
initWidget(panel);
|
|
|
37 |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener);
|
|
|
38 |
|
|
|
39 |
}
|
|
|
40 |
|
| 4 |
ddelon |
41 |
public void onCompletion(String str) {
|
|
|
42 |
|
|
|
43 |
JSONValue jsonValue= JSONParser.parse(str);
|
|
|
44 |
JSONArray jsonArray;
|
|
|
45 |
JSONArray jsonArrayNested;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
49 |
for (int i = 0; i < jsonArray.size(); ++i) {
|
|
|
50 |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
|
| 7 |
ddelon |
51 |
autoCompletebox.addItem(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue());
|
| 4 |
ddelon |
52 |
}
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
autoCompletebox.displayList();
|
|
|
57 |
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
|
| 2 |
ddelon |
61 |
|
| 4 |
ddelon |
62 |
public String getServiceBaseUrl() {
|
|
|
63 |
|
|
|
64 |
Dictionary theme = Dictionary.getDictionary("Parameters");
|
|
|
65 |
return theme.get("serviceBaseUrl");
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
|
| 2 |
ddelon |
71 |
}
|
|
|
72 |
|