1287 |
cyprien |
1 |
package org.tela_botanica.client.composants.pagination;
|
|
|
2 |
|
1445 |
cyprien |
3 |
import java.util.Iterator;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
import java.util.Map;
|
|
|
6 |
import java.util.Set;
|
|
|
7 |
|
1425 |
cyprien |
8 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
9 |
import org.tela_botanica.client.modeles.Information;
|
1445 |
cyprien |
10 |
import org.tela_botanica.client.modeles.collection.CollectionAPersonne;
|
|
|
11 |
import org.tela_botanica.client.modeles.personne.Personne;
|
1425 |
cyprien |
12 |
import org.tela_botanica.client.util.Debug;
|
1445 |
cyprien |
13 |
import org.tela_botanica.client.util.UtilString;
|
1425 |
cyprien |
14 |
|
1445 |
cyprien |
15 |
import com.extjs.gxt.ui.client.data.BaseListLoadResult;
|
|
|
16 |
import com.extjs.gxt.ui.client.data.BaseModelData;
|
|
|
17 |
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
|
1287 |
cyprien |
18 |
import com.extjs.gxt.ui.client.data.BasePagingLoader;
|
|
|
19 |
import com.extjs.gxt.ui.client.data.LoadEvent;
|
|
|
20 |
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
|
|
21 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
22 |
|
|
|
23 |
public class ChargeurListe<D extends PagingLoadResult<?>> extends BasePagingLoader<D> {
|
|
|
24 |
|
|
|
25 |
private String recherche = "";
|
1425 |
cyprien |
26 |
private Rafraichissable vueARafraichir = null;
|
1445 |
cyprien |
27 |
private boolean doRafraichir = false;
|
1287 |
cyprien |
28 |
|
|
|
29 |
@SuppressWarnings("unchecked")
|
1425 |
cyprien |
30 |
public ChargeurListe(Proxy proxy, TransformateurJSONaModelData reader, Rafraichissable vueARafraichir) {
|
1287 |
cyprien |
31 |
super(proxy, reader);
|
1425 |
cyprien |
32 |
this.vueARafraichir = vueARafraichir;
|
1287 |
cyprien |
33 |
}
|
|
|
34 |
|
1445 |
cyprien |
35 |
public boolean load(Object loadConfig, String recherche, boolean doRafraichir) {
|
|
|
36 |
this.doRafraichir = doRafraichir;
|
1425 |
cyprien |
37 |
if (fireEvent(BeforeLoad, new LoadEvent(this, loadConfig))) {
|
1287 |
cyprien |
38 |
lastConfig = loadConfig;
|
|
|
39 |
|
|
|
40 |
this.recherche = recherche;
|
|
|
41 |
|
|
|
42 |
loadData(loadConfig, recherche);
|
|
|
43 |
return true;
|
|
|
44 |
}
|
|
|
45 |
else return false;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public boolean load(Object loadConfig) {
|
|
|
49 |
if (fireEvent(BeforeLoad, new LoadEvent(this, loadConfig))) {
|
|
|
50 |
lastConfig = loadConfig;
|
|
|
51 |
loadData(loadConfig, recherche);
|
|
|
52 |
return true;
|
|
|
53 |
}
|
|
|
54 |
return false;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public void load(int offset, int limit) {
|
|
|
58 |
this.offset = offset;
|
|
|
59 |
this.limit = limit;
|
|
|
60 |
load();
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public boolean load() {
|
|
|
64 |
Object config = (reuseConfig && lastConfig != null) ? lastConfig : newLoadConfig();
|
|
|
65 |
config = prepareLoadConfig(config);
|
|
|
66 |
return load(config);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
@SuppressWarnings("unchecked")
|
|
|
70 |
protected void loadData(final Object config, String recherche) {
|
|
|
71 |
AsyncCallback<D> callback = new AsyncCallback<D>() {
|
1425 |
cyprien |
72 |
|
1287 |
cyprien |
73 |
public void onFailure(Throwable caught) {
|
|
|
74 |
onLoadFailure(config, caught);
|
1445 |
cyprien |
75 |
if (!UtilString.isEmpty(caught.getMessage())) Debug.log("[FAILURE] ChargeurListe : message="+caught.getMessage());
|
|
|
76 |
else Debug.log("[FAILURE] ChargeurListe : message=NULL. Peut-être le modelType est-il mal paramétré ?");
|
1287 |
cyprien |
77 |
}
|
1425 |
cyprien |
78 |
|
1287 |
cyprien |
79 |
public void onSuccess(D result) {
|
1425 |
cyprien |
80 |
onLoadSuccess(config, result);
|
1445 |
cyprien |
81 |
|
|
|
82 |
/*
|
|
|
83 |
// SUPPRIMER LES PREFIXES
|
|
|
84 |
if (result instanceof BasePagingLoadResult) {
|
|
|
85 |
BasePagingLoadResult retourPaging = (BasePagingLoadResult)result;
|
|
|
86 |
List retourListe = retourPaging.getData();
|
|
|
87 |
|
|
|
88 |
for(int i=0; i< retourListe.size(); i++) {
|
|
|
89 |
if (retourListe.get(i) instanceof BaseModelData) {
|
|
|
90 |
BaseModelData model = (BaseModelData)retourListe.get(i);
|
|
|
91 |
|
|
|
92 |
Map<String, Object> a = model.getProperties();
|
|
|
93 |
Set<String> cles = a.keySet();
|
|
|
94 |
Iterator<String> it = cles.iterator();
|
|
|
95 |
while (it.hasNext()) {
|
|
|
96 |
String cle = it.next();
|
|
|
97 |
if (a.get(cle) != null) {
|
|
|
98 |
String cleObjet = "";
|
|
|
99 |
cleObjet = cle.replaceFirst("^[A-Za-z]+_", "");
|
|
|
100 |
model.set(cleObjet, a.get(cle));
|
|
|
101 |
model.remove(cle);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
}*/
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
// Cas où il faut rafraichir le combo manuellement
|
|
|
110 |
// (cela sert pour charger la valeur initiale du combo au chargement d'un formulaire)
|
|
|
111 |
if (doRafraichir) {
|
1425 |
cyprien |
112 |
Information info = new Information("selectionnerValeurCombo");
|
|
|
113 |
info.setDonnee(result);
|
|
|
114 |
info.setMessage("");
|
|
|
115 |
|
|
|
116 |
vueARafraichir.rafraichir(info);
|
|
|
117 |
}
|
|
|
118 |
}
|
1287 |
cyprien |
119 |
};
|
|
|
120 |
((Proxy)proxy).load((TransformateurJSONaModelData)reader, config, callback, recherche);
|
|
|
121 |
}
|
|
|
122 |
}
|