Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 10 | Rev 13 | 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
/**
21
 * A composite that displays a list of names that can be selected.
20
 * Affiche une liste de nom pour selection. Son retournés le nom selectionné (gettext()) et un code associé (getvalue()).
22
 */
21
 */
23
 
22
 
24
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler  {
23
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler  {
25
 
24
 
26
  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
25
  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
27
  private HorizontalPanel panel = new HorizontalPanel();
26
  private HorizontalPanel panel = new HorizontalPanel();
-
 
27
  
-
 
28
  private Mediator mediator = null;
-
 
29
	
28
  
30
  
-
 
31
  public NameAssistant(Mediator med) {
-
 
32
 
-
 
33
	mediator=med;
-
 
34
	mediator.registerNameAssistant(this);		
29
  public NameAssistant(AutoCompleteAsyncTextBoxListener listener) {
35
	
30
 
36
	
31
//	autoCompletebox.setFocus(true);
37
//	autoCompletebox.setFocus(true);
32
	autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/NameSearch/");
38
	autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/");
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
 
67
 
62
 
68
 
63
public String getText() {
69
public String getText() {
64
	return autoCompletebox.getText();
70
	return autoCompletebox.getText();
65
}
71
}
66
 
72
 
67
 
73
 
68
public String getValue() {
74
public String getValue() {
69
	return autoCompletebox.getValue();
75
	return autoCompletebox.getValue();
70
}
76
}
71
 
-
 
72
 
-
 
73
public String getServiceBaseUrl() {
-
 
74
	  
-
 
75
	  Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
76
	  return theme.get("serviceBaseUrl");
-
 
77
	  
-
 
78
 
-
 
79
	} 
-
 
80
  
77
 
81
  
78
  
82
}
79
}
83
  
80