Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 2 Rev 4
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
 
-
 
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;
7
 
13
import com.google.gwt.user.client.ResponseTextHandler;
8
import com.google.gwt.user.client.ui.Composite;
14
import com.google.gwt.user.client.ui.Composite;
9
import com.google.gwt.user.client.ui.HorizontalPanel;
15
import com.google.gwt.user.client.ui.HorizontalPanel;
-
 
16
 
-
 
17
import java.util.Vector;
10
 
18
 
11
 
19
 
12
import org.tela_botanica.client.AutoCompleteAsyncTextBox;
20
import org.tela_botanica.client.AutoCompleteAsyncTextBox;
13
 
21
 
14
/**
22
/**
15
 * A composite that displays a list of names that can be selected.
23
 * A composite that displays a list of names that can be selected.
16
 */
24
 */
17
 
25
 
18
public class NameAssistant extends Composite implements EventListener  {
26
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler  {
19
 
27
 
20
  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox();
-
 
-
 
28
  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
21
  private HorizontalPanel panel = new HorizontalPanel();
29
  private HorizontalPanel panel = new HorizontalPanel();
22
 
30
  private Vector complements=null;
23
  
31
  
24
  public NameAssistant(AutoCompleteAsyncTextBoxListener listener) {
-
 
25
	 
32
  public NameAssistant(AutoCompleteAsyncTextBoxListener listener,Vector comps) {
26
//	autoCompletebox.setSearchUrl("http://localhost/david/PHPJSON/server/server.php");
33
	
27
//	autoCompletebox.setSearchUrl("http://localhost/david/papyrus/client/eflore_bp/index.php?module=recherche&action=completion_nom_latin&referentiel=25&format=json&nom=");
34
	complements=comps;
28
	autoCompletebox.setSearchUrl("http://localhost/david/jrest/NameSearch/");
35
	autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/NameSearch/");
29
	
36
	
30
	panel.add(autoCompletebox);
37
	panel.add(autoCompletebox);
31
 
38
 
32
	autoCompletebox.setWidth("100%");
39
	autoCompletebox.setWidth("100%");
33
    initWidget(panel);
40
    initWidget(panel);
34
    autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener);
41
    autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener);
35
 
42
 
36
  }
43
  }
-
 
44
 
-
 
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
 
-
 
72
  
-
 
73
public String getServiceBaseUrl() {
-
 
74
	  
-
 
75
	  Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
76
	  return theme.get("serviceBaseUrl");
-
 
77
	  
-
 
78
 
-
 
79
	} 
37
 
80
  
38
  
81
  
39
}
82
}
40
  
83