Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 11 Rev 13
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 nom pour selection. Son retournés le nom selectionné (gettext()) et un code associé (getvalue()).
20
 * Affiche une liste de nom pour selection. Son retournés le nom selectionné (gettext()) et un code associé (getvalue()).
21
 */
21
 */
22
 
22
 
23
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler  {
23
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler  {
24
 
24
 
25
  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
25
  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
26
  private HorizontalPanel panel = new HorizontalPanel();
26
  private HorizontalPanel panel = new HorizontalPanel();
27
  
27
  
28
  private Mediator mediator = null;
28
  private Mediator mediator = null;
29
	
29
	
30
  
30
  
31
  public NameAssistant(Mediator med) {
31
  public NameAssistant(Mediator med) {
32
 
32
 
33
	mediator=med;
33
	mediator=med;
34
	mediator.registerNameAssistant(this);		
34
	mediator.registerNameAssistant(this);		
35
	
35
	
36
	
36
	
37
//	autoCompletebox.setFocus(true);
37
//	autoCompletebox.setFocus(true);
38
	autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/");
38
	autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/");
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.getInventoryItemList());
44
    autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator.getInventoryItemList());
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
 
-
 
68
public void setText(String str) {
-
 
69
	autoCompletebox.setText(str);
-
 
70
}
67
 
71
 
68
 
72
 
69
public String getText() {
73
public String getText() {
70
	return autoCompletebox.getText();
74
	return autoCompletebox.getText();
71
}
75
}
72
 
76
 
73
 
77
 
74
public String getValue() {
78
public String getValue() {
75
	return autoCompletebox.getValue();
79
	return autoCompletebox.getValue();
76
}
80
}
-
 
81
 
-
 
82
public void setValue(String value) {
-
 
83
	autoCompletebox.setValue(value);
-
 
84
}
77
 
85
 
78
  
86
  
79
}
87
}
80
  
88