Subversion Repositories eFlore/Applications.coel

Rev

Rev 1417 | Rev 1468 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1287 cyprien 1
package org.tela_botanica.client.composants.pagination;
2
 
1428 cyprien 3
import org.tela_botanica.client.interfaces.Rafraichissable;
4
import org.tela_botanica.client.modeles.Information;
5
import org.tela_botanica.client.util.Debug;
6
 
1287 cyprien 7
import com.extjs.gxt.ui.client.data.BasePagingLoader;
8
import com.extjs.gxt.ui.client.data.LoadEvent;
9
import com.extjs.gxt.ui.client.data.PagingLoadResult;
10
import com.google.gwt.user.client.rpc.AsyncCallback;
11
 
12
public class ChargeurListe<D extends PagingLoadResult<?>> extends BasePagingLoader<D> {
13
 
14
	private String recherche = "";
1428 cyprien 15
	private Integer id = null;
16
	private Rafraichissable vueARafraichir = null;
17
	private boolean rafraichir = false;
1287 cyprien 18
 
19
	@SuppressWarnings("unchecked")
1428 cyprien 20
	public ChargeurListe(Proxy proxy, TransformateurJSONaModelData reader, Rafraichissable vueARafraichir) {
1287 cyprien 21
		super(proxy, reader);
1428 cyprien 22
		this.vueARafraichir = vueARafraichir;
1287 cyprien 23
	}
24
 
1428 cyprien 25
	public boolean load(Object loadConfig, String recherche, boolean rafraichir) {
26
		this.rafraichir = rafraichir;
27
		if (fireEvent(BeforeLoad, new LoadEvent(this, loadConfig))) {
1287 cyprien 28
	    lastConfig = loadConfig;
29
 
30
		this.recherche = recherche;
31
 
32
	    loadData(loadConfig, recherche);
33
	    return true;
34
	  }
35
	  else return false;
36
	}
37
 
38
	public boolean load(Object loadConfig) {
39
	    if (fireEvent(BeforeLoad, new LoadEvent(this, loadConfig))) {
40
	      lastConfig = loadConfig;
41
	      loadData(loadConfig, recherche);
42
	      return true;
43
	    }
44
	    return false;
45
	}
46
 
47
	public void load(int offset, int limit) {
48
	  this.offset = offset;
49
	  this.limit = limit;
50
	  load();
51
	}
52
 
53
	public boolean load() {
54
	  Object config = (reuseConfig && lastConfig != null) ? lastConfig : newLoadConfig();
55
	  config = prepareLoadConfig(config);
56
	  return load(config);
57
	}
58
 
59
	@SuppressWarnings("unchecked")
60
	protected void loadData(final Object config, String recherche) {
61
		AsyncCallback<D> callback = new AsyncCallback<D>() {
1428 cyprien 62
 
1287 cyprien 63
		    public void onFailure(Throwable caught) {
64
		      onLoadFailure(config, caught);
65
		    }
1428 cyprien 66
 
1287 cyprien 67
		    public void onSuccess(D result) {
1428 cyprien 68
		    	onLoadSuccess(config, result);
69
 
70
			    if (rafraichir) {
71
			    	Information info = new Information("selectionnerValeurCombo");
72
			    	info.setDonnee(result);
73
			    	info.setMessage("");
74
 
75
					vueARafraichir.rafraichir(info);
76
			    }
77
			}
1287 cyprien 78
		};
79
		((Proxy)proxy).load((TransformateurJSONaModelData)reader, config, callback, recherche);
80
	}
81
}