Subversion Repositories eFlore/Applications.cel

Rev

Rev 147 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
147 aurelien 1
package org.tela_botanica.client.modeles;
2
 
3
import org.tela_botanica.client.CarnetEnLigneModele;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import com.google.gwt.http.client.Request;
6
import com.google.gwt.http.client.RequestBuilder;
7
import com.google.gwt.http.client.RequestCallback;
8
import com.google.gwt.http.client.RequestException;
9
import com.google.gwt.http.client.Response;
10
import com.google.gwt.json.client.JSONArray;
11
import com.google.gwt.json.client.JSONParser;
12
import com.google.gwt.json.client.JSONString;
13
import com.google.gwt.json.client.JSONValue;
14
import com.google.gwt.user.client.Window;
15
 
16
public class ListeUtilisateurAsynchroneDAO {
17
 
18
	CarnetEnLigneModele cModele = null ;
19
 
20
	public ListeUtilisateurAsynchroneDAO(CarnetEnLigneModele carnetEnLigneModele) {
21
		cModele = carnetEnLigneModele ;
22
	}
23
 
24
	public final void obtenirListeUtilisateur(final Rafraichissable r,final String rech, final String utilisateur) {
25
 
26
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + "/InventoryUserList/" + utilisateur+"/"+rech);
27
 
28
 
29
		try {
30
 
31
			rb.sendRequest(null, new RequestCallback() {
32
 
33
				public void onError(final Request request, final Throwable exception) {
34
					// TODO Auto-generated method stub
35
 
36
				}
37
 
38
				public void onResponseReceived(final Request request,
39
						final Response response) {
40
 
41
					String[][] util ;
42
 
43
					final JSONValue responseValue = JSONParser.parse(response.getText());
44
					JSONArray reponse = responseValue.isArray();
45
 
46
					if(reponse != null) {
47
 
48
						util = new String[reponse.size()][1];
49
 
50
						for(int i = 0; i < reponse.size() ; i++) {
51
 
52
							 JSONString item = reponse.get(i).isString();
53
 
54
							if(item != null) {
55
								util[i][0] = item.stringValue();
56
							}
57
						}
58
					}
59
					else {
60
						util = new String[0][1];
61
					}
62
 
63
					r.rafraichir(util, true);
64
				}
65
			});
66
 
67
		} catch (RequestException e) {
68
 
69
			e.printStackTrace();
70
		}
71
 
72
	}
73
 
74
}