Subversion Repositories eFlore/Applications.cel

Rev

Rev 42 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 46
Line 1... Line 1...
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
Line -... Line 2...
-
 
2
 
-
 
3
 
-
 
4
import java.util.Iterator;
-
 
5
 
2
 
6
import org.tela_botanica.client.modeles.ListeObservation;
3
 
7
import org.tela_botanica.client.modeles.Observation;
4
import org.tela_botanica.client.observation.ObservationMediateur;
8
import org.tela_botanica.client.observation.ObservationMediateur;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
Line 6... Line 10...
6
import org.tela_botanica.client.interfaces.VueListable;
10
import org.tela_botanica.client.interfaces.VueListable;
7
import org.tela_botanica.client.vues.BarrePaginationObservationVue;
11
import org.tela_botanica.client.vues.BarrePaginationListeObservationVue;
8
 
12
 
-
 
13
import com.gwtext.client.core.EventObject;
9
import com.gwtext.client.core.EventObject;
14
import com.gwtext.client.core.Ext;
-
 
15
import com.gwtext.client.core.ExtElement;
10
import com.gwtext.client.core.Ext;
16
import com.gwtext.client.data.ArrayReader;
11
import com.gwtext.client.core.ExtElement;
17
import com.gwtext.client.data.FieldDef;
12
import com.gwtext.client.data.FieldDef;
18
import com.gwtext.client.data.MemoryProxy;
13
import com.gwtext.client.data.Record;
19
import com.gwtext.client.data.Record;
14
import com.gwtext.client.data.RecordDef;
20
import com.gwtext.client.data.RecordDef;
Line 19... Line 25...
19
import com.gwtext.client.widgets.grid.CellMetadata;
25
import com.gwtext.client.widgets.grid.CellMetadata;
20
import com.gwtext.client.widgets.grid.ColumnConfig;
26
import com.gwtext.client.widgets.grid.ColumnConfig;
21
import com.gwtext.client.widgets.grid.ColumnModel;
27
import com.gwtext.client.widgets.grid.ColumnModel;
22
import com.gwtext.client.widgets.grid.GridPanel;
28
import com.gwtext.client.widgets.grid.GridPanel;
23
import com.gwtext.client.widgets.grid.Renderer;
29
import com.gwtext.client.widgets.grid.Renderer;
24
import com.gwtext.client.widgets.grid.RowSelectionModel;
-
 
25
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
30
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
26
import com.gwtext.client.widgets.grid.event.RowSelectionListenerAdapter;
-
 
Line 27... Line 31...
27
 
31
 
28
/**
32
/**
29
 * Liste d'observation composée de ligne d'observation
33
 * Liste d'observation composée de ligne d'observation
30
 * l'interface rafraichissable et l'interface vueListable
34
 * l'interface rafraichissable et l'interface vueListable
Line 76... Line 80...
76
	
80
	
77
	
81
	
78
	/**
82
	/**
79
	 * Barre de pagination
83
	 * Barre de pagination
Line -... Line 84...
-
 
84
	 */
-
 
85
	private BarrePaginationListeObservationVue bt = null ;
-
 
86
 
-
 
87
	
-
 
88
	
-
 
89
	/**
-
 
90
	 * Numéro de page en cours
-
 
91
	 */
-
 
92
	private int pageEncours = 0 ;
-
 
93
	/**
-
 
94
	 * Nombre de pages totales
-
 
95
	 */
-
 
96
	private int pageMax = 1 ;
-
 
97
	/**
-
 
98
	 * Taille de page (par défaut 20)
-
 
99
	 */
-
 
100
	private int taillePage = 20 ;
-
 
101
	/**
-
 
102
	 * Nombre d'éléments total correspondant à la requete
-
 
103
	 */
-
 
104
	private int nbElements = 0 ;
80
	 */
105
	
81
	private BarrePaginationObservationVue bt = null ;
106
	
82
 
107
	
83
	/**
108
	/**
84
	 * Constructeur sans arguments (privé car ne doit pas être utilisé)
109
	 * Constructeur sans arguments (privé car ne doit pas être utilisé)
Line 98... Line 123...
98
		
123
		
99
		setHeader(true);
124
		setHeader(true);
Line 100... Line 125...
100
		setTitle("Observations");
125
		setTitle("Observations");
101
        
126
        
102
		// on place la barre de pagination
127
		// on place la barre de pagination
Line 103... Line 128...
103
		bt = new BarrePaginationObservationVue(observationMediateur);		
128
		bt = new BarrePaginationListeObservationVue(this);		
Line 104... Line 129...
104
		this.setBottomToolbar(bt) ;
129
		this.setBottomToolbar(bt) ;
Line 157... Line 182...
157
		this.setColumnModel(modeleColonnes);
182
		this.setColumnModel(modeleColonnes);
Line 158... Line 183...
158
		
183
		
159
		this.setAutoScroll(true);
184
		this.setAutoScroll(true);
Line -... Line 185...
-
 
185
		this.setEnableColumnResize(true);
-
 
186
		
-
 
187
		//temp dd viewport desactive ajout de ces 2 lignes
-
 
188
		this.setAutoWidth(true);
-
 
189
		this.setAutoHeight(true) ;
160
		this.setEnableColumnResize(true);
190
		// temp
161
		
191
		
162
		// creation du store
192
		// creation du store
163
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
193
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
164
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
194
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
Line 280... Line 310...
280
		}
310
		}
Line 281... Line 311...
281
 
311
 
282
		return id_selection;
312
		return id_selection;
Line 283... Line -...
283
	}
-
 
284
	
-
 
285
	/**
-
 
286
	 * Méthode héritée de l'interface rafraichissable
-
 
287
	 * @param nouvelleDonnees les nouvelles données
-
 
288
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
-
 
289
	 */
