Subversion Repositories eFlore/Archives.cel-v1

Rev

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

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