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