1448 |
cyprien |
1 |
package org.tela_botanica.client.composants;
|
|
|
2 |
|
1513 |
jpm |
3 |
import java.util.HashMap;
|
1448 |
cyprien |
4 |
import java.util.List;
|
|
|
5 |
import java.util.Map;
|
|
|
6 |
|
|
|
7 |
import org.tela_botanica.client.composants.pagination.ChargeurListe;
|
|
|
8 |
import org.tela_botanica.client.composants.pagination.Proxy;
|
|
|
9 |
import org.tela_botanica.client.composants.pagination.TransformateurJSONaModelData;
|
|
|
10 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
11 |
import org.tela_botanica.client.modeles.aDonnee;
|
|
|
12 |
import org.tela_botanica.client.util.Debug;
|
|
|
13 |
import org.tela_botanica.client.composants.GrilleParametrable;
|
|
|
14 |
|
|
|
15 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
|
|
16 |
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
|
|
|
17 |
import com.extjs.gxt.ui.client.data.LoadEvent;
|
|
|
18 |
import com.extjs.gxt.ui.client.data.Loader;
|
|
|
19 |
import com.extjs.gxt.ui.client.data.ModelData;
|
|
|
20 |
import com.extjs.gxt.ui.client.data.ModelType;
|
|
|
21 |
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
|
|
|
22 |
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
|
|
23 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
24 |
import com.extjs.gxt.ui.client.event.GridEvent;
|
|
|
25 |
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
26 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
27 |
import com.extjs.gxt.ui.client.store.Store;
|
|
|
28 |
import com.extjs.gxt.ui.client.store.StoreEvent;
|
|
|
29 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
|
|
30 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
31 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
32 |
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
|
|
|
33 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
|
|
34 |
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
|
|
|
35 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
1513 |
jpm |
36 |
import com.extjs.gxt.ui.client.widget.selection.SelectionModel;
|
1448 |
cyprien |
37 |
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
|
|
|
38 |
|
|
|
39 |
public class GrillePaginable<D extends ModelData> extends ContentPanel implements Rafraichissable, GrilleParametrable<D> {
|
|
|
40 |
|
|
|
41 |
//-------------//
|
|
|
42 |
// ATTRIBUTS //
|
|
|
43 |
//-------------//
|
|
|
44 |
|
|
|
45 |
// Pagination
|
|
|
46 |
private int start = 0;
|
|
|
47 |
private int limit = 50;
|
|
|
48 |
|
|
|
49 |
// Récupération, stockage et pagination des données
|
|
|
50 |
private ModelType modelType = null;
|
|
|
51 |
private Proxy<D> proxy = null;
|
|
|
52 |
private TransformateurJSONaModelData<PagingLoadResult<D>> reader = null;
|
|
|
53 |
private ChargeurListe<PagingLoadResult<D>> loader = null;
|
|
|
54 |
private ListStore<D> storeGrille = null;
|
|
|
55 |
|
|
|
56 |
// Elements graphiques
|
1513 |
jpm |
57 |
EditorGrid<D> grille = null;
|
1448 |
cyprien |
58 |
List<ColumnConfig> colonnes = null;
|
|
|
59 |
ColumnModel modeleDeColonnes = null;
|
|
|
60 |
|
|
|
61 |
//-------------//
|
|
|
62 |
// METHODES //
|
|
|
63 |
//-------------//
|
|
|
64 |
|
|
|
65 |
/*--------------
|
|
|
66 |
Constructeur
|
|
|
67 |
--------------*/
|
|
|
68 |
|
1513 |
jpm |
69 |
public GrillePaginable(ModelType modeltype, HashMap<String, String> virtualFields, Proxy<D> proxy, List<ColumnConfig> colonnes, ColumnModel modeleDeColonnes) {
|
1448 |
cyprien |
70 |
|
|
|
71 |
// Récupération des paramètres
|
|
|
72 |
this.modelType = modeltype;
|
|
|
73 |
this.proxy = proxy;
|
|
|
74 |
this.colonnes = colonnes;
|
|
|
75 |
this.modeleDeColonnes = modeleDeColonnes;
|
|
|
76 |
|
|
|
77 |
// Formatage du conteneur;
|
|
|
78 |
this.setLayout(new FitLayout());
|
|
|
79 |
|
|
|
80 |
// Création des objets pour la récupération et la pagination des données
|
|
|
81 |
BasePagingLoadConfig plc = new BasePagingLoadConfig();
|
|
|
82 |
plc.setLimit(limit);
|
|
|
83 |
plc.setOffset(start);
|
|
|
84 |
|
1513 |
jpm |
85 |
reader = new TransformateurJSONaModelData<PagingLoadResult<D>>(modelType, virtualFields);
|
1448 |
cyprien |
86 |
|
|
|
87 |
loader = new ChargeurListe<PagingLoadResult<D>>(proxy, reader, this);
|
|
|
88 |
loader.setLimit(plc.getLimit());
|
|
|
89 |
loader.setOffset(plc.getOffset());
|
|
|
90 |
|
|
|
91 |
loader.addListener(Loader.BeforeLoad, new Listener<LoadEvent>() {
|
|
|
92 |
public void handleEvent(LoadEvent be) {
|
|
|
93 |
|
|
|
94 |
}
|
|
|
95 |
});
|
|
|
96 |
|
1513 |
jpm |
97 |
loader.addListener(Loader.Load, new Listener<LoadEvent>() {
|
|
|
98 |
public void handleEvent(LoadEvent be) {
|
|
|
99 |
|
|
|
100 |
}
|
|
|
101 |
});
|
|
|
102 |
|
1448 |
cyprien |
103 |
// Création de la grille
|
|
|
104 |
creerGrille();
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
/*------------
|
|
|
109 |
Accesseurs
|
|
|
110 |
------------*/
|
|
|
111 |
|
|
|
112 |
public EditorGrid<D> getGrille() {
|
1513 |
jpm |
113 |
return grille;
|
1448 |
cyprien |
114 |
}
|
|
|
115 |
|
|
|
116 |
public ListStore<D> getStore() {
|
|
|
117 |
return storeGrille;
|
|
|
118 |
}
|
|
|
119 |
|
1513 |
jpm |
120 |
public GridSelectionModel<D> getSelectionModel() {
|
|
|
121 |
return grille.getSelectionModel();
|
|
|
122 |
}
|
|
|
123 |
|
1448 |
cyprien |
124 |
public D getSelection() {
|
1513 |
jpm |
125 |
return grille.getSelectionModel().getSelectedItem();
|
|
|
126 |
}
|
1448 |
cyprien |
127 |
|
1513 |
jpm |
128 |
@SuppressWarnings("unchecked")
|
|
|
129 |
public Proxy getProxy() {
|
|
|
130 |
return this.proxy;
|
|
|
131 |
}
|
1448 |
cyprien |
132 |
|
1513 |
jpm |
133 |
|
1448 |
cyprien |
134 |
/*-----------------------------
|
|
|
135 |
Rafraichir
|
|
|
136 |
-----------------------------*/
|
|
|
137 |
|
|
|
138 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
139 |
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
/*----------------
|
|
|
144 |
Méthode privées
|
|
|
145 |
-----------------*/
|
|
|
146 |
|
|
|
147 |
private void creerGrille() {
|
|
|
148 |
|
|
|
149 |
final PagingToolBar toolBar = new PagingToolBar(this.limit);
|
|
|
150 |
toolBar.bind(loader);
|
|
|
151 |
this.setBottomComponent(toolBar);
|
|
|
152 |
|
|
|
153 |
storeGrille = new ListStore<D>(loader);
|
|
|
154 |
|
|
|
155 |
storeGrille.addListener(Store.Add, new Listener<StoreEvent<D>>() {
|
|
|
156 |
public void handleEvent(StoreEvent<D> ce) {
|
|
|
157 |
|
|
|
158 |
}
|
|
|
159 |
});
|
|
|
160 |
storeGrille.addListener(Store.Remove, new Listener<StoreEvent<D>>() {
|
|
|
161 |
public void handleEvent(StoreEvent<D> ce) {
|
|
|
162 |
|
|
|
163 |
}
|
|
|
164 |
});
|
|
|
165 |
storeGrille.addListener(Store.Update, new Listener<StoreEvent<D>>() {
|
|
|
166 |
public void handleEvent(StoreEvent<D> ce) {
|
|
|
167 |
|
|
|
168 |
}
|
|
|
169 |
});
|
|
|
170 |
|
|
|
171 |
RowNumberer pluginLigneNumero = new RowNumberer();
|
|
|
172 |
|
|
|
173 |
GridSelectionModel<D> modeleDeSelection = new GridSelectionModel<D>();
|
|
|
174 |
|
1513 |
jpm |
175 |
grille = new EditorGrid<D>(storeGrille, modeleDeColonnes);
|
|
|
176 |
grille.setHeight("100%");
|
|
|
177 |
grille.setBorders(true);
|
|
|
178 |
grille.setSelectionModel(modeleDeSelection);
|
|
|
179 |
grille.addPlugin(pluginLigneNumero);
|
|
|
180 |
grille.getView().setForceFit(true);
|
|
|
181 |
grille.setStripeRows(true);
|
|
|
182 |
grille.setBorders(true);
|
1448 |
cyprien |
183 |
|
1513 |
jpm |
184 |
grille.setStateful(true);
|
1448 |
cyprien |
185 |
|
1513 |
jpm |
186 |
grille.addListener(Events.Attach, new Listener<GridEvent<D>>() {
|
1448 |
cyprien |
187 |
public void handleEvent(GridEvent<D> be) {
|
|
|
188 |
PagingLoadConfig config = new BasePagingLoadConfig();
|
1513 |
jpm |
189 |
config.setOffset(start);
|
|
|
190 |
config.setLimit(limit);
|
1448 |
cyprien |
191 |
|
1513 |
jpm |
192 |
Map<String, Object> state = grille.getState();
|
1448 |
cyprien |
193 |
if (state.containsKey("offset")) {
|
|
|
194 |
int offset = (Integer)state.get("offset");
|
|
|
195 |
int limit = (Integer)state.get("limit");
|
|
|
196 |
config.setOffset(offset);
|
|
|
197 |
config.setLimit(limit);
|
|
|
198 |
}
|
|
|
199 |
if (state.containsKey("sortField")) {
|
|
|
200 |
config.setSortField((String)state.get("sortField"));
|
|
|
201 |
config.setSortDir(SortDir.valueOf((String)state.get("sortDir")));
|
|
|
202 |
}
|
|
|
203 |
loader.load(config);
|
|
|
204 |
}
|
|
|
205 |
});
|
|
|
206 |
|
1513 |
jpm |
207 |
this.add(grille);
|
1448 |
cyprien |
208 |
}
|
1513 |
jpm |
209 |
|
|
|
210 |
public void reload() {
|
|
|
211 |
loader.load();
|
|
|
212 |
}
|
1448 |
cyprien |
213 |
}
|