12 |
david |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
|
|
3 |
|
46 |
david |
4 |
import java.util.Iterator;
|
|
|
5 |
|
|
|
6 |
import org.tela_botanica.client.modeles.ListeObservation;
|
|
|
7 |
import org.tela_botanica.client.modeles.Observation;
|
12 |
david |
8 |
import org.tela_botanica.client.observation.ObservationMediateur;
|
59 |
david |
9 |
import org.tela_botanica.client.interfaces.ListePaginable;
|
12 |
david |
10 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
11 |
import org.tela_botanica.client.interfaces.VueListable;
|
128 |
aurelien |
12 |
import com.gwtext.client.core.EventCallback;
|
41 |
jpm |
13 |
import com.gwtext.client.core.EventObject;
|
12 |
david |
14 |
import com.gwtext.client.core.Ext;
|
|
|
15 |
import com.gwtext.client.core.ExtElement;
|
101 |
jpm |
16 |
import com.gwtext.client.core.Function;
|
46 |
david |
17 |
import com.gwtext.client.data.ArrayReader;
|
12 |
david |
18 |
import com.gwtext.client.data.FieldDef;
|
46 |
david |
19 |
import com.gwtext.client.data.MemoryProxy;
|
12 |
david |
20 |
import com.gwtext.client.data.Record;
|
|
|
21 |
import com.gwtext.client.data.RecordDef;
|
|
|
22 |
import com.gwtext.client.data.Store;
|
|
|
23 |
import com.gwtext.client.data.StringFieldDef;
|
128 |
aurelien |
24 |
import com.gwtext.client.widgets.Button;
|
12 |
david |
25 |
import com.gwtext.client.widgets.Component;
|
101 |
jpm |
26 |
import com.gwtext.client.widgets.Tool;
|
128 |
aurelien |
27 |
import com.gwtext.client.widgets.Toolbar;
|
|
|
28 |
import com.gwtext.client.widgets.ToolbarButton;
|
|
|
29 |
import com.gwtext.client.widgets.ToolbarTextItem;
|
|
|
30 |
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
|
|
|
31 |
import com.gwtext.client.widgets.event.PanelListenerAdapter;
|
41 |
jpm |
32 |
import com.gwtext.client.widgets.grid.CellMetadata;
|
12 |
david |
33 |
import com.gwtext.client.widgets.grid.ColumnConfig;
|
|
|
34 |
import com.gwtext.client.widgets.grid.ColumnModel;
|
|
|
35 |
import com.gwtext.client.widgets.grid.GridPanel;
|
41 |
jpm |
36 |
import com.gwtext.client.widgets.grid.Renderer;
|
|
|
37 |
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
|
12 |
david |
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Liste d'observation composée de ligne d'observation
|
|
|
41 |
* l'interface rafraichissable et l'interface vueListable
|
|
|
42 |
*
|
|
|
43 |
* @author David Delon 2008
|
|
|
44 |
*/
|
|
|
45 |
public class ListeObservationVue extends GridPanel implements Rafraichissable,
|
59 |
david |
46 |
VueListable, ListePaginable {
|
12 |
david |
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Le médiateur associé à la vue
|
|
|
50 |
*/
|
|
|
51 |
private ObservationMediateur observationMediateur = null;
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Config de colonne
|
|
|
56 |
*/
|
|
|
57 |
private ColumnConfig etatObservation;
|
|
|
58 |
/**
|
|
|
59 |
* Config de colonne
|
|
|
60 |
*/
|
|
|
61 |
private ColumnConfig nomSaisiObservation;
|
|
|
62 |
/**
|
|
|
63 |
* Config de colonne
|
|
|
64 |
*/
|
|
|
65 |
private ColumnConfig nomRetenuObservation;
|
|
|
66 |
/**
|
|
|
67 |
* Config de colonne
|
|
|
68 |
*/
|
|
|
69 |
private ColumnConfig lieuObservation;
|
|
|
70 |
/**
|
|
|
71 |
* Config de colonne
|
|
|
72 |
*/
|
|
|
73 |
private ColumnConfig dateObservation;
|
|
|
74 |
/**
|
|
|
75 |
* Config de colonne
|
|
|
76 |
*/
|
|
|
77 |
private ColumnConfig ordreObservation;
|
|
|
78 |
/**
|
|
|
79 |
* Modele de colonnes
|
|
|
80 |
*/
|
|
|
81 |
private ColumnModel modeleColonnes;
|
|
|
82 |
|
82 |
david |
83 |
|
12 |
david |
84 |
/**
|
|
|
85 |
* Store qui contient les données à afficher
|
|
|
86 |
*/
|
|
|
87 |
private Store st = null;
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Barre de pagination
|
|
|
92 |
*/
|
59 |
david |
93 |
private BarrePaginationVue bt = null ;
|
12 |
david |
94 |
|
|
|
95 |
/**
|
46 |
david |
96 |
* Numéro de page en cours
|
|
|
97 |
*/
|
|
|
98 |
private int pageEncours = 0 ;
|
|
|
99 |
/**
|
|
|
100 |
* Nombre de pages totales
|
|
|
101 |
*/
|
|
|
102 |
private int pageMax = 1 ;
|
|
|
103 |
/**
|
|
|
104 |
* Taille de page (par défaut 20)
|
|
|
105 |
*/
|
|
|
106 |
private int taillePage = 20 ;
|
|
|
107 |
/**
|
|
|
108 |
* Nombre d'éléments total correspondant à la requete
|
|
|
109 |
*/
|
|
|
110 |
private int nbElements = 0 ;
|
|
|
111 |
|
82 |
david |
112 |
private ListeObservation cacheListeObservation = null;
|
46 |
david |
113 |
|
101 |
jpm |
114 |
private Tool exporterObservations = null ;
|
|
|
115 |
|
46 |
david |
116 |
/**
|
12 |
david |
117 |
* Constructeur sans arguments (privé car ne doit pas être utilisé)
|
|
|
118 |
*/
|
59 |
david |
119 |
@SuppressWarnings("unused")
|
12 |
david |
120 |
private ListeObservationVue()
|
|
|
121 |
{
|
|
|
122 |
super() ;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
* Constructeur avec argument
|
|
|
127 |
* @param im le médiateur à associer
|
|
|
128 |
*/
|
|
|
129 |
public ListeObservationVue(ObservationMediateur obs) {
|
|
|
130 |
|
|
|
131 |
this.observationMediateur = obs;
|
|
|
132 |
|
|
|
133 |
setHeader(true);
|
53 |
david |
134 |
|
12 |
david |
135 |
|
|
|
136 |
// on place la barre de pagination
|
59 |
david |
137 |
bt = new BarrePaginationVue(this);
|
|
|
138 |
bt.setLabelElement("Observations");
|
|
|
139 |
bt.setTaillePageParDefaut(20);
|
128 |
aurelien |
140 |
bt.setIntervallesPages(new String[] {"400","200", "100" , "50" , "20", "10"}) ;
|
|
|
141 |
this.setTopToolbar(bt) ;
|
94 |
jpm |
142 |
|
128 |
aurelien |
143 |
Toolbar barreActions = new Toolbar();
|
|
|
144 |
ToolbarButton transmettre = new ToolbarButton("Transmettre");
|
|
|
145 |
transmettre.addListener(new ButtonListenerAdapter() {
|
|
|
146 |
public void onClick(Button b, EventObject e) {
|
|
|
147 |
observationMediateur.transmettreObservations();
|
|
|
148 |
}
|
|
|
149 |
});
|
|
|
150 |
ToolbarButton supprimer = new ToolbarButton("Supprimer");
|
|
|
151 |
supprimer.addListener(new ButtonListenerAdapter() {
|
|
|
152 |
public void onClick(Button b, EventObject e) {
|
|
|
153 |
observationMediateur.supprimerObservations();
|
|
|
154 |
}
|
|
|
155 |
});
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
ToolbarTextItem exporter = new ToolbarTextItem("<a href=\"#\" id=\"lienExport\"> Exporter </a>");
|
|
|
159 |
|
|
|
160 |
barreActions.addButton(transmettre);
|
|
|
161 |
barreActions.addSpacer();
|
|
|
162 |
barreActions.addButton(supprimer);
|
|
|
163 |
barreActions.addSpacer();
|
|
|
164 |
barreActions.addItem(exporter);
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
this.setBottomToolbar(barreActions);
|
|
|
168 |
|
129 |
aurelien |
169 |
this.setCollapsible(true);
|
|
|
170 |
this.setTitleCollapse(true);
|
|
|
171 |
|
|
|
172 |
/*exporterObservations = new Tool(Tool.PIN, new Function() {
|
101 |
jpm |
173 |
|
|
|
174 |
public void execute() {
|
|
|
175 |
observationMediateur.exporterObservations() ;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
}, "Exporter des observations") ;
|
|
|
179 |
|
|
|
180 |
this.addTool(exporterObservations) ;
|
129 |
aurelien |
181 |
*/
|
94 |
jpm |
182 |
this.setTitle("Observations") ;
|
12 |
david |
183 |
|
|
|
184 |
// on construit le modèle de colonnes
|
|
|
185 |
|
|
|
186 |
// Le store suivant est ensuite remplacé par le store contenant les données obtenus depuis le serveur (cf rafraichir)
|
|
|
187 |
|
41 |
jpm |
188 |
Renderer colRend = new Renderer() {
|
|
|
189 |
|
|
|
190 |
public String render(Object value, CellMetadata cellMetadata,
|
|
|
191 |
Record record, int rowIndex, int colNum, Store store) {
|
|
|
192 |
|
|
|
193 |
if(value == null || value.equals("null") || value.equals("000null") || value.equals("0000-00-00 00:00:00")) {
|
|
|
194 |
|
|
|
195 |
return "" ;
|
|
|
196 |
}
|
|
|
197 |
else
|
|
|
198 |
{
|
|
|
199 |
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
return value.toString() ;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
} ;
|
12 |
david |
206 |
|
128 |
aurelien |
207 |
etatObservation = new ColumnConfig("Transmis", "etat_observation", 20, true, new Renderer() {
|
41 |
jpm |
208 |
|
|
|
209 |
public String render(Object value, CellMetadata cellMetadata,
|
|
|
210 |
Record record, int rowIndex, int colNum, Store store) {
|
|
|
211 |
if(value.equals("1"))
|
|
|
212 |
{
|
128 |
aurelien |
213 |
return "<img src=\"tela.png\"/></img>" ;
|
41 |
jpm |
214 |
}
|
|
|
215 |
else
|
|
|
216 |
{
|
|
|
217 |
return "" ;
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
});
|
|
|
222 |
nomSaisiObservation = new ColumnConfig("Nom saisi", "nomSaisi_observation", 200, true, colRend);
|
|
|
223 |
nomRetenuObservation = new ColumnConfig("Nom retenu", "nomRetenu_observation", 200, true, colRend);
|
|
|
224 |
lieuObservation = new ColumnConfig("Lieu", "lieu_observation", 200, true, colRend);
|
42 |
jpm |
225 |
dateObservation = new ColumnConfig("Date", "date_observation", 120, true, colRend);
|
41 |
jpm |
226 |
ordreObservation = new ColumnConfig("Ordre", "ordre_observation", 50, true, colRend);
|
42 |
jpm |
227 |
|
12 |
david |
228 |
|
|
|
229 |
// on associe le modèle de colonnes
|
|
|
230 |
|
|
|
231 |
ColumnConfig[] cm = {etatObservation, nomSaisiObservation, nomRetenuObservation, lieuObservation, dateObservation, ordreObservation};
|
|
|
232 |
|
|
|
233 |
modeleColonnes = new ColumnModel(cm);
|
|
|
234 |
|
|
|
235 |
this.setColumnModel(modeleColonnes);
|
|
|
236 |
|
|
|
237 |
this.setAutoScroll(true);
|
|
|
238 |
this.setEnableColumnResize(true);
|
|
|
239 |
|
46 |
david |
240 |
//temp dd viewport desactive ajout de ces 2 lignes
|
53 |
david |
241 |
// this.setAutoWidth(true);
|
46 |
david |
242 |
// temp
|
|
|
243 |
|
12 |
david |
244 |
// creation du store
|
52 |
david |
245 |
|
12 |
david |
246 |
FieldDef defEtatObservation = new StringFieldDef("etat_observation");
|
|
|
247 |
FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
|
|
|
248 |
FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
|
|
|
249 |
FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
|
|
|
250 |
FieldDef defDateObservation = new StringFieldDef("date_observation");
|
|
|
251 |
FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
|
|
|
255 |
defLieuObservation, defDateObservation, defOrdreObservation };
|
|
|
256 |
|
|
|
257 |
RecordDef rd = new RecordDef(defTab);
|
|
|
258 |
st = new Store(rd);
|
|
|
259 |
|
|
|
260 |
// on associe le store
|
|
|
261 |
|
|
|
262 |
this.setStore(st);
|
|
|
263 |
this.getView().setAutoFill(true);
|
42 |
jpm |
264 |
this.getView().setForceFit(true) ;
|
12 |
david |
265 |
|
|
|
266 |
// on crée un masque de chargement qui s'affichera lors des mises à jour
|
|
|
267 |
this.setLoadMask("Chargement");
|
|
|
268 |
|
|
|
269 |
// on ajoute les listeners
|
|
|
270 |
ajouterListeners();
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
/**
|
|
|
277 |
* Ajoute les listeners pour la gestion des évènements
|
|
|
278 |
*/
|
|
|
279 |
private void ajouterListeners() {
|
41 |
jpm |
280 |
|
|
|
281 |
this.addGridRowListener(new GridRowListenerAdapter() {
|
12 |
david |
282 |
|
|
|
283 |
// gestion du clic sur une ligne
|
41 |
jpm |
284 |
public void onRowClick(GridPanel grid, int rowIndex,
|
|
|
285 |
EventObject e) {
|
12 |
david |
286 |
// on notifie le médiateur et on lui passe le nuémro de ligne
|
71 |
jpm |
287 |
Record rd = getSelectionModel().getSelected();
|
|
|
288 |
String ordreObservation = rd.getAsString("ordre_observation") ;
|
82 |
david |
289 |
observationMediateur.onClicListeObservation(rowIndex,ordreObservation);
|
41 |
jpm |
290 |
|
12 |
david |
291 |
}
|
41 |
jpm |
292 |
|
12 |
david |
293 |
// gestion du clic droit
|
|
|
294 |
public void onRowContextMenu(GridPanel grid, int rowIndex,
|
|
|
295 |
EventObject e) {
|
|
|
296 |
// on stoppe l'évenement pour empecher le navigateur d'afficher son propre menu
|
|
|
297 |
e.stopEvent() ;
|
|
|
298 |
// on notifie le médiateur en lui passant l'évenement
|
54 |
david |
299 |
observationMediateur.montrerContextMenu(e);
|
12 |
david |
300 |
}
|
|
|
301 |
|
|
|
302 |
// gestion du double clic
|
|
|
303 |
public void onRowDblClick(GridPanel grid, int rowIndex,
|
|
|
304 |
EventObject e) {
|
|
|
305 |
// on notifie le médiateur en lui passant le numéro de ligne
|
54 |
david |
306 |
observationMediateur.doubleClicListeObservation(rowIndex);
|
12 |
david |
307 |
}
|
41 |
jpm |
308 |
|
12 |
david |
309 |
});
|
|
|
310 |
|
128 |
aurelien |
311 |
this.addListener(new PanelListenerAdapter() {
|
|
|
312 |
public void onRender(Component c) {
|
|
|
313 |
|
|
|
314 |
ExtElement lienExport = Ext.get("lienExport") ;
|
|
|
315 |
lienExport.addListener("click", new EventCallback() {
|
12 |
david |
316 |
|
128 |
aurelien |
317 |
public void execute(EventObject e) {
|
|
|
318 |
|
|
|
319 |
observationMediateur.exporterObservations();
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
});
|
12 |
david |
323 |
}
|
128 |
aurelien |
324 |
});
|
12 |
david |
325 |
}
|
|
|
326 |
|
|
|
327 |
/**
|
|
|
328 |
* Méthode héritée de l'interface VueListable
|
|
|
329 |
* Sélectionne les observations dans la liste suivant les identifiants donnés en paramètres
|
|
|
330 |
*/
|
|
|
331 |
|
|
|
332 |
public String[] getIdSelectionnees() {
|
|
|
333 |
|
|
|
334 |
Record[] selection = this.getSelectionModel().getSelections();
|
|
|
335 |
int taille = selection.length;
|
|
|
336 |
String id_selection[] = new String[taille];
|
|
|
337 |
|
|
|
338 |
for (int i = 0; i < selection.length; i++) {
|
|
|
339 |
|
|
|
340 |
id_selection[i] = selection[i].getAsString("ordre_observation");
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
return id_selection;
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
/**
|
|
|
349 |
* Sélectionne des enregistrements donné
|
|
|
350 |
* @param sel un tableau d'enregistrement à selectionner
|
|
|
351 |
*/
|
|
|
352 |
public void selectionnerEnregistrements(Record[] sel) {
|
|
|
353 |
|
|
|
354 |
getSelectionModel().clearSelections();
|
|
|
355 |
getSelectionModel().selectRecords(sel);
|
|
|
356 |
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
/**
|
|
|
360 |
* Accesseur pour la toolbar de pagination
|
|
|
361 |
* @return la toolbar de pagination
|
|
|
362 |
*/
|
|
|
363 |
|
59 |
david |
364 |
public BarrePaginationVue getToolBarVue()
|
12 |
david |
365 |
{
|
|
|
366 |
return bt ;
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
/**
|
|
|
371 |
* Recherche l'élement actuellement affiché et affiche son message de chargement
|
|
|
372 |
*/
|
|
|
373 |
public void masquerChargement()
|
|
|
374 |
{
|
|
|
375 |
ExtElement masked = Ext.get(getId()) ;
|
|
|
376 |
|
52 |
david |
377 |
|
12 |
david |
378 |
if (masked!=null) {
|
|
|
379 |
masked.mask("Chargement") ;
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
/**
|
|
|
385 |
* Recherche l'élement actuellement affiché et retire son message de chargement si l'était affiché
|
|
|
386 |
*/
|
|
|
387 |
public void demasquerChargement()
|
|
|
388 |
{
|
|
|
389 |
ExtElement masked = Ext.get(getId()) ;
|
|
|
390 |
|
52 |
david |
391 |
|
12 |
david |
392 |
if (masked!=null) {
|
|
|
393 |
|
|
|
394 |
if(masked.isMasked())
|
|
|
395 |
{
|
|
|
396 |
masked.unmask() ;
|
|
|
397 |
}
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
|
54 |
david |
402 |
|
46 |
david |
403 |
/**
|
|
|
404 |
* Méthode héritée de l'interface rafraichissable
|
|
|
405 |
* @param nouvelleDonnees les nouvelles données
|
|
|
406 |
* @param repandreRafraichissement le booleen de notification du rafraichissement
|
|
|
407 |
*/
|
|
|
408 |
|
12 |
david |
409 |
|
46 |
david |
410 |
|
|
|
411 |
public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
// si l'on a reçu une liste d'observation
|
|
|
417 |
if(nouvelleDonnees instanceof ListeObservation)
|
|
|
418 |
{
|
|
|
419 |
|
|
|
420 |
ListeObservation data = (ListeObservation) nouvelleDonnees ;
|
54 |
david |
421 |
Object[][] observationData = new Object[data.size()][7];
|
46 |
david |
422 |
int i = 0 ;
|
|
|
423 |
|
|
|
424 |
if(data.size() == 0)
|
|
|
425 |
{
|
|
|
426 |
pageEncours = 0 ;
|
|
|
427 |
}
|
|
|
428 |
|
54 |
david |
429 |
// on la parse et on récupère les informations qui nous interessent
|
46 |
david |
430 |
for (Iterator it = data.keySet().iterator(); it.hasNext();)
|
|
|
431 |
{
|
|
|
432 |
|
|
|
433 |
Observation obs=(Observation) data.get(it.next());
|
|
|
434 |
|
|
|
435 |
observationData[i][0]= obs.getTransmis();
|
|
|
436 |
observationData[i][1]= obs.getNomSaisi();
|
|
|
437 |
observationData[i][2]= obs.getNomRetenu();
|
|
|
438 |
observationData[i][3]= obs.getLieudit();
|
|
|
439 |
observationData[i][4]= obs.getDate();
|
|
|
440 |
observationData[i][5]= obs.getNumeroOrdre();
|
54 |
david |
441 |
observationData[i][6]= obs.getNumeroNomenclaturalSaisi();
|
46 |
david |
442 |
|
|
|
443 |
|
|
|
444 |
i++ ;
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
// creation du store qui les contient
|
|
|
448 |
|
|
|
449 |
FieldDef defEtatObservation = new StringFieldDef("etat_observation");
|
|
|
450 |
FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
|
|
|
451 |
FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
|
|
|
452 |
FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
|
|
|
453 |
FieldDef defDateObservation = new StringFieldDef("date_observation");
|
|
|
454 |
FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
|
|
|
455 |
|
54 |
david |
456 |
// Non affiches :
|
|
|
457 |
FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
|
|
|
458 |
|
|
|
459 |
|
46 |
david |
460 |
// on associe le store
|
|
|
461 |
|
|
|
462 |
FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
|
54 |
david |
463 |
defLieuObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation };
|
46 |
david |
464 |
|
|
|
465 |
RecordDef rd = new RecordDef(defTab);
|
|
|
466 |
|
|
|
467 |
final MemoryProxy dataProxy = new MemoryProxy(observationData);
|
|
|
468 |
final ArrayReader reader = new ArrayReader(rd);
|
|
|
469 |
|
|
|
470 |
final Store observationStore = new Store(dataProxy, reader);
|
|
|
471 |
|
|
|
472 |
|
|
|
473 |
st = observationStore ;
|
|
|
474 |
st.load() ;
|
|
|
475 |
|
|
|
476 |
|
|
|
477 |
// et on reconfigure et rafraichit la vue
|
|
|
478 |
this.reconfigure(st, this.getColumnModel());
|
|
|
479 |
|
|
|
480 |
demasquerChargement();
|
|
|
481 |
|
82 |
david |
482 |
cacheListeObservation=data;
|
|
|
483 |
|
|
|
484 |
observationMediateur.onRafraichissementListeObservations();
|
46 |
david |
485 |
|
82 |
david |
486 |
|
46 |
david |
487 |
}
|
|
|
488 |
|
|
|
489 |
|
|
|
490 |
// Si on reçoit un tableau d'entiers
|
|
|
491 |
// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères
|
|
|
492 |
if(nouvelleDonnees instanceof int[])
|
|
|
493 |
{
|
|
|
494 |
int[] pages = (int[])nouvelleDonnees ;
|
|
|
495 |
|
|
|
496 |
// on calcule le nombre de pages nécessaires et on les met à jour dans le modèle
|
|
|
497 |
pageMax = calculerNbPages(pages[0]) ;
|
|
|
498 |
nbElements = pages[0] ;
|
|
|
499 |
|
52 |
david |
500 |
|
46 |
david |
501 |
// et on notifie de le mediateur du changement des valeurs
|
51 |
david |
502 |
changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
|
46 |
david |
503 |
|
54 |
david |
504 |
masquerChargement();
|
82 |
david |
505 |
observationMediateur.obtenirListeObservation(this);
|
46 |
david |
506 |
}
|
|
|
507 |
|
|
|
508 |
|
82 |
david |
509 |
// si l'on a reçu une Observation
|
46 |
david |
510 |
|
|
|
511 |
if(nouvelleDonnees instanceof Observation) {
|
79 |
david |
512 |
|
|
|
513 |
Observation obs= (Observation) nouvelleDonnees;
|
|
|
514 |
if (obs.getNumeroOrdre()==null) { // Nouvelle observation
|
52 |
david |
515 |
// On affiche la dernière page
|
|
|
516 |
|
|
|
517 |
pageEncours = pageMax ;
|
54 |
david |
518 |
masquerChargement();
|
|
|
519 |
|
46 |
david |
520 |
observationMediateur.obtenirNombreObservation();
|
|
|
521 |
|
79 |
david |
522 |
}
|
|
|
523 |
else { // Modification d'une observation
|
|
|
524 |
|
82 |
david |
525 |
|
|
|
526 |
masquerChargement();
|
|
|
527 |
|
94 |
jpm |
528 |
observationMediateur.obtenirNombreObservation();
|
82 |
david |
529 |
|
79 |
david |
530 |
}
|
107 |
aurelien |
531 |
}
|
74 |
david |
532 |
|
107 |
aurelien |
533 |
// Si on a effectué une suppression
|
|
|
534 |
if(nouvelleDonnees instanceof String)
|
|
|
535 |
{
|
|
|
536 |
String str = (String)nouvelleDonnees ;
|
|
|
537 |
observationMediateur.obtenirNombreObservation() ;
|
|
|
538 |
}
|
|
|
539 |
|
46 |
david |
540 |
}
|
51 |
david |
541 |
|
|
|
542 |
|
|
|
543 |
// GESTION DE LA PAGINATION
|
46 |
david |
544 |
|
|
|
545 |
|
82 |
david |
546 |
public ListeObservation getCacheListeObservation() {
|
|
|
547 |
return cacheListeObservation;
|
|
|
548 |
}
|
|
|
549 |
|
46 |
david |
550 |
/**
|
|
|
551 |
* Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
|
|
|
552 |
* en cours
|
|
|
553 |
* @param nbElements le nombre d'élements total
|
|
|
554 |
* @return le nombre de pages
|
|
|
555 |
*/
|
|
|
556 |
public int calculerNbPages(int nbElements)
|
|
|
557 |
{
|
|
|
558 |
// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
|
|
|
559 |
// pour eviter qu'il arrondisse mal la division
|
|
|
560 |
// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
|
|
|
561 |
|
|
|
562 |
double nPage = (1.0*nbElements)/(1.0*taillePage) ;
|
|
|
563 |
double nPageRound = Math.ceil(nPage) ;
|
|
|
564 |
Double nPageInt = new Double(nPageRound) ;
|
|
|
565 |
|
|
|
566 |
// on convertit en entier
|
|
|
567 |
return nPageInt.intValue() ;
|
|
|
568 |
}
|
|
|
569 |
|
|
|
570 |
|
|
|
571 |
/**
|
|
|
572 |
* Recalcule la page en cours lors du changement du nombre d'élements
|
|
|
573 |
* @param nbElements le nombre d'élements total
|
|
|
574 |
* @return la nouvelle page encours
|
|
|
575 |
*/
|
|
|
576 |
public int calculerPageCourante(int nbElements)
|
|
|
577 |
{
|
|
|
578 |
// on calcule le nombre de page
|
|
|
579 |
int nouvelNbPages = calculerNbPages(nbElements) ;
|
|
|
580 |
// la nouvelle page en cours
|
|
|
581 |
double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
|
|
|
582 |
|
|
|
583 |
// on arrondit au supérieur
|
|
|
584 |
double nPageRound = Math.ceil(nPageCourante) ;
|
|
|
585 |
Double nPageInt = new Double(nPageRound) ;
|
|
|
586 |
|
|
|
587 |
// on convertit en entier
|
|
|
588 |
return Math.abs(nPageInt.intValue()) ;
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
|
|
|
592 |
/**
|
|
|
593 |
* Appelle le modèle pour lui demander les données d'une page à afficher
|
|
|
594 |
* @param pageCourante le numéro de page à affciher
|
|
|
595 |
*/
|
|
|
596 |
public void changerNumeroPage(int pageCourante) {
|
|
|
597 |
|
|
|
598 |
|
|
|
599 |
|
|
|
600 |
pageEncours = pageCourante ;
|
|
|
601 |
|
54 |
david |
602 |
masquerChargement();
|
|
|
603 |
|
46 |
david |
604 |
// On lance le chargerment des observations
|
|
|
605 |
observationMediateur.obtenirNombreObservation();
|
|
|
606 |
|
|
|
607 |
getToolBarVue().changerPageCourante(pageCourante);
|
|
|
608 |
|
|
|
609 |
}
|
|
|
610 |
|
|
|
611 |
|
|
|
612 |
/**
|
|
|
613 |
* Appelle le modèle pour qu'il change la taille de page utilisée
|
|
|
614 |
* @param nouvelleTaillePage la nouvelle taille de page
|
|
|
615 |
*/
|
|
|
616 |
|
|
|
617 |
public void changerTaillePage(int nouvelleTaillePage)
|
|
|
618 |
{
|
|
|
619 |
|
|
|
620 |
taillePage = nouvelleTaillePage ;
|
|
|
621 |
pageEncours = calculerPageCourante(nbElements) ;
|
|
|
622 |
|
54 |
david |
623 |
masquerChargement();
|
|
|
624 |
|
61 |
jpm |
625 |
// On lance le chargement des observations
|
46 |
david |
626 |
observationMediateur.obtenirNombreObservation();
|
|
|
627 |
|
|
|
628 |
|
|
|
629 |
// et on met à jour la taille de page dans les barres d'outils
|
|
|
630 |
getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
|
|
|
631 |
|
|
|
632 |
|
|
|
633 |
}
|
|
|
634 |
|
|
|
635 |
|
51 |
david |
636 |
/**
|
|
|
637 |
* Met à jour les barre d'outils avec des nouvelles valeurs
|
|
|
638 |
* @param pageMax le nombre de pages
|
|
|
639 |
* @param pageEncours la page en cours
|
|
|
640 |
* @param taillePage la taille de page
|
|
|
641 |
* @param nbElement le nombre d'élements par page
|
|
|
642 |
*/
|
|
|
643 |
public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement)
|
|
|
644 |
{
|
|
|
645 |
|
|
|
646 |
int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
|
|
|
647 |
getToolBarVue().rafraichir(pages, false) ;
|
|
|
648 |
|
|
|
649 |
}
|
46 |
david |
650 |
|
61 |
jpm |
651 |
/**
|
|
|
652 |
* Renvoie la taille de page en cours d'utilisation
|
|
|
653 |
* @return la taille de page
|
|
|
654 |
*/
|
46 |
david |
655 |
public int getTaillePage() {
|
|
|
656 |
|
|
|
657 |
return taillePage;
|
|
|
658 |
}
|
61 |
jpm |
659 |
|
|
|
660 |
/**
|
|
|
661 |
* Renvoie le numéro de la page encours (attention on commence à 0)
|
|
|
662 |
* @return le numéro de la page en cours
|
|
|
663 |
*/
|
46 |
david |
664 |
public int getPageEncours() {
|
|
|
665 |
|
|
|
666 |
return pageEncours;
|
|
|
667 |
}
|
|
|
668 |
|
94 |
jpm |
669 |
public void afficherFiltres(String nLieu, String nDate)
|
|
|
670 |
{
|
|
|
671 |
|
|
|
672 |
String titre = "Observations " ;
|
|
|
673 |
|
|
|
674 |
if(!nLieu.equals(""))
|
|
|
675 |
{
|
|
|
676 |
titre += " - Lieu : "+nLieu ;
|
|
|
677 |
|
|
|
678 |
}
|
|
|
679 |
|
|
|
680 |
if(!nDate .equals(""))
|
|
|
681 |
{
|
|
|
682 |
titre += " - Date : "+nDate ;
|
|
|
683 |
}
|
|
|
684 |
|
|
|
685 |
this.setTitle(titre) ;
|
|
|
686 |
}
|
46 |
david |
687 |
|
104 |
jpm |
688 |
public void raz() {
|
|
|
689 |
|
|
|
690 |
|
|
|
691 |
// creation du store qui les contient
|
|
|
692 |
|
|
|
693 |
FieldDef defEtatObservation = new StringFieldDef("etat_observation");
|
|
|
694 |
FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
|
|
|
695 |
FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
|
|
|
696 |
FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
|
|
|
697 |
FieldDef defDateObservation = new StringFieldDef("date_observation");
|
|
|
698 |
FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
|
|
|
699 |
|
|
|
700 |
// Non affiches :
|
|
|
701 |
FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
|
|
|
702 |
|
|
|
703 |
FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
|
|
|
704 |
defLieuObservation, defDateObservation, defOrdreObservation };
|
|
|
705 |
|
|
|
706 |
RecordDef rd = new RecordDef(defTab);
|
|
|
707 |
st = new Store(rd);
|
|
|
708 |
|
|
|
709 |
// on associe le store
|
|
|
710 |
|
|
|
711 |
this.setStore(st);
|
|
|
712 |
|
|
|
713 |
}
|
|
|
714 |
|
12 |
david |
715 |
}
|