Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 2 | Rev 6 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
4 ddelon 17
import java.util.Vector;
2 ddelon 18
 
4 ddelon 19
 
2 ddelon 20
import org.tela_botanica.client.AutoCompleteAsyncTextBox;
21
 
22
/**
23
 * A composite that displays a list of names that can be selected.
24
 */
25
 
4 ddelon 26
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler  {
2 ddelon 27
 
4 ddelon 28
  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
2 ddelon 29
  private HorizontalPanel panel = new HorizontalPanel();
4 ddelon 30
  private Vector complements=null;
2 ddelon 31
 
4 ddelon 32
  public NameAssistant(AutoCompleteAsyncTextBoxListener listener,Vector comps) {
2 ddelon 33
 
4 ddelon 34
	complements=comps;
35
	autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/NameSearch/");
36
 
2 ddelon 37
	panel.add(autoCompletebox);
38
 
39
	autoCompletebox.setWidth("100%");
40
    initWidget(panel);
41
    autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener);
42
 
43
  }
44
 
4 ddelon 45
public void onCompletion(String str) {
46
 
47
  			JSONValue jsonValue= JSONParser.parse(str);
48
  			JSONArray jsonArray;
49
  			JSONArray jsonArrayNested;
50
  			JSONString jsonString;
51
 
52
  			complements.clear();
53
 
54
  			if ((jsonArray = jsonValue.isArray()) != null) {
55
  				for (int i = 0; i < jsonArray.size(); ++i) {
56
  				  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
57
  					if ((jsonString = (jsonArrayNested.get(0)).isString()) != null) {
58
  						autoCompletebox.addItem(jsonString.stringValue());
59
  					}
60
  					if ((jsonString = (jsonArrayNested.get(1)).isString()) != null) {
61
  						complements.add(i,jsonString.stringValue());
62
  					}
63
  				  }
64
  				}
65
  			}
66
 
67
  			autoCompletebox.displayList();
68
 
69
}
70
 
71
 
2 ddelon 72
 
4 ddelon 73
public String getServiceBaseUrl() {
74
 
75
	  Dictionary theme = Dictionary.getDictionary("Parameters");
76
	  return theme.get("serviceBaseUrl");
77
 
78
 
79
	}
80
 
81
 
2 ddelon 82
}
83