Subversion Repositories eFlore/Applications.cel

Rev

Rev 53 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12 david 1
package org.tela_botanica.client.vues;
2
 
3
 
4
 
13 david 5
import java.util.Iterator;
6
 
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.ListeReferentielCommune;
20 david 9
import org.tela_botanica.client.modeles.ListeReferentielNom;
39 david 10
import org.tela_botanica.client.modeles.Observation;
13 david 11
import org.tela_botanica.client.modeles.ReferentielCommune;
20 david 12
import org.tela_botanica.client.modeles.ReferentielNom;
12 david 13
import org.tela_botanica.client.observation.ObservationMediateur;
14
 
15
 
71 jpm 16
import com.google.gwt.user.client.Window;
13 david 17
import com.gwtext.client.core.EventCallback;
18
import com.gwtext.client.core.EventObject;
19
import com.gwtext.client.core.ListenerConfig;
12 david 20
import com.gwtext.client.core.Position;
71 jpm 21
import com.gwtext.client.core.Template;
13 david 22
import com.gwtext.client.data.ArrayReader;
23
import com.gwtext.client.data.FieldDef;
24
import com.gwtext.client.data.MemoryProxy;
25
import com.gwtext.client.data.RecordDef;
71 jpm 26
import com.gwtext.client.data.SimpleStore;
13 david 27
import com.gwtext.client.data.Store;
28
import com.gwtext.client.data.StringFieldDef;
12 david 29
import com.gwtext.client.widgets.Button;
30
import com.gwtext.client.widgets.Panel;
71 jpm 31
import com.gwtext.client.widgets.Toolbar;
20 david 32
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
13 david 33
import com.gwtext.client.widgets.form.ComboBox;
12 david 34
import com.gwtext.client.widgets.form.DateField;
35
import com.gwtext.client.widgets.form.FormPanel;
36
import com.gwtext.client.widgets.form.TextField;
13 david 37
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
12 david 38
import com.gwtext.client.widgets.layout.ColumnLayout;
39
import com.gwtext.client.widgets.layout.ColumnLayoutData;
40
import com.gwtext.client.widgets.layout.FormLayout;
13 david 41
import com.gwtext.client.data.Record;
12 david 42
 
43
/**
44
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
45
 * @author aurelien
46
 *
47
 */
13 david 48
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 49
 
50
 
51
	/**
52
	 * Le médiateur associé à la vue
53
	 */
54
	private ObservationMediateur	observationMediateur		= null;
55
 
56
 
20 david 57
 
13 david 58
	private DateField date = null;
12 david 59
	private TextField lieudit = null;
60
	private TextField station = null;
61
	private TextField milieu = null;
62
	private TextField comment = null;
13 david 63
	private ComboBox  commune = null;
39 david 64
	private String departement = null;
20 david 65
	private ComboBox  espece = null;
39 david 66
	private String numeroNom = null;
20 david 67
 
71 jpm 68
	private Button boutonOK = new Button("Créer");
20 david 69
	private Button boutonAnnuler = new Button("Annuler");
70
 
13 david 71
	private boolean selectionCommune=false;
20 david 72
	private boolean selectionEspece=false;
12 david 73
 
71 jpm 74
	private boolean modification = false ;
75
	private Toolbar bt = null ;
13 david 76
 
20 david 77
	private final int KEY_ALT = 18;
78
	private final int KEY_BACKSPACE = 8;
79
	private final int KEY_CTRL = 17;
80
	private final int KEY_DELETE = 46;
81
	private final int KEY_DOWN = 40;
82
	private final int KEY_END = 35;
83
	private final int KEY_ENTER = 13;
84
	private final int KEY_ESCAPE = 27;
85
	private final int KEY_HOME = 36;
86
	private final int KEY_LEFT = 37;
87
	private final int KEY_PAGEDOWN = 34;
88
	private final int KEY_PAGEUP = 33;
89
	private final int KEY_RIGHT = 39;
90
	private final int KEY_SHIFT = 16;
91
	private final int KEY_TAB = 9;
92
	private final int KEY_UP = 38;
13 david 93
 
71 jpm 94
	/**
95
	 * Combobox permettant de selectionner le mode
96
	 * modification ou bien création
97
	 */
98
	private ComboBox selecteurMode = new ComboBox();
