Subversion Repositories eFlore/Applications.cel

Rev

Rev 13 | 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;
13 david 10
import org.tela_botanica.client.modeles.ReferentielCommune;
20 david 11
import org.tela_botanica.client.modeles.ReferentielNom;
12 david 12
import org.tela_botanica.client.observation.ObservationMediateur;
13
 
14
 
13 david 15
import com.gwtext.client.core.EventCallback;
16
import com.gwtext.client.core.EventObject;
17
import com.gwtext.client.core.ListenerConfig;
12 david 18
import com.gwtext.client.core.Position;
13 david 19
import com.gwtext.client.data.ArrayReader;
20
import com.gwtext.client.data.FieldDef;
21
import com.gwtext.client.data.MemoryProxy;
22
import com.gwtext.client.data.RecordDef;
23
import com.gwtext.client.data.Store;
24
import com.gwtext.client.data.StringFieldDef;
12 david 25
import com.gwtext.client.widgets.Button;
26
import com.gwtext.client.widgets.Panel;
20 david 27
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
13 david 28
import com.gwtext.client.widgets.form.ComboBox;
12 david 29
import com.gwtext.client.widgets.form.DateField;
30
import com.gwtext.client.widgets.form.FormPanel;
31
import com.gwtext.client.widgets.form.TextField;
13 david 32
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
12 david 33
import com.gwtext.client.widgets.layout.ColumnLayout;
34
import com.gwtext.client.widgets.layout.ColumnLayoutData;
35
import com.gwtext.client.widgets.layout.FormLayout;
13 david 36
import com.gwtext.client.data.Record;
12 david 37
 
38
/**
39
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
40
 * @author aurelien
41
 *
42
 */
13 david 43
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 44
 
45
 
46
	/**
47
	 * Le médiateur associé à la vue
48
	 */
49
	private ObservationMediateur	observationMediateur		= null;
50
 
51
 
20 david 52
 
13 david 53
	private DateField date = null;
12 david 54
	private TextField lieudit = null;
55
	private TextField station = null;
56
	private TextField milieu = null;
57
	private TextField comment = null;
13 david 58
	private ComboBox  commune = null;
20 david 59
	private ComboBox  espece = null;
60
 
61
	private Button boutonOK = new Button("Ok");
62
	private Button boutonAnnuler = new Button("Annuler");
63
 
13 david 64
	private boolean selectionCommune=false;
20 david 65
	private boolean selectionEspece=false;
12 david 66
 
13 david 67
 
20 david 68
	private final int KEY_ALT = 18;
69
	private final int KEY_BACKSPACE = 8;
70
	private final int KEY_CTRL = 17;
71
	private final int KEY_DELETE = 46;
72
	private final int KEY_DOWN = 40;
73
	private final int KEY_END = 35;
74
	private final int KEY_ENTER = 13;
75
	private final int KEY_ESCAPE = 27;
76
	private final int KEY_HOME = 36;
77
	private final int KEY_LEFT = 37;
78
	private final int KEY_PAGEDOWN = 34;
79
	private final int KEY_PAGEUP = 33;
80
	private final int KEY_RIGHT = 39;
81
	private final int KEY_SHIFT = 16;
82
	private final int KEY_TAB = 9;
83
	private final int KEY_UP = 38;
13 david 84
 
85
 
20 david 86
 
13 david 87
 
12 david 88
	/**
89
	 * Booleen d'instanciation
90
	 */
91
	boolean estInstancie = false ;
92
 
93
	/**
94
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
95
	 */
96
	private FormulaireSaisieObservationVue()
97
	{
98
		super() ;
99
	}
100
 
101
	/**
102
	 * Constructeur avec argument
103
	 * @param im
104
	 */
105
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
106
	{
107
 
108
 
109
		// on associe le médiateur
110
		observationMediateur = obs ;
111
 
112
		this.setHeader(true);
113
		this.setTitle("Saisie");
114
 
115
 
116
		this.setCollapsible(true) ;
117
 
118
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
119
		panneauFormulaire.setBorder(false);
120
 
121
		// Panneau intermediaire qui contient deux colonnes de formulaire
122
 
123
		Panel panneauIntermediaire = new Panel();
124
		panneauIntermediaire.setLayout(new ColumnLayout());
125
		panneauIntermediaire.setBorder(false);
126
 
127
		//create first panel and add fields to it
128
		Panel panneauPremierColonne = new Panel();
129
		panneauPremierColonne.setLayout(new FormLayout());
130
		panneauPremierColonne.setBorder(false);
131
 
132
		//create second panel and add fields to it
133
	    Panel panneauSecondeColonne = new Panel();
134
		panneauSecondeColonne.setLayout(new FormLayout());
135
		panneauSecondeColonne.setBorder(false);
136
 
13 david 137
	/*
138
	    //	  creation du store
139
		FieldDef defCommune = new StringFieldDef("commune");
140
		FieldDef defDepartement = new StringFieldDef("departement");
12 david 141
 
13 david 142
 
143
		FieldDef[] defTab = { defCommune, defDepartement};
144
 
145
		RecordDef rd = new RecordDef(defTab);
146
 
147
 
148
		store = new Store(rd);
149
 
150
		//store.load();*/
151
 
20 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
 
20 david 226
 
12 david 227
		panneauFormulaire.addButton(boutonOK);
228
 
20 david 229
 
12 david 230
		panneauFormulaire.addButton(boutonAnnuler);
231
 
232
 
233
		this.add(panneauFormulaire) ;
234
 
235
 
236
		this.setAutoHeight(true);
237
 
238
 
239
		// on ajoute les listeners
240
		ajouterListeners() ;
241
 
242
 
243
 
244
	}
