Subversion Repositories eFlore/Archives.cel-v1

Rev

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

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