13 david 99
 
71 jpm 100
	Store storeMode = null ;
13 david 101
 
12 david 102
	/**
103
	 * Booleen d'instanciation
104
	 */
105
	boolean estInstancie = false ;
106
 
107
	/**
108
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
109
	 */
71 jpm 110
	@SuppressWarnings("unused")
12 david 111
	private FormulaireSaisieObservationVue()
112
	{
113
		super() ;
114
	}
115
 
116
	/**
117
	 * Constructeur avec argument
118
	 * @param im
119
	 */
120
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
121
	{
122
 
123
 
124
		// on associe le médiateur
125
		observationMediateur = obs ;
126
 
127
 
53 david 128
		setHeader(true);
12 david 129
 
130
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
131
		panneauFormulaire.setBorder(false);
132
 
133
		// Panneau intermediaire qui contient deux colonnes de formulaire
134
 
135
		Panel panneauIntermediaire = new Panel();
136
		panneauIntermediaire.setLayout(new ColumnLayout());
137
		panneauIntermediaire.setBorder(false);
138
 
139
		//create first panel and add fields to it
140
		Panel panneauPremierColonne = new Panel();
141
		panneauPremierColonne.setLayout(new FormLayout());
142
		panneauPremierColonne.setBorder(false);
143
 
144
		//create second panel and add fields to it
145
	    Panel panneauSecondeColonne = new Panel();
146
		panneauSecondeColonne.setLayout(new FormLayout());
147
		panneauSecondeColonne.setBorder(false);
42 jpm 148
 
149
		this.setPaddings(5) ;
12 david 150
 
20 david 151
 
49 david 152
 
13 david 153
		commune=new ComboBox("Commune","commune",275 );
154
 
155
 
20 david 156
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
13 david 157
 
158
 
20 david 159
		commune.setTpl(resultTplCommune);
13 david 160
		commune.setMode(ComboBox.REMOTE);
161
		// commune.setPageSize(10); // Ne fonctionne pas
20 david 162
		commune.setItemSelector("div.search-item-commune");
13 david 163
		commune.setTypeAhead(true);
164
		commune.setLoadingText("Recherche...");
165
 
166
		commune.setHideTrigger(true);
167
 
168
 
20 david 169
 
13 david 170
 
171
 
172
	    panneauPremierColonne.add(commune);
173
 
174
 
175
 
12 david 176
	    station = new TextField("Station", "station", 275);
177
	    station.setAllowBlank(true);
178
	    panneauPremierColonne.add(station);
179
 
180
	    date = new DateField("Date", "date", 100);
181
	    date.setAllowBlank(true);
20 david 182
	    date.setFormat("d/m/Y") ;
12 david 183
	    panneauPremierColonne.add(date);
20 david 184
 
185
 
186
		espece=new ComboBox("Espèce","nom",275 );
12 david 187
 
20 david 188
 
189
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";
190
 
191
 
192
		espece.setTpl(resultTplEspece);
193
		espece.setMode(ComboBox.REMOTE);
194
		// commune.setPageSize(10); // Ne fonctionne pas
195
		espece.setItemSelector("div.search-item-espece");
196
		espece.setTypeAhead(true);
197
		espece.setLoadingText("Recherche...");
198
 
199
		espece.setHideTrigger(true);
200
 
201
 
202
 
203
	    panneauPremierColonne.add(espece);
204
 
12 david 205
	    comment = new TextField("Notes", "comment", 275);
206
	    comment.setAllowBlank(true);
207
	    panneauPremierColonne.add(comment);
208
 
209
 
210
	    lieudit = new TextField("Lieu-dit", "lieudit", 275);
211
	    lieudit.setAllowBlank(true);
212
	    panneauSecondeColonne.add(lieudit);
213
 
214
 
215
	    milieu = new TextField("Milieu", "milieu", 275);
216
	    milieu.setAllowBlank(true);
217
	    panneauSecondeColonne.add(milieu);
218
 
13 david 219
 
12 david 220
 
221
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
222
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
223
 
224
		panneauFormulaire.add(panneauIntermediaire);
225
 
71 jpm 226
		/*final Template tp = new Template("<div class=\"x-combo-list-item\">"
227
				+ "{nom_mode}" + "<div class=\"x-clear\"></div></div>");
228
		tp.compile();*/
20 david 229
 
71 jpm 230
		Object[][] mode = {{"création",false} , {"modification", true} };
231
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
232
				mode);
