Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 6 | Rev 8 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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