Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 16 | Rev 22 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.modeles;

import java.util.Iterator;

import org.tela_botanica.client.image.ImageMediateur;
import org.tela_botanica.client.interfaces.Rafraichissable;

import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;
import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;

/**
 * Data Object Access communiquant avec le serveur jrest fournissant la liste des images
 * répondant à des critères donné
 * @author aurelien
 *
 */
public class ListeImageAsynchroneDAO {
        
        ImageMediateur iMediateur = null ;
        
        public void setIMediateur(ImageMediateur im)
        {
                iMediateur = im ;
        }
        
        public void ObtenirListeImages(final Rafraichissable r)
        {
                HTTPRequest.asyncGet("jrest/inventoryImageList/1/ci_publiable_eflore=0", new ResponseTextHandler() {
                        public void onCompletion(String responseText) {
                                
                                final ListeImage photoData ;

                                final JSONValue responseValue = JSONParser.parse(responseText);
                                if (responseValue.isArray() != null) {
                                        
                                        final JSONArray reponse = responseValue.isArray();

                                        final int taillemax = reponse.size();
                                        photoData = new ListeImage(taillemax);
                                        
                                        
                                        for (int j = 0; j < taillemax ; j++) {
                                                
                                                JSONObject image = (JSONObject)reponse.get(j) ;
                                                
                                                ImageCarnet im = new ImageCarnet(image) ;
                                                
                                                photoData.put(im.getOrdre(),im) ;
                                                
                                        }
                                }
                                else
                                {
                                        if(responseValue.isObject() != null)
                                        {
                                                photoData = new ListeImage(1);
                                                ImageCarnet im = new ImageCarnet(responseValue.isObject()) ;
                                                photoData.put(im.getOrdre(),im) ;
                                        }
                                        else
                                        {
                                                photoData = null ;
                                        }
                                }
                                
                                r.rafraichir(photoData,true);
                        }
                });
        }
        
        public void SynchroniserBaseDeDonnees(ListeImage li)
        {
                for(Iterator it = li.keySet().iterator() ; it.hasNext() ;)
                {
                                        
                //      HTTPRequest.asyncPost("jrest/inventoryImageList/1/", postData, handler)
                }
        }
        

}