233
		storeMode.load();
234
		selecteurMode.setStore(storeMode);
235
		selecteurMode.setDisplayField("nom_mode") ;
236
		selecteurMode.setLabel("mode ") ;
237
		selecteurMode.setForceSelection(true) ;
238
		selecteurMode.setValue("création") ;
239
		selecteurMode.setEditable(false) ;
240
 
241
		bt = new Toolbar() ;
242
		bt.addSpacer() ;
243
		bt.addText("Mode de saisie ") ;
244
		bt.addField(selecteurMode) ;
245
 
12 david 246
		panneauFormulaire.addButton(boutonOK);
247
 
248
		panneauFormulaire.addButton(boutonAnnuler);
71 jpm 249
 
250
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
251
 
252
			public void onSelect(ComboBox comboBox, Record record, int index) {
253
 
254
				// et on met la valeur à jour dans la combobox
255
				comboBox.setValue(record.getAsString("nom_mode"));
256
				setModification(record.getAsString("mode")) ;
257
			}
258
 
259
		});
12 david 260
 
261
		this.add(panneauFormulaire) ;
71 jpm 262
		this.setBottomToolbar(bt) ;
12 david 263
 
264
 
265
		this.setAutoHeight(true);
266
 
267
 
268
		// on ajoute les listeners
269
		ajouterListeners() ;
270
 
271
 
272
 
273
	}
274
 
275
	private void ajouterListeners()
276
	{
20 david 277
 
278
 
279
		// Listener completion communne
280
 
281
		   commune.addListener(new ComboBoxListenerAdapter() {
282
	             public void onSelect(ComboBox comboBox, Record record, int index) {
283
	                 commune.setValue(record.getAsString("commune"));
39 david 284
	                 departement=record.getAsString("departement");
20 david 285
	                 selectionCommune=true;
286
	             }
287
	         });
288
 
289
 
290
			ListenerConfig listenerConfigCommune=new ListenerConfig();
291
			listenerConfigCommune.setDelay(10);
292
			listenerConfigCommune.setStopPropagation(false);
293
			listenerConfigCommune.setStopEvent(false);
294
 
295
 
296
 
297
		    commune.addKeyPressListener(new EventCallback()	{
298
 
299
		    	    public void execute(EventObject e) {
300
 
301
 
302
		    	    		  switch(e.getKey()) {
303
 
304
 
305
		    	    		  case KEY_ALT:
306
		    	    	      case KEY_CTRL:
307
		    	    	      case KEY_DOWN:
308
		    	    	      case KEY_END:
309
		    	    	      case KEY_ESCAPE:
310
		    	    	      case KEY_HOME:
311
		    	    	      case KEY_LEFT:
312
		    	    	      case KEY_PAGEDOWN:
313
		    	    	      case KEY_PAGEUP:
314
		    	    	      case KEY_RIGHT:
315
		    	    	      case KEY_SHIFT:
316
		    	    	      case KEY_TAB:
317
		    	    	      case KEY_UP:
318
 
319
		    	    	        break;
320
 
321
		    	    	      case KEY_ENTER:
322
 
323
		    	    	    	 if (selectionCommune) {
324
		    	    	    		 selectionCommune=false;
325
		    	    	    	 }
326
		    	    	    	 else {
327
		    	    	    		// lancer mise a jour
328
		    	    	    	 }
329
 
330
 
331
		    	    	    	  break;
332
 
333
		    	    	      default:
334
 
335
		    	    	    	  obtenirListeReferentielCommune();
336
 
337
		    	    	        break;
338
		    	    	    }
339
 
340
 
341
 
342
		     		}
343
 
344
		    		},    listenerConfigCommune
345
 
346
			);
347
 
348
			// Listener completion espece
349
 
350
 
351
			espece.addListener(new ComboBoxListenerAdapter() {
352
	             public void onSelect(ComboBox comboBox, Record record, int index) {
353
	            	 espece.setValue(record.getAsString("nom"));
39 david 354
	            	 numeroNom=record.getAsString("numeroNom");
20 david 355
	                 selectionEspece=true;
356
	             }
357
	         });
358
 
359
 
360
			ListenerConfig listenerConfigEspece=new ListenerConfig();
361
			listenerConfigEspece.setDelay(10);
362
			listenerConfigEspece.setStopPropagation(false);
363
			listenerConfigEspece.setStopEvent(false);
364
 
365
 
366
			espece.addKeyPressListener(new EventCallback()	{
367
 
368
		    	    public void execute(EventObject e) {
369
 
370
 
371
		    	    		  switch(e.getKey()) {
372
 
373
 
374
		    	    		  case KEY_ALT:
375
		    	    	      case KEY_CTRL:
376
		    	    	      case KEY_DOWN:
377
		    	    	      case KEY_END:
378
		    	    	      case KEY_ESCAPE:
379
		    	    	      case KEY_HOME:
380
		    	    	      case KEY_LEFT:
381
		    	    	      case KEY_PAGEDOWN:
382
		    	    	      case KEY_PAGEUP:
383
		    	    	      case KEY_RIGHT:
384
		    	    	      case KEY_SHIFT:
385
		    	    	      case KEY_TAB:
386
		    	    	      case KEY_UP:
387
 
388
		    	    	        break;
389
 
390
		    	    	      case KEY_ENTER:
391
 
392
		    	    	    	 if (selectionEspece) {
393
		    	    	    		 selectionEspece=false;
394
		    	    	    	 }
395
		    	    	    	 else {
396
		    	    	    		// lancer mise a jour
397
		    	    	    	 }
398
 
399
 
400
		    	    	    	  break;
401
 
402
		    	    	      default:
403
 
404
		    	    	    	  obtenirListeReferentielNom();
405
 
406
		    	    	        break;
407
		    	    	    }
408
 
409
 
410
 
411
		     		}
412
 
413
		    		},    listenerConfigEspece
414
 
415
			);
416
 
417
 
418
 
419
 
420
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 421
 
20 david 422
			public void onClick(Button button, EventObject e) {
39 david 423
 
71 jpm 424
				if(modification)
425
				{
426
					modifierObservation() ;
427
				}
428
				else
429
				{
430
					ajouterObservation();
431
				}
39 david 432
 
71 jpm 433
 
20 david 434
			}
435
 
436
		});
