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