245
 
246
	private void ajouterListeners()
247
	{
20 david 248
 
249
 
250
		// Listener completion communne
251
 
252
		   commune.addListener(new ComboBoxListenerAdapter() {
253
	             public void onSelect(ComboBox comboBox, Record record, int index) {
254
	                 commune.setValue(record.getAsString("commune"));
255
	                 selectionCommune=true;
256
	             }
257
	         });
258
 
259
 
260
			ListenerConfig listenerConfigCommune=new ListenerConfig();
261
			listenerConfigCommune.setDelay(10);
262
			listenerConfigCommune.setStopPropagation(false);
263
			listenerConfigCommune.setStopEvent(false);
264
 
265
 
266
 
267
		    commune.addKeyPressListener(new EventCallback()	{
268
 
269
		    	    public void execute(EventObject e) {
270
 
271
 
272
		    	    		  switch(e.getKey()) {
273
 
274
 
275
		    	    		  case KEY_ALT:
276
		    	    	      case KEY_CTRL:
277
		    	    	      case KEY_DOWN:
278
		    	    	      case KEY_END:
279
		    	    	      case KEY_ESCAPE:
280
		    	    	      case KEY_HOME:
281
		    	    	      case KEY_LEFT:
282
		    	    	      case KEY_PAGEDOWN:
283
		    	    	      case KEY_PAGEUP:
284
		    	    	      case KEY_RIGHT:
285
		    	    	      case KEY_SHIFT:
286
		    	    	      case KEY_TAB:
287
		    	    	      case KEY_UP:
288
 
289
		    	    	        break;
290
 
291
		    	    	      case KEY_ENTER:
292
 
293
		    	    	    	 if (selectionCommune) {
294
		    	    	    		 selectionCommune=false;
295
		    	    	    	 }
296
		    	    	    	 else {
297
		    	    	    		// lancer mise a jour
298
		    	    	    	 }
299
 
300
 
301
		    	    	    	  break;
302
 
303
		    	    	      default:
304
 
305
		    	    	    	  obtenirListeReferentielCommune();
306
 
307
		    	    	        break;
308
		    	    	    }
309
 
310
 
311
 
312
		     		}
313
 
314
		    		},    listenerConfigCommune
315
 
316
			);
317
 
318
			// Listener completion espece
319
 
320
 
321
			espece.addListener(new ComboBoxListenerAdapter() {
322
	             public void onSelect(ComboBox comboBox, Record record, int index) {
323
	            	 espece.setValue(record.getAsString("nom"));
324
	                 selectionEspece=true;
325
	             }
326
	         });
327
 
328
 
329
			ListenerConfig listenerConfigEspece=new ListenerConfig();
330
			listenerConfigEspece.setDelay(10);
331
			listenerConfigEspece.setStopPropagation(false);
332
			listenerConfigEspece.setStopEvent(false);
333
 
334
 
335
			espece.addKeyPressListener(new EventCallback()	{
336
 
337
		    	    public void execute(EventObject e) {
338
 
339
 
340
		    	    		  switch(e.getKey()) {
341
 
342
 
343
		    	    		  case KEY_ALT:
344
		    	    	      case KEY_CTRL:
345
		    	    	      case KEY_DOWN:
346
		    	    	      case KEY_END:
347
		    	    	      case KEY_ESCAPE:
348
		    	    	      case KEY_HOME:
349
		    	    	      case KEY_LEFT:
350
		    	    	      case KEY_PAGEDOWN:
351
		    	    	      case KEY_PAGEUP:
352
		    	    	      case KEY_RIGHT:
353
		    	    	      case KEY_SHIFT:
354
		    	    	      case KEY_TAB:
355
		    	    	      case KEY_UP:
356
 
357
		    	    	        break;
358
 
359
		    	    	      case KEY_ENTER:
360
 
361
		    	    	    	 if (selectionEspece) {
362
		    	    	    		 selectionEspece=false;
363
		    	    	    	 }
364
		    	    	    	 else {
365
		    	    	    		// lancer mise a jour
366
		    	    	    	 }
367
 
368
 
369
		    	    	    	  break;
370
 
371
		    	    	      default:
372
 
373
		    	    	    	  obtenirListeReferentielNom();
374
 
375
		    	    	        break;
376
		    	    	    }
377
 
378
 
379
 
380
		     		}
381
 
382
		    		},    listenerConfigEspece
383
 
384
			);
385
 
386
 
387
 
388
 
389
		boutonOK.addListener(new ButtonListenerAdapter() {
390
			public void onClick(Button button, EventObject e) {
391
				observationMediateur.ajouterObservation(this);
392
			}
393
 
394
		});
395
 
12 david 396
		// on ajoute un écouteur
397
		/*validerInfo.addListener(new ButtonListenerAdapter() {
398
 
399
			// gestion du clic
400
 
401
			public void onClick(Button button, EventObject e) {
402
 
403
				// lors du clic sur le bouton valider on met à jour les commentaires et la date
404
		//	getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ;
405
 
406
			}
407
		});
408
		*/
409
 
410
 
411
	}