437
 
12 david 438
		// on ajoute un écouteur
439
		/*validerInfo.addListener(new ButtonListenerAdapter() {
440
 
441
			// gestion du clic
442
 
443
			public void onClick(Button button, EventObject e) {
444
 
445
				// lors du clic sur le bouton valider on met à jour les commentaires et la date
446
		//	getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ;
447
 
448
			}
449
		});
450
		*/
451
 
452
 
453
	}
454
 
455
	/**
456
	 * Desactive visuellement ce panneau
457
	 */
458
	public void desactiverPanneau()
459
	{
460
		this.setDisabled(true) ;
461
	}
462
 
463
	/**
464
	 * Active visuellement ce panneau
465
	 */
466
	public void activerPanneau()
467
	{
468
		this.setDisabled(false) ;
469
	}
13 david 470
 
471
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
472
 
49 david 473
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 474
			if(nouvelleDonnees instanceof ListeReferentielCommune)
475
			{
476
 
477
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
478
					Object[][] communeData = new Object[data.size()][2];
479
					int i = 0 ;
480
 
481
					// on la parse et on récupère les informations quiç nous interessent
482
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
483
					{
484
 
485
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
486
 
487
						communeData[i][0]= ref.getCommune();
488
						communeData[i][1]= ref.getDepartement();
489
 
490
 
491
						i++ ;
492
					}
493
 
494
					   //	  creation du store
495
					FieldDef defCommune = new StringFieldDef("commune");
496
					FieldDef defDepartement = new StringFieldDef("departement");
497
 
498
 
499
					FieldDef[] defTab = { defCommune, defDepartement};
500
 
501
					RecordDef rd = new RecordDef(defTab);
502
 
503
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
504
					final ArrayReader reader = new ArrayReader(rd);
505
 
20 david 506
					Store store=new Store(dataProxy,reader);
13 david 507
					store.load() ;
508
 
41 jpm 509
					commune.setStore(store);
13 david 510
 
511
			}
