Subversion Repositories eFlore/Archives.cel-v2

Rev

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

Rev 31 Rev 36
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
2
 
2
 
3
import org.tela_botanica.client.image.ImageMediateur;
3
import org.tela_botanica.client.image.ImageMediateur;
-
 
4
import org.tela_botanica.client.image.ImageModele;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
 
6
 
6
import com.google.gwt.json.client.JSONArray;
7
import com.google.gwt.json.client.JSONArray;
7
import com.google.gwt.json.client.JSONObject;
8
import com.google.gwt.json.client.JSONObject;
8
import com.google.gwt.json.client.JSONParser;
9
import com.google.gwt.json.client.JSONParser;
9
import com.google.gwt.json.client.JSONString;
10
import com.google.gwt.json.client.JSONString;
10
import com.google.gwt.json.client.JSONValue;
11
import com.google.gwt.json.client.JSONValue;
11
import com.google.gwt.user.client.HTTPRequest;
12
import com.google.gwt.user.client.HTTPRequest;
12
import com.google.gwt.user.client.ResponseTextHandler;
13
import com.google.gwt.user.client.ResponseTextHandler;
13
import com.google.gwt.user.client.Window;
14
import com.google.gwt.user.client.Window;
-
 
15
import com.google.gwt.user.client.ui.Image;
-
 
16
 
-
 
17
/**
-
 
18
 * DAO qui renvoie le nombre d'image associées à différents critères donnés (utile pour la pagination)
-
 
19
 * @author aurelien
-
 
20
 *
14
 
21
 */
-
 
22
public class NombreImageAsynchroneDAO {
-
 
23
 
-
 
24
	/**
15
public class NombreImageAsynchroneDAO {
25
	 * Le modèle associé au DAO
-
 
26
	 */
-
 
27
	private ImageModele iModele = null ;
-
 
28
	
-
 
29
	/**
16
 
30
	 * Setteur pour le modèle
17
	private ImageMediateur iMediateur = null ;
31
	 * @param im le modèlme à associer
18
	
32
	 */
19
	public void setImediateur(ImageMediateur im)
33
	public void setIModele(ImageModele im)
-
 
34
	{
-
 
35
		iModele = im ;
-
 
36
	}
-
 
37
	
-
 
38
	/**
-
 
39
	 * Envoie une requete au serveur jrest pour obtenir le nombre d'images correspondant
20
	{
40
	 * à des critères données en paramètres
21
		iMediateur = im ;
41
	 * @param r le rafraichissable qui demande la mise à jour
22
	}
42
	 * @param criteres un tableau nom/valeur des critères pour les images
23
	
43
	 */
24
	public void obtenirNombreImages(final Rafraichissable r, String[][] criteres)
44
	public void obtenirNombreImages(final Rafraichissable r, String[][] criteres)
25
	{
45
	{
26
		String requete = "" ;
46
		String requete = "" ;
27
			
47
			
28
		if(criteres != null)
48
		if(criteres != null)
29
		{
49
		{
-
 
50
			// on construit les paramètres du get avec les critères (&critere1=valeur1&critere2=valeur2 etc...)
30
			for (int i = 0; i < criteres.length; i++) {
51
			for (int i = 0; i < criteres.length; i++) {
31
			
52
			
32
				if(!criteres[i][0].equals("ci_ordre"))
53
				if(!criteres[i][0].equals("ci_ordre"))
33
				{
54
				{
34
					if(i != 0)
55
					if(i != 0)
35
					{
56
					{
36
							requete += "&" ;
57
							requete += "&" ;
37
					}
58
					}
38
					requete += criteres[i][0]+"="+criteres[i][1] ;
59
					requete += criteres[i][0]+"="+criteres[i][1] ;
39
					if(i != criteres.length - 1)
60
					if(i != criteres.length - 1)
40
					{
61
					{
41
						requete += "&" ;
62
						requete += "&" ;
42
					}
63
					}
43
				}
64
				}
44
			}
65
			}
45
		}
66
		}
-
 
67
		
46
		
68
		// on fait un get asynchrone
47
		HTTPRequest.asyncGet("jrest/InventoryImageCount/0/"+requete, new ResponseTextHandler() {
69
		HTTPRequest.asyncGet("jrest/InventoryImageCount/"+iModele.getIdentifiant()+"/"+requete, new ResponseTextHandler() {
48
			public void onCompletion(String responseText) {
70
			public void onCompletion(String responseText) {
49
				
71
				
50
				final JSONValue responseValue = JSONParser.parse(responseText);
72
				final JSONValue responseValue = JSONParser.parse(responseText);
-
 
73
				
51
				
74
				// si la requete se passe bien on reçoit un tableau JSON
52
				if(responseValue.isArray() != null)
75
				if(responseValue.isArray() != null)
-
 
76
				{
53
				{
77
					// qui contient une valeur : le nombre d'images correspondant au critères
54
					JSONValue res = responseValue.isArray().get(0) ;
78
					JSONValue res = responseValue.isArray().get(0) ;
55
						JSONString reponseNombre = res.isString() ;
79
						JSONString reponseNombre = res.isString() ;
56
						int maxImages = (int)Integer.parseInt(reponseNombre.stringValue()) ;
80
						int maxImages = (int)Integer.parseInt(reponseNombre.stringValue()) ;
57
						int[] nbImages = {maxImages} ;
81
						int[] nbImages = {maxImages} ;
-
 
82
						// on le met dans un tableau d'entiers qu'on tranmset au demandeur de la mise à jour
58
						r.rafraichir(nbImages, true) ;
83
						r.rafraichir(nbImages, true) ;
59
				}
84
				}
60
				
85
				
61
			}
86
			}
62
			
87
			
63
		}) ;
88
		}) ;
64
	}
89
	}
65
	
90
	
66
}
91
}