412
 
413
	/**
414
	 * Desactive visuellement ce panneau
415
	 */
416
	public void desactiverPanneau()
417
	{
418
		this.setDisabled(true) ;
419
	}
420
 
421
	/**
422
	 * Active visuellement ce panneau
423
	 */
424
	public void activerPanneau()
425
	{
426
		this.setDisabled(false) ;
427
	}
13 david 428
 
429
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
430
		//
431
 
432
 
433
		// si l'on a reçu une liste de commune
434
			if(nouvelleDonnees instanceof ListeReferentielCommune)
435
			{
436
 
437
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
438
					Object[][] communeData = new Object[data.size()][2];
439
					int i = 0 ;
440
 
441
					// on la parse et on récupère les informations quiç nous interessent
442
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
443
					{
444
 
445
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
446
 
447
						communeData[i][0]= ref.getCommune();
448
						communeData[i][1]= ref.getDepartement();
449
 
450
 
451
						i++ ;
452
					}
453
 
454
					   //	  creation du store
455
					FieldDef defCommune = new StringFieldDef("commune");
456
					FieldDef defDepartement = new StringFieldDef("departement");
457
 
458
 
459
					FieldDef[] defTab = { defCommune, defDepartement};
460
 
461
					RecordDef rd = new RecordDef(defTab);
462
 
463
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
464
					final ArrayReader reader = new ArrayReader(rd);
465
 
20 david 466
					Store store=new Store(dataProxy,reader);
13 david 467
					store.load() ;
468
 
469
					commune.setStore(store);
470
 
471
 
472
 
473
			}
20 david 474
 
475
//			 si l'on a reçu une liste de nom
476
 
477
			if(nouvelleDonnees instanceof ListeReferentielNom)
478
			{
479
 
480
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
481
					Object[][] nomData = new Object[data.size()][2];
482
					int i = 0 ;
483
 
484
					// on la parse et on récupère les informations quiç nous interessent
485
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
486
					{
487
 
488
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
489
 
490
						nomData[i][0]= ref.getNom();
491
						nomData[i][1]= ref.getNumeroNom();
492
 
493
 
494
						i++ ;
495
					}
496
 
497
					   //	  creation du store
498
					FieldDef defNom = new StringFieldDef("nom");
499
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
500
 
501
 
502
					FieldDef[] defTab = { defNom, defNumeroNom};
503
 
504
					RecordDef rd = new RecordDef(defTab);
505
 
506
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
507
					final ArrayReader reader = new ArrayReader(rd);
508
 
509
					Store store=new Store(dataProxy,reader);
510
					store.load() ;
511
 
512
					espece.setStore(store);
513
 
514
 
515
 
516
			}
517
 
518
 
13 david 519
	}
12 david 520
 
521
 
13 david 522
	public void obtenirListeReferentielCommune() {
20 david 523
	 String com=commune.getText().replaceAll(" ","/");
524
	 com=com.replaceAll("%","");
525
 
526
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 527
 
528
	}
20 david 529
 
530
 
531
	public void obtenirListeReferentielNom() {
532
 
533
	  String esp=espece.getText().replaceAll(" ","/");
534
	  esp=esp.replaceAll("%","");
535
 
536
	  observationMediateur.obtenirListeReferentielNom(this,esp);
537
 
538
	}
539
 
540
 
13 david 541
 
12 david 542
 
543
 
544
 
545
}