20 david 512
 
49 david 513
			//			 si l'on a reçu une liste du referentiel nom (complétion referentiel nom)
20 david 514
 
515
			if(nouvelleDonnees instanceof ListeReferentielNom)
516
			{
517
 
518
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
519
					Object[][] nomData = new Object[data.size()][2];
520
					int i = 0 ;
521
 
522
					// on la parse et on récupère les informations quiç nous interessent
523
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
524
					{
525
 
526
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
527
 
528
						nomData[i][0]= ref.getNom();
529
						nomData[i][1]= ref.getNumeroNom();
530
 
531
 
532
						i++ ;
533
					}
534
 
535
					   //	  creation du store
536
					FieldDef defNom = new StringFieldDef("nom");
537
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
538
 
539
 
540
					FieldDef[] defTab = { defNom, defNumeroNom};
541
 
542
					RecordDef rd = new RecordDef(defTab);
543
 
544
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
545
					final ArrayReader reader = new ArrayReader(rd);
546
 
547
					Store store=new Store(dataProxy,reader);
548
					store.load() ;
549
 
550
					espece.setStore(store);
551
 
552
 
553
 
554
			}
555
 
71 jpm 556
			if(nouvelleDonnees instanceof Observation)
557
			{
558
				Observation obs = (Observation)nouvelleDonnees ;
559
				afficherDetailsObservation(obs) ;
560
			}
20 david 561
 
13 david 562
	}
12 david 563
 
564
 
13 david 565
	public void obtenirListeReferentielCommune() {
20 david 566
	 String com=commune.getText().replaceAll(" ","/");
567
	 com=com.replaceAll("%","");
568
 
569
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 570
 
571
	}
20 david 572
 
573
 
574
	public void obtenirListeReferentielNom() {
575
 
576
	  String esp=espece.getText().replaceAll(" ","/");
577
	  esp=esp.replaceAll("%","");
578
 
579
	  observationMediateur.obtenirListeReferentielNom(this,esp);
580
 
581
	}
582
 
583
 
39 david 584
	public void ajouterObservation() {
585
 
41 jpm 586
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getText());
46 david 587
		observationMediateur.ajouterObservation(obs);
39 david 588
	}
12 david 589
 
71 jpm 590
	private void modifierObservation() {
591
		// TODO appeler le médiateur et mettre en place la modif
592
 
593
	}
12 david 594
 
71 jpm 595
 
596
	public void afficherDetailsObservation(Observation obs)
597
	{
598
		viderChampsObservation() ;
599
 
600
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null")) {
601
			String[] dateEtHeure = obs.getDate().split(" ", 2);
602
			date.setRawValue(dateEtHeure[0]) ;
603
		}
604
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
605
			lieudit.setValue(obs.getLieudit()) ;
606
		}
607
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
608
			station.setValue(obs.getStation()) ;
609
		}
610
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
611
			milieu.setValue(obs.getMilieu()) ;
612
		}
613
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
614
			comment.setValue(obs.getCommentaire()) ;
615
		}
616
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
617
			commune.setValue(obs.getLocalite()) ;
618
		}
619
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
620
			departement = obs.getIdentifiantLocalite();
621
		}
622
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
623
			espece.setValue(obs.getNomSaisi()) ;
624
		}
625
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
626
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
627
		}
628
	}
629
 
630
	public void viderChampsObservation()
631
	{
632
 
633
		date.reset() ;
634
		lieudit.reset() ;
635
		station.reset() ;
636
		milieu.reset();
637
		comment.reset();
638
		commune.reset();
639
		departement = "";
640
		espece.reset();
641
		numeroNom = "" ;
642
 
643
	}
644
 
645
	private void setModification(String mode)
646
	{
647
		if(mode.equals("true")) {
648
 
649
			boutonOK.setText("Modifier") ;
650
			setTitle("Modification") ;
651
			modification = true ;
652
		}
653
		else
654
		{
655
 
656
			boutonOK.setText("Créer") ;
657
			setTitle("Saisir") ;
658
			modification = false ;
659
		}
660
 
661
	}
662
 
663
 
664
	/**
665
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
666
	 * @return
667
	 */
668
	public boolean getModification()
669
	{
670
		return modification ;
671
	}
672
 
673
 
12 david 674
}