Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 13 Rev 26
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
	
-
 
37
//	autoCompletebox.setFocus(true);
36
	
38
	autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/");
37
	autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/");
39
	
38
	
40
	panel.add(autoCompletebox);
39
	panel.add(autoCompletebox);
41
 
40
 
42
	autoCompletebox.setWidth("100%");
41
	autoCompletebox.setWidth("100%");
43
    initWidget(panel);
42
    initWidget(panel);
44
    autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator.getInventoryItemList());
43
    autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator);
45
 
44
 
46
  }
45
  }
47
 
46
 
48
public void onCompletion(String str) {
47
public void onCompletion(String str) {
49
	  
48
	  
50
  			JSONValue jsonValue= JSONParser.parse(str);
49
  			JSONValue jsonValue= JSONParser.parse(str);
51
  			JSONArray jsonArray;
50
  			JSONArray jsonArray;
52
  			JSONArray jsonArrayNested;
51
  			JSONArray jsonArrayNested;
53
 
52
 
54
  			
53
  			
55
  			if ((jsonArray = jsonValue.isArray()) != null) {
54
  			if ((jsonArray = jsonValue.isArray()) != null) {
56
  				for (int i = 0; i < jsonArray.size(); ++i) {
55
  				for (int i = 0; i < jsonArray.size(); ++i) {
57
  				  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
56
  				  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
58
 			  		autoCompletebox.addItem(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue());
57
 			  		autoCompletebox.addItem(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue());
59
  				  }
58
  				  }
60
  				}
59
  				}
61
  			}
60
  			}
62
 
61
 
63
  			autoCompletebox.displayList();
62
  			autoCompletebox.displayList();
64
	            
63
	            
65
}	  
64
}	  
66
 
65
 
67
 
66
 
68
public void setText(String str) {
67
public void setText(String str) {
69
	autoCompletebox.setText(str);
68
	autoCompletebox.setText(str);
70
}
69
}
71
 
70
 
72
 
71
 
73
public String getText() {
72
public String getText() {
74
	return autoCompletebox.getText();
73
	return autoCompletebox.getText();
75
}
74
}
76
 
75
 
77
 
76
 
78
public String getValue() {
77
public String getValue() {
79
	return autoCompletebox.getValue();
78
	return autoCompletebox.getValue();
80
}
79
}
81
 
80
 
82
public void setValue(String value) {
81
public void setValue(String value) {
83
	autoCompletebox.setValue(value);
82
	autoCompletebox.setValue(value);
84
}
83
}
85
 
84
 
86
  
85
  
87
}
86
}
88
  
87