Subversion Repositories eFlore/Archives.cel-v1

Rev

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

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