Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.composants.pagination;

import java.util.ArrayList;
import java.util.List;

import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.util.Debug;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.MemoryProxy;
import com.google.gwt.user.client.rpc.AsyncCallback;

public abstract class Proxy<D> extends MemoryProxy<D> implements Rafraichissable {

        protected Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
        
        protected DataReader<D> reader = null;
        protected Object loadConfig = null;
        protected AsyncCallback<D> callback = null;
        
        protected static Object data;
        
        public Proxy() {
                super(data);
        }

        public abstract void load(TransformateurJSONaModelData<D> reader, Object loadConfig, AsyncCallback<D> callback, String recherche);

        @Override
        @SuppressWarnings("unchecked")
        public void rafraichir(Object nouvellesDonnees) {
                
                try {
                          data = nouvellesDonnees;
                        
                      D d = null;
                      if (reader != null) {
                        d = reader.read(loadConfig, data);
                      } else {
                        d = (D) data;
                        if (d instanceof List) {
                          d = (D) new ArrayList((List) d);
                        }
                      }
                      callback.onSuccess(d);
                    } catch (Exception e) {
                      callback.onFailure(e);
                 }
        }

}