-
 
290
	
-
 
291
	public void rafraichir(Object nouvelleDonnees,
-
 
292
			boolean repandreRafraichissement) {
-
 
293
 
-
 
294
		// si on reçoit un store
-
 
295
		if (nouvelleDonnees instanceof Store) {
-
 
296
		
-
 
297
			
-
 
298
			// on affecte celui-ci comme gestionnaire de données
-
 
299
			st = (Store) nouvelleDonnees;
-
 
300
			st.load();
-
 
301
			// et on reconfigure et rafraichit la vue
-
 
302
			this.reconfigure(st, this.getColumnModel());
-
 
303
			
-
 
304
			demasquerChargement();
-
 
305
			
-
 
306
						
-
 
307
		}
-
 
Line 308... Line 313...
308
 
313
	}
309
	}
314
	
310
 
315
 
Line 323... Line 328...
323
	/**
328
	/**
324
	 * Accesseur pour la toolbar de pagination
329
	 * Accesseur pour la toolbar de pagination
325
	 * @return la toolbar de pagination
330
	 * @return la toolbar de pagination
326
	 */
331
	 */
Line 327... Line 332...
327
	
332
	
328
	public BarrePaginationObservationVue getToolBarVue()
333
	public BarrePaginationListeObservationVue getToolBarVue()
