10 |
ddelon |
1 |
package org.tela_botanica.client;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
import java.util.EventListener;
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
import com.google.gwt.json.client.JSONArray;
|
|
|
9 |
import com.google.gwt.json.client.JSONParser;
|
|
|
10 |
import com.google.gwt.json.client.JSONString;
|
|
|
11 |
import com.google.gwt.json.client.JSONValue;
|
|
|
12 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
13 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
14 |
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
import org.tela_botanica.client.AutoCompleteAsyncTextBox;
|
|
|
18 |
|
|
|
19 |
/**
|
28 |
ddelon |
20 |
* Affiche une liste de localite qui peuvent etre selectionnees, retourne la valeur de la localite selectionne et une code associe
|
|
|
21 |
* (gettext et getvalue pour le code associe)
|
11 |
ddelon |
22 |
* Utilise un assistant de saisie asynchrone.
|
10 |
ddelon |
23 |
*/
|
|
|
24 |
|
|
|
25 |
public class LocationAssistant extends Composite implements EventListener, ResponseTextHandler {
|
|
|
26 |
|
|
|
27 |
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
|
|
|
28 |
private HorizontalPanel panel = new HorizontalPanel();
|
|
|
29 |
|
11 |
ddelon |
30 |
private Mediator mediator = null;
|
|
|
31 |
|
|
|
32 |
public LocationAssistant(Mediator med) {
|
10 |
ddelon |
33 |
|
11 |
ddelon |
34 |
mediator=med;
|
|
|
35 |
mediator.registerLocationAssistant(this);
|
|
|
36 |
|
10 |
ddelon |
37 |
// autoCompletebox.setFocus(true);
|
11 |
ddelon |
38 |
autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/LocationSearch/");
|
10 |
ddelon |
39 |
|
|
|
40 |
panel.add(autoCompletebox);
|
|
|
41 |
|
|
|
42 |
autoCompletebox.setWidth("100%");
|
|
|
43 |
initWidget(panel);
|
26 |
ddelon |
44 |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator);
|
10 |
ddelon |
45 |
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public void onCompletion(String str) {
|
|
|
49 |
|
|
|
50 |
JSONValue jsonValue= JSONParser.parse(str);
|
|
|
51 |
JSONArray jsonArray;
|
|
|
52 |
JSONArray jsonArrayNested;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
56 |
for (int i = 0; i < jsonArray.size(); ++i) {
|
|
|
57 |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
|
|
|
58 |
autoCompletebox.addItem(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue());
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
autoCompletebox.displayList();
|
|
|
64 |
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public String getText() {
|
|
|
68 |
return autoCompletebox.getText();
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
11 |
ddelon |
72 |
public void setText(String str) {
|
|
|
73 |
autoCompletebox.setText(str);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
|
10 |
ddelon |
77 |
public String getValue() {
|
|
|
78 |
return autoCompletebox.getValue();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
}
|
|
|
83 |
|