329
	{
334
	{
330
		return bt ;
335
		return bt ;
Line 365... Line 370...
365
	private ObservationMediateur getObservationMediateur() {
370
	private ObservationMediateur getObservationMediateur() {
Line 366... Line 371...
366
		
371
		
367
		return observationMediateur ;
372
		return observationMediateur ;
Line -... Line 373...
-
 
373
	}
-
 
374
 
-
 
375
	/**
-
 
376
	 * Méthode héritée de l'interface rafraichissable
-
 
377
	 * @param nouvelleDonnees les nouvelles données
-
 
378
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
-
 
379
	 */
-
 
380
	
-
 
381
 
-
 
382
 
-
 
383
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
-
 
384
	
-
 
385
	
-
 
386
	
-
 
387
		
-
 
388
//		 si l'on a reçu une liste d'observation
-
 
389
		if(nouvelleDonnees instanceof ListeObservation)
-
 
390
		{
-
 
391
			
-
 
392
				ListeObservation data = (ListeObservation) nouvelleDonnees ;
-
 
393
				Object[][] observationData = new Object[data.size()][8];
-
 
394
				int i = 0 ;
-
 
395
				
-
 
396
				if(data.size() == 0)
-
 
397
				{
-
 
398
					pageEncours = 0 ;
-
 
399
				}
-
 
400
				
-
 
401
				// on la parse et on récupère les informations quiç nous interessent
-
 
402
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
-
 
403
				{
-
 
404
					
-
 
405
					Observation obs=(Observation) data.get(it.next());
-
 
406
					
-
 
407
					observationData[i][0]= obs.getTransmis();
-
 
408
					observationData[i][1]= obs.getNomSaisi();
-
 
409
					observationData[i][2]= obs.getNomRetenu();
-
 
410
					observationData[i][3]= obs.getLieudit();
-
 
411
					observationData[i][4]= obs.getDate();
-
 
412
					observationData[i][5]= obs.getNumeroOrdre();		
-
 
413
									
-
 
414
				
-
 
415
					i++ ;
-
 
416
				}
-
 
417
		
-
 
418
				// creation du store qui les contient
-
 
419
				
-
 
420
				FieldDef defEtatObservation = new StringFieldDef("etat_observation");
-
 
421
				FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
-
 
422
				FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
-
 
423
				FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
-
 
424
				FieldDef defDateObservation = new StringFieldDef("date_observation");
-
 
425
				FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
-
 
426
				
-
 
427
				// on associe le store
-
 
428
 
-
 
429
				FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
-
 
430
						defLieuObservation, defDateObservation, defOrdreObservation };
-
 
431
				
-
 
432
				RecordDef rd = new RecordDef(defTab);
-
 
433
				
-
 
434
				final MemoryProxy dataProxy = new MemoryProxy(observationData);
-
 
435
				final ArrayReader reader = new ArrayReader(rd);
-
 
436
		
-
 
437
				final Store observationStore = new Store(dataProxy, reader);
-
 
438
				
-
 
439
				
-
 
440
				st = observationStore ;
-
 
441
				st.load() ;
-
 
442
				
-
 
443
				
-
 
444
				// et on reconfigure et rafraichit la vue
-
 
445
				this.reconfigure(st, this.getColumnModel());
-
 
446
				
-
 
447
				demasquerChargement();
-
 
448
				
-
 
449
				
-
 
450
		}
-
 
451
		
-
 
452
		
-
 
453
		// Si on reçoit un tableau d'entiers
-
 
454
		// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères
-
 
455
		if(nouvelleDonnees instanceof int[])
-
 
456
		{
-
 
457
			int[] pages = (int[])nouvelleDonnees ;
-
 
458
			
-
 
459
			// on calcule le nombre de pages nécessaires et on les met à jour dans le modèle
-
 
460
			pageMax  = calculerNbPages(pages[0]) ;
-
 
461
			nbElements = pages[0] ;
-
 
462
			
-
 
463
			// et on notifie de le mediateur du changement des valeurs
-
 
464
			observationMediateur.changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
-
 
465
			
-
 
466
			observationMediateur.obtenirListeObservation();
-
 
467
		}
-
 
468
		
-
 
469
		
-
 
470
//		 si l'on a reçu une Observation, qui vient d'être cree on lance un raffraichissement
-
 
471
		
-
 
472
		if(nouvelleDonnees instanceof Observation) {
-
 
473
			
-
 
474
			observationMediateur.obtenirNombreObservation();
-
 
475
			
-
 
476
		}
-
 
477
	}
-
 
478
 
-
 
479
	
-
 
480
	/**
-
 
481
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
-
 
482
	 * en cours
-
 
483
	 * @param nbElements le nombre d'élements total
-
 
484
	 * @return le nombre de pages 
-
 
485
	 */
-
 
486
	public int calculerNbPages(int nbElements)
-
 
487
	{
-
 
488
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
-
 
489
		// pour eviter qu'il arrondisse mal la division
-
 
490
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
-
 
491
		
-
 
492
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
-
 
493
		double nPageRound = Math.ceil(nPage) ;
-
 
494
		Double nPageInt = new Double(nPageRound) ;
-
 
495
		
-
 
496
		// on convertit en entier
-
 
497
		return nPageInt.intValue() ; 
-
 
498
	}
-
 
499
 
-
 
500
	
-
 
501
	/**
-
 
502
	 * Recalcule la page en cours lors du changement du nombre d'élements
-
 
503
	 * @param nbElements le nombre d'élements total
-
 
504
	 * @return la nouvelle page encours
-
 
505
	 */
-
 
506
	public int calculerPageCourante(int nbElements)
-
 
507
	{
-
 
508
		// on calcule le nombre de page
-
 
509
		int nouvelNbPages = calculerNbPages(nbElements) ;
-
 
510
		// la nouvelle page en cours
-
 
511
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
-
 
512
		
-
 
513
		// on arrondit au supérieur
-
 
514
		double nPageRound = Math.ceil(nPageCourante) ;
-
 
515
		Double nPageInt = new Double(nPageRound) ;
-
 
516
		
-
 
517
		// on convertit en entier
-
 
518
		return Math.abs(nPageInt.intValue()) ; 
-
 
519
	}
-
 
520
	
-
 
521
 
-
 
522
	/**
-
 
523
	 * Appelle le modèle pour lui demander les données d'une page à afficher
-
 
524
	 * @param pageCourante le numéro de page à affciher
-
 
525
	 */
-
 
526
	public void changerNumeroPage(int pageCourante) {
-
 
527
		
-
 
528
		
-
 
529
		
-
 
530
		pageEncours = pageCourante ;
-
 
531
		
-
 
532
		// On lance le chargerment des observations
-
 
533
		observationMediateur.obtenirNombreObservation();
-
 
534
		
-
 
535
		getToolBarVue().changerPageCourante(pageCourante);
-
 
536
		
-
 
537
	}
-
 
538
	
-
 
539
	
-
 
540
	/**
-
 
541
	 * Appelle le modèle pour qu'il change la taille de page utilisée
-
 
542
	 * @param nouvelleTaillePage la nouvelle taille de page
-
 
543
	 */
-
 
544
	
-
 
545
	public void changerTaillePage(int nouvelleTaillePage)
-
 
546
	{
-
 
547
	
-
 
548
		taillePage = nouvelleTaillePage ;
-
 
549
		pageEncours = calculerPageCourante(nbElements) ;
-
 
550
 
-
 
551
		// 	On lance le chargerment des observations
-
 
552
		observationMediateur.obtenirNombreObservation();
-
 
553
		
-
 
554
		
-
 
555
		// et on met à jour la taille de page dans les barres d'outils
-
 
556
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
-
 
557
		
-
 
558
		
-
 
559
	}
-
 
560
 
-
 
561
	
-
 
562
	
-
 
563
	public int getTaillePage() {
-
 
564
		
-
 
565
		return taillePage;
-
 
566
	}
-
 
567
 
-
 
568
	public int getPageEncours() {
-
 
569
		
-
 
570
		return pageEncours;
Line 368... Line 571...
368
	}
571
	}