Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
195 david 1
package org.tela_botanica.client.vues.observation;
12 david 2
 
201 david 3
// TODO Detecter redim et supprimer ajuster
12 david 4
 
221 aurelien 5
import java.util.Date;
13 david 6
import java.util.Iterator;
7
 
8
import org.tela_botanica.client.interfaces.Rafraichissable;
264 aurelien 9
import org.tela_botanica.client.modeles.Configuration;
248 aurelien 10
import org.tela_botanica.client.modeles.EntiteGeographiqueObservation;
216 aurelien 11
import org.tela_botanica.client.modeles.ListeObservation;
13 david 12
import org.tela_botanica.client.modeles.ListeReferentielCommune;
20 david 13
import org.tela_botanica.client.modeles.ListeReferentielNom;
39 david 14
import org.tela_botanica.client.modeles.Observation;
13 david 15
import org.tela_botanica.client.modeles.ReferentielCommune;
20 david 16
import org.tela_botanica.client.modeles.ReferentielNom;
12 david 17
import org.tela_botanica.client.observation.ObservationMediateur;
132 aurelien 18
 
221 aurelien 19
import com.google.gwt.core.client.JavaScriptObject;
248 aurelien 20
import com.google.gwt.maps.client.geom.LatLng;
268 aurelien 21
import com.google.gwt.user.client.Timer;
216 aurelien 22
import com.google.gwt.user.client.Window;
268 aurelien 23
import com.google.gwt.user.client.ui.ClickListener;
248 aurelien 24
import com.google.gwt.user.client.ui.HTML;
268 aurelien 25
import com.google.gwt.user.client.ui.Widget;
13 david 26
import com.gwtext.client.core.EventCallback;
27
import com.gwtext.client.core.EventObject;
218 david 28
import com.gwtext.client.core.Ext;
248 aurelien 29
import com.gwtext.client.core.ExtElement;
268 aurelien 30
import com.gwtext.client.core.Function;
13 david 31
import com.gwtext.client.core.ListenerConfig;
12 david 32
import com.gwtext.client.core.Position;
13 david 33
import com.gwtext.client.data.ArrayReader;
34
import com.gwtext.client.data.FieldDef;
35
import com.gwtext.client.data.MemoryProxy;
36
import com.gwtext.client.data.RecordDef;
71 jpm 37
import com.gwtext.client.data.SimpleStore;
13 david 38
import com.gwtext.client.data.Store;
39
import com.gwtext.client.data.StringFieldDef;
132 aurelien 40
import com.gwtext.client.widgets.BoxComponent;
12 david 41
import com.gwtext.client.widgets.Button;
221 aurelien 42
import com.gwtext.client.widgets.Component;
132 aurelien 43
import com.gwtext.client.widgets.Container;
221 aurelien 44
import com.gwtext.client.widgets.DatePicker;
12 david 45
import com.gwtext.client.widgets.Panel;
248 aurelien 46
import com.gwtext.client.widgets.ToolTip;
71 jpm 47
import com.gwtext.client.widgets.Toolbar;
230 david 48
import com.gwtext.client.widgets.Viewport;
132 aurelien 49
import com.gwtext.client.widgets.event.BoxComponentListenerAdapter;
20 david 50
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
276 aurelien 51
import com.gwtext.client.widgets.event.ContainerListener;
132 aurelien 52
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
221 aurelien 53
import com.gwtext.client.widgets.event.DatePickerListener;
54
import com.gwtext.client.widgets.event.DatePickerListenerAdapter;
276 aurelien 55
import com.gwtext.client.widgets.event.PanelListener;
201 david 56
import com.gwtext.client.widgets.event.PanelListenerAdapter;
13 david 57
import com.gwtext.client.widgets.form.ComboBox;
12 david 58
import com.gwtext.client.widgets.form.DateField;
216 aurelien 59
import com.gwtext.client.widgets.form.Field;
12 david 60
import com.gwtext.client.widgets.form.FormPanel;
268 aurelien 61
import com.gwtext.client.widgets.form.Label;
248 aurelien 62
import com.gwtext.client.widgets.form.MultiFieldPanel;
128 aurelien 63
import com.gwtext.client.widgets.form.TextArea;
12 david 64
import com.gwtext.client.widgets.form.TextField;
13 david 65
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
268 aurelien 66
import com.gwtext.client.widgets.form.event.TextFieldListener;
248 aurelien 67
import com.gwtext.client.widgets.form.event.TextFieldListenerAdapter;
201 david 68
import com.gwtext.client.widgets.layout.AnchorLayoutData;
12 david 69
import com.gwtext.client.widgets.layout.ColumnLayout;
70
import com.gwtext.client.widgets.layout.ColumnLayoutData;
71
import com.gwtext.client.widgets.layout.FormLayout;
230 david 72
import com.gwtext.client.widgets.layout.RowLayout;
13 david 73
import com.gwtext.client.data.Record;
12 david 74
 
75
/**
76
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
77
 * @author aurelien
78
 *
79
 */
13 david 80
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 81
 
82
 
83
	/**
84
	 * Le médiateur associé à la vue
85
	 */
86
	private ObservationMediateur	observationMediateur		= null;
87
 
205 aurelien 88
	FormPanel panneauFormulaire = null;
20 david 89
 
13 david 90
	private DateField date = null;
12 david 91
	private TextField lieudit = null;
92
	private TextField station = null;
93
	private TextField milieu = null;
94
	private TextField comment = null;
13 david 95
	private ComboBox  commune = null;
39 david 96
	private String departement = null;
20 david 97
	private ComboBox  espece = null;
39 david 98
	private String numeroNom = null;
74 david 99
	private String numeroOrdre = null;
264 aurelien 100
 
101
	private String referentielGeo = null;
20 david 102
 
118 david 103
	// Pour remise a zero partielle lors d'une validation
104
 
105
	private  enum Champs {
264 aurelien 106
	    DATE, LIEUDIT, STATION, MILIEU, COMMENT, COMMUNE, ESPECE, TOUT, LATITUDE, LONGITUDE ;
216 aurelien 107
 
108
	    public String toString() {
109
 
110
	    	switch(this) {
111
	    	case DATE:
112
	    		return "date";
113
 
114
	    	case COMMUNE:
115
	    		return "commune";
116
 
117
    		case LIEUDIT:
118
    			return "lieu dit";
119
 
120
    		case STATION:
121
    			return "station";
122
 
123
    		case MILIEU:
124
    			return "milieu";
125
 
126
    		case COMMENT:
127
    			return "commentaire";
128
 
129
	    	case ESPECE:
130
	    		return "espèce";
264 aurelien 131
 
132
	    	case LATITUDE:
133
	    		return "latitude";
134
 
135
	    	case LONGITUDE:
136
	    		return "longitude";
216 aurelien 137
 
138
	    	case TOUT:
264 aurelien 139
	    		return "date, commune, lieu dit, station, milieu, espèce, commentaire, latitude, longitude";
216 aurelien 140
	    	}
141
			return TOUT.toString();
142
	    }
118 david 143
	};
144
 
110 aurelien 145
	private String formatDate = null ;
71 jpm 146
	private Button boutonOK = new Button("Créer");
77 jpm 147
	private Button boutonAnnuler = new Button("Réinitialiser");
20 david 148
 
13 david 149
	private boolean selectionCommune=false;
20 david 150
	private boolean selectionEspece=false;
12 david 151
 
71 jpm 152
	private boolean modification = false ;
153
	private Toolbar bt = null ;
13 david 154
 
216 aurelien 155
	private final String VALEURS_MULTIPLES = "(Valeurs multiples)";
264 aurelien 156
	private final String modeleMessageModif = "commune:lieu-dit:station:milieu:latitude:longitude:date:espece:commentaire";
216 aurelien 157
	private boolean communeModifiee = false;
221 aurelien 158
	private boolean lieuDitModifie = false;
159
	private boolean stationModifiee = false;
216 aurelien 160
	private boolean milieuModifie = false;
161
	private boolean dateModifiee = false;
162
	private boolean especeModifiee = false;
163
	private boolean commModifie = false;
164
 
165
 
20 david 166
	private final int KEY_ALT = 18;
167
	private final int KEY_BACKSPACE = 8;
168
	private final int KEY_CTRL = 17;
169
	private final int KEY_DELETE = 46;
170
	private final int KEY_DOWN = 40;
171
	private final int KEY_END = 35;
172
	private final int KEY_ENTER = 13;
173
	private final int KEY_ESCAPE = 27;
174
	private final int KEY_HOME = 36;
175
	private final int KEY_LEFT = 37;
176
	private final int KEY_PAGEDOWN = 34;
177
	private final int KEY_PAGEUP = 33;
178
	private final int KEY_RIGHT = 39;
179
	private final int KEY_SHIFT = 16;
180
	private final int KEY_TAB = 9;
181
	private final int KEY_UP = 38;
13 david 182
 
128 aurelien 183
 
71 jpm 184
	/**
185
	 * Combobox permettant de selectionner le mode
186
	 * modification ou bien création
187
	 */
188
	private ComboBox selecteurMode = new ComboBox();
13 david 189
 
71 jpm 190
	Store storeMode = null ;
13 david 191
 
12 david 192
	/**
193
	 * Booleen d'instanciation
194
	 */
195
	boolean estInstancie = false ;
205 aurelien 196
 
197
	private Panel panneauIntermediaire;
198
 
199
	private Panel panneauPremierColonne;
200
 
201
	private Panel panneauSecondeColonne;
216 aurelien 202
 
203
	private boolean masseModification =false ;
248 aurelien 204
 
205
	private TextField longitude;
206
 
207
	private TextField latitude;
208
 
209
	private MultiFieldPanel coordPanel;
210
 
211
	private TextField coordonnees;
268 aurelien 212
 
213
	private Label lienSelectionCommune = null;
248 aurelien 214
 
215
	private HTML accesformulaire;
216
 
217
	private HTML basculerverscarto;
12 david 218
 
248 aurelien 219
	private boolean longlatAjoutee;
264 aurelien 220
 
221
	private boolean latModifiee;
222
 
223
	private boolean longModifiee;
268 aurelien 224
 
225
	protected boolean rechercheCommuneEnCours = false;
226
 
227
	private Timer tCoord;
248 aurelien 228
 
12 david 229
	/**
230
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
231
	 */
71 jpm 232
	@SuppressWarnings("unused")
12 david 233
	private FormulaireSaisieObservationVue()
234
	{
235
		super() ;
236
	}
237
 
238
	/**
239
	 * Constructeur avec argument
240
	 * @param im
241
	 */
242
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
243
	{
246 aurelien 244
 
245
		super("Saisie");
12 david 246
		// on associe le médiateur
247
		observationMediateur = obs ;
248
 
201 david 249
 
205 aurelien 250
		panneauFormulaire = new FormPanel(Position.RIGHT);
12 david 251
		panneauFormulaire.setBorder(false);
252
 
218 david 253
 
254
 
12 david 255
		// Panneau intermediaire qui contient deux colonnes de formulaire
256
 
205 aurelien 257
		panneauIntermediaire = new Panel();
230 david 258
 
259
		if (Window.getClientWidth()> Window.getClientHeight()) {
260
			panneauIntermediaire.setLayout(new ColumnLayout());
261
		}
262
		else {
263
			panneauIntermediaire.setLayout(new RowLayout());
264
		}
265
 
12 david 266
		panneauIntermediaire.setBorder(false);
218 david 267
 
12 david 268
		//create first panel and add fields to it
205 aurelien 269
		panneauPremierColonne = new Panel();
12 david 270
		panneauPremierColonne.setLayout(new FormLayout());
271
		panneauPremierColonne.setBorder(false);
272
 
273
		//create second panel and add fields to it
205 aurelien 274
	    panneauSecondeColonne = new Panel();
12 david 275
		panneauSecondeColonne.setLayout(new FormLayout());
276
		panneauSecondeColonne.setBorder(false);
276 aurelien 277
 
42 jpm 278
		this.setPaddings(5) ;
12 david 279
 
195 david 280
		// Accesskey pour debugging
281
 
201 david 282
		commune=new ComboBox("Commune","commune\" accesskey=\"1");
195 david 283
 
20 david 284
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
285
		commune.setTpl(resultTplCommune);
13 david 286
		commune.setMode(ComboBox.REMOTE);
287
		// commune.setPageSize(10); // Ne fonctionne pas
20 david 288
		commune.setItemSelector("div.search-item-commune");
13 david 289
		commune.setTypeAhead(true);
290
		commune.setLoadingText("Recherche...");
291
 
292
		commune.setHideTrigger(true);
248 aurelien 293
		//commune.setTabIndex(1);
13 david 294
 
268 aurelien 295
		  //création du lien "Accès carto" dans le formulaire
296
		basculerverscarto = new HTML(" <a id=\"lien_carto\" href=\"#\" tabindex=\"2\">Localiser</a>");
297
		basculerverscarto.addStyleName("lien_actif");
298
 
299
		//création info bulle sur le lien "accès carto"
300
		ToolTip tip2 = new ToolTip();
301
		tip2.setHtml("Via une carte, obtenez les coordonnées (longitude/latitude) de votre observation ");
302
		tip2.applyTo(basculerverscarto.getElement());
303
 
304
		//Sur une meme ligne, ajout de plusieurs champs
276 aurelien 305
		final MultiFieldPanel htmlCommunePanel = new MultiFieldPanel();
306
 
307
		htmlCommunePanel.addToRow(commune,new ColumnLayoutData(0.7));
308
		htmlCommunePanel.addToRow(basculerverscarto,new ColumnLayoutData(0.3));
309
 
268 aurelien 310
		htmlCommunePanel.setBorder(false);
311
		htmlCommunePanel.setId("x-commune-panel");
13 david 312
 
268 aurelien 313
		panneauPremierColonne.add(htmlCommunePanel);
314
 
201 david 315
	    station = new TextField("Station", "station");
132 aurelien 316
	    station.setAllowBlank(true);
268 aurelien 317
 
201 david 318
	    panneauPremierColonne.add(station, new AnchorLayoutData("95%"));
12 david 319
 
276 aurelien 320
		latitude = new TextField("X", "x");
321
		latitude.setGrowMax(200);
264 aurelien 322
		latitude.setAllowBlank(true);
323
 
276 aurelien 324
	    longitude = new TextField("Y", "y");
325
	    longitude.setGrowMax(200);
248 aurelien 326
		longitude.setAllowBlank(true);
276 aurelien 327
 
328
		lienSelectionCommune = new Label("");
268 aurelien 329
 
276 aurelien 330
 
268 aurelien 331
		lienSelectionCommune.setId("conteneur_selection_commune");
332
		lienSelectionCommune.setStyleName("conteneur_selection_commune");
276 aurelien 333
		lienSelectionCommune.addStyleName("lien_actif");
264 aurelien 334
 
248 aurelien 335
		// Panneau de type plusieurs champs de formulaire sur une meme ligne, où seront renseignés X/Y
336
		coordPanel = new MultiFieldPanel();
276 aurelien 337
		//FormLayout coordFormLayout = new FormLayout();
338
		//coordFormLayout.setLabelWidth(5);
339
		//coordPanel.setLayout(coordFormLayout);
340
		coordPanel.setPaddings(0);
248 aurelien 341
		coordPanel.setVisible(false);
276 aurelien 342
 
343
		final double largeur ;
344
 
345
		if(Ext.isIE()) {
346
			largeur = 50;
347
			coordPanel.setPaddings(0, 0, 0, 30);
348
			lienSelectionCommune.addClass("lien_decale");
349
		} else {
350
			largeur = 0.34;
351
		}
352
 
353
		coordPanel.addToRow(latitude, new ColumnLayoutData(largeur));
354
		coordPanel.addToRow(longitude, new ColumnLayoutData(largeur));
355
		coordPanel.addToRow(lienSelectionCommune, new ColumnLayoutData(150));
248 aurelien 356
		coordPanel.setBorder(false);
357
 
264 aurelien 358
		  //création du champs coordonnées
359
		referentielGeo = Configuration.getReferentielGeo();
248 aurelien 360
 
268 aurelien 361
		coordonnees = new TextField("Coordonnées", "", 0);
248 aurelien 362
		coordonnees.setMaxLength(0);
363
		coordonnees.setReadOnly(true);
364
		coordonnees.setCls("fieldname");
365
 
276 aurelien 366
		//création du lien "saisie X/Y" dans le formulaire
268 aurelien 367
		accesformulaire = new HTML("<a id=\"lien_coord\" href=\"#\" tabindex=\"6\">Saisie X/Y ("+referentielGeo+")</a>");
276 aurelien 368
		accesformulaire.setWidth("100%");
268 aurelien 369
		accesformulaire.addStyleName("lien_actif");
248 aurelien 370
 
371
		//création info bulle sur le lien "saisie X/Y"
372
			ToolTip tip1 = new ToolTip();
373
			tip1.setHtml("X / Y sont les longitudes / latitudes, à remplir en degrés décimaux");
374
			tip1.applyTo(accesformulaire.getElement());
375
 
376
			//ajout d'un listener sur le lien "saisie X/Y"
377
 
378
			coordPanel.addListener(new PanelListenerAdapter() {
379
 
380
				public void onAfterLayout(Container c) {
381
					ExtElement lienCoord = Ext.get("lien_coord");
382
					lienCoord.removeAllListeners();
383
					lienCoord.addListener("click", new EventCallback() {
384
						public void execute(EventObject e) {
276 aurelien 385
 
248 aurelien 386
							coordPanel.setVisible(!coordPanel.isVisible());
276 aurelien 387
 
388
							if(Ext.isIE()) {
389
								ObservationMediateur.fireResize();
390
								latitude.focus();
391
							}
248 aurelien 392
						}
393
					}) ;
394
 
395
					ExtElement lienCarto = Ext.get("lien_carto");
396
					lienCarto.removeAllListeners();
397
					lienCarto.addListener("click", new EventCallback() {
398
 
399
						public void execute(EventObject e) {
400
 
268 aurelien 401
							if(commune.getValue() != null && !commune.getValue().equals("")) {
402
								obtenirInformationCommune();
403
								longlatAjoutee = true;
404
 
248 aurelien 405
							} else {
268 aurelien 406
								Window.alert("Veuillez renseigner une commune à préciser");
248 aurelien 407
							}
408
						}
409
					});
410
				}
411
 
412
			});
268 aurelien 413
 
276 aurelien 414
		//Sur une meme ligne, ajout de plusieurs champs
415
		final MultiFieldPanel htmlPanel = new MultiFieldPanel();
416
 
417
		htmlPanel.addToRow(coordonnees, 100);
418
		htmlPanel.addToRow(accesformulaire, new ColumnLayoutData(0.5));
419
		htmlPanel.setBorder(false);
420
		htmlPanel.setId("x-coord-panel");
248 aurelien 421
 
422
		panneauPremierColonne.add(htmlPanel);
423
		panneauPremierColonne.add(coordPanel);
424
 
12 david 425
	    date = new DateField("Date", "date", 100);
426
	    date.setAllowBlank(true);
110 aurelien 427
	    formatDate = "d/m/Y";
428
	    date.setFormat(formatDate) ;
248 aurelien 429
	    //date.setTabIndex(5);
201 david 430
	    panneauPremierColonne.add(date, new AnchorLayoutData("60%"));
20 david 431
 
432
 
201 david 433
		espece=new ComboBox("Espèce","nom");
12 david 434
 
20 david 435
 
436
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";
437
 
438
 
439
		espece.setTpl(resultTplEspece);
440
		espece.setMode(ComboBox.REMOTE);
441
		// commune.setPageSize(10); // Ne fonctionne pas
442
		espece.setItemSelector("div.search-item-espece");
443
		espece.setTypeAhead(true);
444
		espece.setLoadingText("Recherche...");
445
 
446
		espece.setHideTrigger(true);
248 aurelien 447
		//espece.setTabIndex(6);
20 david 448
 
201 david 449
	    panneauPremierColonne.add(espece, new AnchorLayoutData("95%"));
20 david 450
 
201 david 451
	    lieudit = new TextField("Lieu-dit", "lieudit");
132 aurelien 452
	    lieudit.setAllowBlank(true);
248 aurelien 453
	    //lieudit.setTabIndex(2);
201 david 454
	    panneauSecondeColonne.add(lieudit,  new AnchorLayoutData("95%"));
12 david 455
 
456
 
201 david 457
	    milieu = new TextField("Milieu", "milieu");
132 aurelien 458
	    milieu.setAllowBlank(true);
248 aurelien 459
	    //milieu.setTabIndex(4);
201 david 460
	    panneauSecondeColonne.add(milieu,  new AnchorLayoutData("95%"));
128 aurelien 461
 
462
	    comment = new TextArea("Notes", "comment");
463
	    comment.setAllowBlank(true);
464
	    comment.setHeight(50);
248 aurelien 465
	    //comment.setTabIndex(7);
201 david 466
	    panneauSecondeColonne.add(comment, new AnchorLayoutData("95%") );
230 david 467
 
276 aurelien 468
	    if (Window.getClientWidth() > Window.getClientHeight() || Window.getClientWidth() < 800) {
230 david 469
			panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
470
			panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
471
	    }
472
	    else {
473
			panneauIntermediaire.add(panneauPremierColonne);
474
			panneauIntermediaire.add(panneauSecondeColonne);
475
 
476
	    }
477
 
12 david 478
		panneauFormulaire.add(panneauIntermediaire);
479
 
71 jpm 480
		Object[][] mode = {{"création",false} , {"modification", true} };
481
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
482
				mode);
483
		storeMode.load();
484
		selecteurMode.setStore(storeMode);
485
		selecteurMode.setDisplayField("nom_mode") ;
486
		selecteurMode.setLabel("mode ") ;
487
		selecteurMode.setForceSelection(true) ;
488
		selecteurMode.setValue("création") ;
489
		selecteurMode.setEditable(false) ;
97 jpm 490
		selecteurMode.setCls("x-selec-crea") ;
71 jpm 491
 
492
		bt = new Toolbar() ;
493
		bt.addSpacer() ;
494
		bt.addText("Mode de saisie ") ;
495
		bt.addField(selecteurMode) ;
496
 
74 david 497
 
276 aurelien 498
		if (Ext.isIE()) {
218 david 499
			panneauPremierColonne.setButtonAlign(Position.RIGHT);
500
			panneauPremierColonne.addButton(boutonOK);
501
			panneauSecondeColonne.setButtonAlign(Position.LEFT);
276 aurelien 502
			panneauPremierColonne.addButton(boutonAnnuler);
218 david 503
		}
504
		else {
505
 
506
			panneauFormulaire.addButton(boutonOK);
507
			panneauFormulaire.addButton(boutonAnnuler);
508
		}
509
 
510
 
71 jpm 511
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
512
 
513
			public void onSelect(ComboBox comboBox, Record record, int index) {
514
 
515
				// et on met la valeur à jour dans la combobox
516
				comboBox.setValue(record.getAsString("nom_mode"));
517
				setModification(record.getAsString("mode")) ;
518
			}
519
 
520
		});
12 david 521
 
522
		this.add(panneauFormulaire) ;
80 jpm 523
		this.setTopToolbar(bt) ;
12 david 524
 
120 aurelien 525
		this.setAutoScroll(true);
12 david 526
 
201 david 527
 
528
		panneauFormulaire.addListener(new PanelListenerAdapter() {
529
	        public void onResize(BoxComponent component, int adjWidth, int adjHeight, int rawWidth, int rawHeight) {
530
	        	panneauIntermediaire.setWidth(rawWidth);
531
	        	panneauIntermediaire.setHeight(rawHeight);
276 aurelien 532
 
533
	        	panneauPremierColonne.doLayout();
534
	        	panneauSecondeColonne.doLayout();
535
 
536
	        	htmlCommunePanel.doLayout();
537
	        	htmlPanel.doLayout();
201 david 538
	     }});
539
 
12 david 540
		// on ajoute les listeners
201 david 541
 
542
 
12 david 543
		ajouterListeners() ;
544
 
248 aurelien 545
		saisieTabindex();
546
 
12 david 547
	}
548
 
549
	private void ajouterListeners()
94 jpm 550
	{
20 david 551
		// Listener completion communne
268 aurelien 552
		final Rafraichissable r = this;
20 david 553
 
554
		   commune.addListener(new ComboBoxListenerAdapter() {
555
	             public void onSelect(ComboBox comboBox, Record record, int index) {
556
	                 commune.setValue(record.getAsString("commune"));
39 david 557
	                 departement=record.getAsString("departement");
20 david 558
	                 selectionCommune=true;
559
	             }
560
	         });
561
 
562
 
563
			ListenerConfig listenerConfigCommune=new ListenerConfig();
564
			listenerConfigCommune.setDelay(10);
565
			listenerConfigCommune.setStopPropagation(false);
566
			listenerConfigCommune.setStopEvent(false);
567
 
568
		    commune.addKeyPressListener(new EventCallback()	{
569
 
120 aurelien 570
	    	    public void execute(EventObject e) {
571
 
572
 
573
	    	    		switch(e.getKey()) {
574
 
132 aurelien 575
    	    				case KEY_ALT:
576
	    	    	        case KEY_CTRL:
577
	    	    	        case KEY_DOWN:
578
	    	    	        case KEY_END:
579
	    	    	        case KEY_ESCAPE:
580
	    	    	        case KEY_HOME:
581
	    	    	        case KEY_LEFT:
582
	    	    	        case KEY_PAGEDOWN:
583
	    	    	        case KEY_PAGEUP:
584
	    	    	        case KEY_RIGHT:
585
	    	    	        case KEY_SHIFT:
586
	    	    	        case KEY_TAB:
587
	    	    	        case KEY_UP:
588
 
589
	    	    	        break;
590
 
120 aurelien 591
	    	    	    	case KEY_ENTER:
592
 
20 david 593
		    	    	    	 if (selectionCommune) {
216 aurelien 594
		    	    	    		 communeModifiee= true;
20 david 595
		    	    	    		 selectionCommune=false;
596
		    	    	    	 }
120 aurelien 597
		    	    	    	else {
598
 
118 david 599
		    	    	    		validerSaisie(Champs.COMMUNE);
20 david 600
		    	    	    		// lancer mise a jour
601
		    	    	    	 }
120 aurelien 602
		    	    	    break;
603
 
604
		    	    	    default:
20 david 605
 
83 david 606
		    	    	    	  departement="";
20 david 607
		    	    	    	  obtenirListeReferentielCommune();
216 aurelien 608
		    	    	    	  communeModifiee= true;
20 david 609
 
120 aurelien 610
		    	    	    break;
611
	    	    	    }
612
	     			}
613
	    		},    listenerConfigCommune
20 david 614
			);
615
 
120 aurelien 616
		    date.addKeyPressListener(new EventCallback() {
20 david 617
 
120 aurelien 618
				public void execute(EventObject e) {
619
					// TODO Auto-generated method stub
620
					switch(e.getKey()) {
221 aurelien 621
 
622
						case KEY_ALT:
623
		    	        case KEY_CTRL:
624
		    	        case KEY_DOWN:
625
		    	        case KEY_END:
626
		    	        case KEY_ESCAPE:
627
		    	        case KEY_HOME:
628
		    	        case KEY_LEFT:
629
		    	        case KEY_PAGEDOWN:
630
		    	        case KEY_PAGEUP:
631
		    	        case KEY_RIGHT:
632
		    	        case KEY_SHIFT:
633
		    	        case KEY_TAB:
634
		    	        	if(date.getRawValue().equals(VALEURS_MULTIPLES)) {
635
		    	        		date.clearInvalid();
636
		    	        	}
637
		    	        case KEY_UP:
638
 
639
		    	        break;
120 aurelien 640
 
221 aurelien 641
	  	    	      case KEY_ENTER:
642
	  	    	    		validerSaisie(Champs.DATE);
120 aurelien 643
	  	    	    	  break;
644
 
645
	  	    	      default:
221 aurelien 646
	  					dateModifiee = true;
120 aurelien 647
					}
648
				}
649
		    });
650
 
221 aurelien 651
		    date.addListener(new DatePickerListenerAdapter() {
652
 
653
				public void onSelect(DatePicker dataPicker, Date date) {
654
					dateModifiee = true;
655
				}
656
		    });
657
 
120 aurelien 658
		    station.addKeyPressListener(new EventCallback() {
659
 
660
				public void execute(EventObject e) {
661
					// TODO Auto-generated method stub
662
					switch(e.getKey()) {
663
 
221 aurelien 664
						case KEY_ALT:
665
		    	        case KEY_CTRL:
666
		    	        case KEY_DOWN:
667
		    	        case KEY_END:
668
		    	        case KEY_ESCAPE:
669
		    	        case KEY_HOME:
670
		    	        case KEY_LEFT:
671
		    	        case KEY_PAGEDOWN:
672
		    	        case KEY_PAGEUP:
673
		    	        case KEY_RIGHT:
674
		    	        case KEY_SHIFT:
675
		    	        case KEY_TAB:
676
		    	        case KEY_UP:
677
		    	      break;
678
 
120 aurelien 679
	  	    	      case KEY_ENTER:
680
	  	    	    		validerSaisie(Champs.STATION);
681
	  	    	    	  break;
682
 
683
	  	    	      default:
221 aurelien 684
	  	    	    	  stationModifiee = true;
120 aurelien 685
					}
686
				}
687
		    });
688
 
689
 
20 david 690
 
120 aurelien 691
			// Listener completion espece
20 david 692
			espece.addListener(new ComboBoxListenerAdapter() {
693
	             public void onSelect(ComboBox comboBox, Record record, int index) {
694
	            	 espece.setValue(record.getAsString("nom"));
39 david 695
	            	 numeroNom=record.getAsString("numeroNom");
20 david 696
	                 selectionEspece=true;
128 aurelien 697
	                 observationMediateur.obtenirImageInformationExternes(numeroNom);
20 david 698
	             }
699
	         });
700
 
701
 
702
			ListenerConfig listenerConfigEspece=new ListenerConfig();
703
			listenerConfigEspece.setDelay(10);
704
			listenerConfigEspece.setStopPropagation(false);
705
			listenerConfigEspece.setStopEvent(false);
706
 
707
 
708
			espece.addKeyPressListener(new EventCallback()	{
709
 
710
		    	    public void execute(EventObject e) {
711
 
712
 
713
		    	    		  switch(e.getKey()) {
714
 
715
 
716
		    	    		  case KEY_ALT:
717
		    	    	      case KEY_CTRL:
718
		    	    	      case KEY_DOWN:
719
		    	    	      case KEY_END:
720
		    	    	      case KEY_ESCAPE:
721
		    	    	      case KEY_HOME:
722
		    	    	      case KEY_LEFT:
723
		    	    	      case KEY_PAGEDOWN:
724
		    	    	      case KEY_PAGEUP:
725
		    	    	      case KEY_RIGHT:
726
		    	    	      case KEY_SHIFT:
727
		    	    	      case KEY_TAB:
728
		    	    	      case KEY_UP:
729
 
730
		    	    	        break;
731
 
732
		    	    	      case KEY_ENTER:
733
 
140 aurelien 734
			    	    	    	if(selectionEspece) {
216 aurelien 735
			    	    	    		especeModifiee = true;
736
			    	    	    		selectionEspece=false;
140 aurelien 737
			    	    	    	}
738
			    	    	    	else {
739
			    	    	    		validerSaisie(Champs.ESPECE);
740
			    	    	    	}
20 david 741
 
742
		    	    	    	  break;
743
 
744
		    	    	      default:
745
 
83 david 746
		    	    	    	  numeroNom="";
20 david 747
		    	    	    	  obtenirListeReferentielNom();
216 aurelien 748
		    	    	    	  especeModifiee = true;
20 david 749
 
750
		    	    	        break;
751
		    	    	    }
752
 
753
 
754
 
755
		     		}
756
 
757
		    		},    listenerConfigEspece
758
 
759
			);
760
 
120 aurelien 761
			lieudit.addKeyPressListener(new EventCallback() {
20 david 762
 
120 aurelien 763
				public void execute(EventObject e) {
764
					// TODO Auto-generated method stub
765
					switch(e.getKey()) {
766
 
221 aurelien 767
					case KEY_ALT:
768
	  	    	      case KEY_CTRL:
769
	  	    	      case KEY_DOWN:
770
	  	    	      case KEY_END:
771
	  	    	      case KEY_ESCAPE:
772
	  	    	      case KEY_HOME:
773
	  	    	      case KEY_LEFT:
774
	  	    	      case KEY_PAGEDOWN:
775
	  	    	      case KEY_PAGEUP:
776
	  	    	      case KEY_RIGHT:
777
	  	    	      case KEY_SHIFT:
778
	  	    	      case KEY_TAB:
779
	  	    	      case KEY_UP:
780
 
781
  	    	        break;
782
 
120 aurelien 783
	  	    	      case KEY_ENTER:
784
	  	    	    		validerSaisie(Champs.LIEUDIT);
785
	  	    	    	  break;
786
 
787
	  	    	      default:
221 aurelien 788
	  					lieuDitModifie = true;
120 aurelien 789
					}
790
				}
791
		    });
792
 
793
			milieu.addKeyPressListener(new EventCallback() {
794
 
795
				public void execute(EventObject e) {
796
					// TODO Auto-generated method stub
797
					switch(e.getKey()) {
221 aurelien 798
 
799
						case KEY_ALT:
800
	  	    	      case KEY_CTRL:
801
	  	    	      case KEY_DOWN:
802
	  	    	      case KEY_END:
803
	  	    	      case KEY_ESCAPE:
804
	  	    	      case KEY_HOME:
805
	  	    	      case KEY_LEFT:
806
	  	    	      case KEY_PAGEDOWN:
807
	  	    	      case KEY_PAGEUP:
808
	  	    	      case KEY_RIGHT:
809
	  	    	      case KEY_SHIFT:
810
	  	    	      case KEY_TAB:
811
	  	    	      case KEY_UP:
812
 
813
	  	    	        break;
120 aurelien 814
 
815
	  	    	      case KEY_ENTER:
816
	  	    	    		validerSaisie(Champs.MILIEU);
817
	  	    	    	  break;
818
 
819
	  	    	      default:
221 aurelien 820
	  					milieuModifie = true;
120 aurelien 821
					}
822
				}
823
		    });
824
 
216 aurelien 825
			comment.addKeyPressListener(new EventCallback() {
120 aurelien 826
 
827
				public void execute(EventObject e) {
221 aurelien 828
					switch(e.getKey()) {
829
						case KEY_ALT:
830
			    	      case KEY_CTRL:
831
			    	      case KEY_DOWN:
832
			    	      case KEY_END:
833
			    	      case KEY_ESCAPE:
834
			    	      case KEY_HOME:
835
			    	      case KEY_LEFT:
836
			    	      case KEY_PAGEDOWN:
837
			    	      case KEY_PAGEUP:
838
			    	      case KEY_RIGHT:
839
			    	      case KEY_SHIFT:
840
			    	      case KEY_TAB:
841
			    	      case KEY_UP:
842
 
843
		    	        break;
844
 
845
		    	        default:
846
						commModifie = true;
847
					}
120 aurelien 848
				}
216 aurelien 849
		    });
264 aurelien 850
 
268 aurelien 851
			tCoord = new Timer() {
852
 
853
				public void run() {
854
    	        	double[] coord = coordonneesValides();
855
    	        	if(!rechercheCommuneEnCours && coord != null && (longModifiee || latModifiee)) {
856
    	        		rechercheCommuneEnCours = true;
857
    	        		Ext.get(lienSelectionCommune.getElement()).mask("recherche");
858
    	        		observationMediateur.obtenirInformationCoord(r,LatLng.newInstance(coord[0], coord[1]));
859
    	        	}
860
				}
861
 
862
			};
863
 
264 aurelien 864
			latitude.addKeyPressListener(new EventCallback() {
120 aurelien 865
 
264 aurelien 866
				public void execute(EventObject e) {
867
					switch(e.getKey()) {
868
						case KEY_ALT:
869
			    	      case KEY_CTRL:
870
			    	      case KEY_DOWN:
871
			    	      case KEY_END:
872
			    	      case KEY_ESCAPE:
873
			    	      case KEY_HOME:
874
			    	      case KEY_LEFT:
875
			    	      case KEY_PAGEDOWN:
876
			    	      case KEY_PAGEUP:
877
			    	      case KEY_RIGHT:
878
			    	      case KEY_SHIFT:
879
			    	      case KEY_TAB:
880
			    	      case KEY_UP:
881
 
882
		    	        break;
883
 
884
			    	      case KEY_ENTER:
885
	  	    	    		validerSaisie(Champs.LATITUDE);
886
	  	    	    	  break;
887
 
888
		    	        default:
889
						latModifiee = true;
268 aurelien 890
	    	        	tCoord.cancel();
891
	    	        	tCoord.schedule(250);
264 aurelien 892
					}
893
				}
894
		    });
895
 
896
			longitude.addKeyPressListener(new EventCallback() {
897
 
898
				public void execute(EventObject e) {
899
					switch(e.getKey()) {
268 aurelien 900
 
264 aurelien 901
						case KEY_ALT:
902
			    	      case KEY_CTRL:
903
			    	      case KEY_DOWN:
904
			    	      case KEY_END:
905
			    	      case KEY_ESCAPE:
906
			    	      case KEY_HOME:
907
			    	      case KEY_LEFT:
908
			    	      case KEY_PAGEDOWN:
909
			    	      case KEY_PAGEUP:
910
			    	      case KEY_RIGHT:
911
			    	      case KEY_SHIFT:
268 aurelien 912
			    	      case KEY_UP:
264 aurelien 913
			    	      case KEY_TAB:
268 aurelien 914
			    	      break;
915
 
264 aurelien 916
			    	      case KEY_ENTER:
917
		  	    	    		validerSaisie(Champs.LONGITUDE);
268 aurelien 918
		  	    	    	break;
264 aurelien 919
 
920
		    	        default:
268 aurelien 921
							longModifiee = true;
922
		    	        	tCoord.cancel();
923
		    	        	tCoord.schedule(250);
264 aurelien 924
					}
925
				}
926
		    });
927
 
20 david 928
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 929
 
20 david 930
			public void onClick(Button button, EventObject e) {
118 david 931
 
932
				if(modification) {
216 aurelien 933
					if(masseModification) {
934
							modifierObservationEnMasse(null);
935
					} else {
936
						modifierObservation() ;
937
					}
71 jpm 938
				}
118 david 939
				else {
71 jpm 940
					ajouterObservation();
941
				}
39 david 942
 
71 jpm 943
 
20 david 944
			}
945
 
946
		});
77 jpm 947
 
948
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
12 david 949
 
950
			public void onClick(Button button, EventObject e) {
951
 
77 jpm 952
				if(modification)
953
				{
954
					supprimerObservation() ;
955
				}
956
				else
957
				{
104 jpm 958
					raz();
77 jpm 959
				}
960
			}
961
 
12 david 962
		});
132 aurelien 963
 
964
		this.addListener(new ContainerListenerAdapter() {
965
			public void onAfterLayout(Container self) {
966
				commune.focus();
967
			}
968
		});
276 aurelien 969
 
12 david 970
	}
971
 
972
	/**
118 david 973
	 * Validation de la saisie
974
	 */
975
 
976
	private void validerSaisie(Champs champs) {
977
 
978
		if(modification) {
216 aurelien 979
			if(masseModification) {
980
					modifierObservationEnMasse(champs);
981
			} else {
982
				modifierObservation();
983
			}
984
 
985
			raz(champs);
118 david 986
		}
987
		else {
988
			ajouterObservation();
989
			raz(champs);
990
		}
991
	}
992
 
993
	/**
12 david 994
	 * Desactive visuellement ce panneau
995
	 */
996
	public void desactiverPanneau()
997
	{
998
		this.setDisabled(true) ;
999
	}
1000
 
1001
	/**
1002
	 * Active visuellement ce panneau
1003
	 */
1004
	public void activerPanneau()
1005
	{
1006
		this.setDisabled(false) ;
1007
	}
13 david 1008
 
1009
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
1010
 
49 david 1011
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 1012
			if(nouvelleDonnees instanceof ListeReferentielCommune)
1013
			{
1014
 
1015
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
1016
					Object[][] communeData = new Object[data.size()][2];
1017
					int i = 0 ;
1018
 
1019
					// on la parse et on récupère les informations quiç nous interessent
1020
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
1021
					{
1022
 
1023
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
1024
 
1025
						communeData[i][0]= ref.getCommune();
1026
						communeData[i][1]= ref.getDepartement();
1027
 
1028
						i++ ;
1029
					}
1030
 
1031
					   //	  creation du store
1032
					FieldDef defCommune = new StringFieldDef("commune");
1033
					FieldDef defDepartement = new StringFieldDef("departement");
1034
 
1035
 
1036
					FieldDef[] defTab = { defCommune, defDepartement};
1037
 
1038
					RecordDef rd = new RecordDef(defTab);
1039
 
1040
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
1041
					final ArrayReader reader = new ArrayReader(rd);
1042
 
20 david 1043
					Store store=new Store(dataProxy,reader);
13 david 1044
					store.load() ;
1045
 
132 aurelien 1046
					commune.setStore(store);
248 aurelien 1047
					commune.expand();
13 david 1048
			}
20 david 1049
 
94 jpm 1050
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
20 david 1051
 
1052
			if(nouvelleDonnees instanceof ListeReferentielNom)
1053
			{
1054
 
1055
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
1056
					Object[][] nomData = new Object[data.size()][2];
1057
					int i = 0 ;
1058
 
1059
					// on la parse et on récupère les informations quiç nous interessent
1060
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
1061
					{
1062
 
1063
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
1064
 
1065
						nomData[i][0]= ref.getNom();
1066
						nomData[i][1]= ref.getNumeroNom();
1067
 
1068
 
1069
						i++ ;
1070
					}
1071
 
1072
					   //	  creation du store
1073
					FieldDef defNom = new StringFieldDef("nom");
1074
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
1075
 
1076
 
1077
					FieldDef[] defTab = { defNom, defNumeroNom};
1078
 
1079
					RecordDef rd = new RecordDef(defTab);
1080
 
1081
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
1082
					final ArrayReader reader = new ArrayReader(rd);
1083
 
1084
					Store store=new Store(dataProxy,reader);
1085
					store.load() ;
1086
 
1087
					espece.setStore(store);
1088
 
1089
			}
1090
 
82 david 1091
			// On recoit une observation dont on veut afficher le detail
1092
 
71 jpm 1093
			if(nouvelleDonnees instanceof Observation)
1094
			{
1095
				Observation obs = (Observation)nouvelleDonnees ;
1096
				afficherDetailsObservation(obs) ;
1097
			}
77 jpm 1098
 
216 aurelien 1099
			if(nouvelleDonnees instanceof ListeObservation) {
1100
				ListeObservation listeObs = (ListeObservation)nouvelleDonnees;
1101
				calculerAfficherDifferences(listeObs);
1102
			}
1103
 
82 david 1104
			// Sur Mise à jour ou suppression d'une suppression ?
1105
 
77 jpm 1106
			if(nouvelleDonnees instanceof String)
1107
			{
1108
				String str = (String)nouvelleDonnees ;
107 aurelien 1109
				observationMediateur.obtenirNombreObservation() ;
77 jpm 1110
			}
140 aurelien 1111
 
1112
			if(nouvelleDonnees instanceof String[]) {
1113
				String[] anumNom = (String[])nouvelleDonnees ;
1114
				numeroNom = anumNom[1];
1115
				espece.setValue(anumNom[0]);
1116
				setModification("false");
1117
			}
248 aurelien 1118
 
1119
			if(nouvelleDonnees instanceof EntiteGeographiqueObservation)
1120
			{
1121
				EntiteGeographiqueObservation infosComm = (EntiteGeographiqueObservation)nouvelleDonnees ;
268 aurelien 1122
				if(rechercheCommuneEnCours) {
1123
					afficherIndicationCommune(infosComm);
1124
				} else {
1125
					rafraichirCommuneEtCoord(infosComm);
1126
				}
248 aurelien 1127
			}
20 david 1128
 
13 david 1129
	}
248 aurelien 1130
 
1131
 
268 aurelien 1132
	private void afficherIndicationCommune(
1133
			final EntiteGeographiqueObservation infosCom) {
248 aurelien 1134
 
1135
		String nCommune = "";
268 aurelien 1136
		if(infosCom != null && !infosCom.getCommune().trim().equals("")){
1137
			nCommune += infosCom.getCommune();
1138
			if(!infosCom.getIdLocalite().trim().equals(""))
1139
			nCommune += " ("+infosCom.getIdLocalite()+")";
1140
		}
1141
		lienSelectionCommune.setHtml("<a id=\"lien_selection_commune\" tabindex=\"9\">"+nCommune+"</a>");
1142
		lienSelectionCommune.setStyleName("img-curseur-depl");
276 aurelien 1143
 
268 aurelien 1144
		Ext.get("lien_selection_commune").addListener("click",new EventCallback() {
1145
			public void execute(EventObject e) {
1146
				rafraichirCommune(infosCom);
1147
			}
1148
		});
1149
 
1150
		Ext.get("lien_selection_commune").addListener("keypress",new EventCallback() {
1151
			public void execute(EventObject e) {
1152
				if(e.getCharCode() == KEY_ENTER) {
1153
					rafraichirCommune(infosCom);
1154
				}
1155
			}
1156
		});
1157
 
1158
		Ext.get("lien_selection_commune").addListener("focus",new EventCallback() {
1159
			public void execute(EventObject e) {
1160
				Ext.get("lien_selection_commune").toggleClass("lien_sel");
1161
			}
1162
		});
1163
 
1164
		Ext.get("lien_selection_commune").addListener("blur",new EventCallback() {
1165
			public void execute(EventObject e) {
1166
				Ext.get("lien_selection_commune").toggleClass("lien_sel");
1167
			}
1168
		});
248 aurelien 1169
 
268 aurelien 1170
		Ext.get(lienSelectionCommune.getElement()).unmask();
1171
		rechercheCommuneEnCours = false;
1172
	}
1173
 
1174
	private void rafraichirCommune(EntiteGeographiqueObservation infosCom) {
1175
		String nCommune = "";
1176
 
248 aurelien 1177
 
264 aurelien 1178
		if(infosCom.getCommune() != null && !infosCom.getCommune().equals("")) {
1179
			nCommune += infosCom.getCommune();
248 aurelien 1180
		}
1181
 
264 aurelien 1182
		if(infosCom.getIdLocalite() != null && !infosCom.getIdLocalite().equals("")) {
1183
			nCommune += " ("+infosCom.getIdLocalite()+")";
1184
			departement = infosCom.getIdLocalite();
248 aurelien 1185
		}
1186
		commune.setValue(nCommune);
268 aurelien 1187
	}
248 aurelien 1188
 
268 aurelien 1189
	private void rafraichirCommuneEtCoord(EntiteGeographiqueObservation infosCom) {
1190
 
1191
		rafraichirCommune(infosCom);
1192
 
248 aurelien 1193
		if(infosCom.getLat() != null && !infosCom.getLat().equals("")) {
1194
			latitude.setValue(infosCom.getLat());
1195
		}
1196
 
1197
		if(infosCom.getLon() != null && !infosCom.getLon().equals("")) {
1198
			longitude.setValue(infosCom.getLon());
1199
		}
264 aurelien 1200
 
1201
		coordPanel.setVisible(true);
1202
 
268 aurelien 1203
		latModifiee = false;
1204
		longModifiee = false;
248 aurelien 1205
	}
1206
 
13 david 1207
	public void obtenirListeReferentielCommune() {
94 jpm 1208
 
268 aurelien 1209
	 String com=commune.getText();
20 david 1210
	 com=com.replaceAll("%","");
1211
 
1212
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 1213
 
1214
	}
20 david 1215
 
1216
 
1217
	public void obtenirListeReferentielNom() {
1218
 
248 aurelien 1219
	  String esp=espece.getText().replaceAll(" ","/*");
20 david 1220
	  esp=esp.replaceAll("%","");
1221
 
1222
	  observationMediateur.obtenirListeReferentielNom(this,esp);
1223
 
1224
	}
1225
 
1226
 
39 david 1227
	public void ajouterObservation() {
140 aurelien 1228
 
1229
		if(departement.equals("000null") || departement.equals("")) {
1230
			String[] depCom = commune.getText().split(" ");
1231
			if(depCom.length > 1) {
1232
				String dep = depCom[1].replace('(', ' ');
1233
				dep =dep.replace(')', ' ');
1234
				dep = dep.trim();
1235
				dep = dep.replace('\\',' ');
1236
				dep = dep.trim();
1237
 
1238
				try
1239
				{
1240
					int nDep = Integer.parseInt(dep);
1241
					if(nDep > 0 && nDep < 110) {
1242
						departement = dep ;
1243
					}
1244
				}
1245
				catch(NumberFormatException e)
1246
				{
1247
					departement = "" ;
1248
				}
1249
			}
1250
		}
39 david 1251
 
120 aurelien 1252
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
264 aurelien 1253
 
1254
		String[] coords = getValeurCoordonnees();
1255
 
1256
		obs.setCoordonneeX(coords[0]);
1257
		obs.setCoordonneeY(coords[1]);
1258
 
46 david 1259
		observationMediateur.ajouterObservation(obs);
39 david 1260
	}
12 david 1261
 
71 jpm 1262
	private void modifierObservation() {
229 aurelien 1263
 
1264
		if(departement.equals("000null") || departement.equals("")) {
1265
			String[] depCom = commune.getText().split(" ");
1266
			if(depCom.length > 1) {
1267
				String dep = depCom[1].replace('(', ' ');
1268
				dep =dep.replace(')', ' ');
1269
				dep = dep.trim();
1270
				dep = dep.replace('\\',' ');
1271
				dep = dep.trim();
1272
 
1273
				try
1274
				{
1275
					int nDep = Integer.parseInt(dep);
1276
					if(nDep > 0 && nDep < 110) {
1277
						departement = dep ;
1278
					}
1279
				}
1280
				catch(NumberFormatException e)
1281
				{
1282
					departement = "" ;
1283
				}
1284
			}
1285
		}
1286
 
120 aurelien 1287
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
79 david 1288
		obs.setNumeroOrdre(numeroOrdre);
216 aurelien 1289
 
264 aurelien 1290
		String[] coords = getValeurCoordonnees();
1291
 
1292
		obs.setCoordonneeX(coords[0]);
1293
		obs.setCoordonneeY(coords[1]);
1294
 
79 david 1295
		observationMediateur.modifierObservation(obs);
216 aurelien 1296
 
205 aurelien 1297
		selecteurMode.setValue("création");
1298
		setModification("false");
1299
 
71 jpm 1300
	}
77 jpm 1301
 
216 aurelien 1302
	private void modifierObservationEnMasse(Champs champModifie) {
1303
		String communeM = null;
1304
		String departementM = null;
221 aurelien 1305
		String numNomSelM = null;
216 aurelien 1306
		String lieuDitM = null;
1307
		String stationM = null;
1308
		String milieuM = null;
1309
		String dateM = null;
1310
		String especeM = null;
1311
		String commM = null;
264 aurelien 1312
		String latM = null;
1313
		String longM = null;
216 aurelien 1314
 
1315
		String champs = modeleMessageModif;
1316
 
1317
		if(communeModifiee) {
1318
			communeM = commune.getText();
221 aurelien 1319
 
1320
			if(departement.equals("000null") || departement.equals("")) {
1321
				String[] depCom = commune.getText().split(" ");
1322
				if(depCom.length > 1) {
1323
					String dep = depCom[1].replace('(', ' ');
1324
					dep =dep.replace(')', ' ');
1325
					dep = dep.trim();
1326
					dep = dep.replace('\\',' ');
1327
					dep = dep.trim();
1328
 
1329
					try
1330
					{
1331
						int nDep = Integer.parseInt(dep);
1332
						if(nDep > 0 && nDep < 110) {
1333
							departement = dep ;
1334
						}
1335
					}
1336
					catch(NumberFormatException e)
1337
					{
1338
						departement = "" ;
1339
					}
1340
				}
1341
			}
1342
 
1343
			departementM = departement;
216 aurelien 1344
		} else {
221 aurelien 1345
			champs = champs.replaceAll("commune", "");
216 aurelien 1346
		}
1347
 
221 aurelien 1348
		if(lieuDitModifie) {
216 aurelien 1349
			lieuDitM = lieudit.getText();
1350
		}else {
221 aurelien 1351
			champs = champs.replaceAll(":lieu-dit", "");
216 aurelien 1352
		}
1353
 
221 aurelien 1354
		if(stationModifiee) {
216 aurelien 1355
			stationM = station.getText();
1356
		}else {
221 aurelien 1357
			champs = champs.replaceAll(":station", "");
216 aurelien 1358
		}
1359
 
1360
		if(milieuModifie) {
1361
			milieuM = milieu.getText();
1362
		}else {
221 aurelien 1363
			champs = champs.replaceAll(":milieu", "");
216 aurelien 1364
		}
1365
 
221 aurelien 1366
		if(dateModifiee && !date.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1367
			dateM = date.getRawValue();
1368
		}else {
221 aurelien 1369
			champs = champs.replaceAll(":date", "");
216 aurelien 1370
		}
1371
 
1372
		if(especeModifiee) {
1373
			especeM = espece.getText();
221 aurelien 1374
			numNomSelM = numeroNom;
216 aurelien 1375
		}else {
221 aurelien 1376
			champs = champs.replaceAll(":espece", "");
216 aurelien 1377
		}
1378
 
1379
		if(commModifie) {
1380
			commM = comment.getText();
1381
		}else {
221 aurelien 1382
			champs = champs.replaceAll(":commentaire", "");
216 aurelien 1383
		}
1384
 
264 aurelien 1385
		if(latModifiee) {
1386
			latM = latitude.getText();
1387
		}else {
1388
			champs = champs.replaceAll(":latitude", "");
1389
		}
1390
 
1391
		if(longModifiee) {
1392
			longM = longitude.getText();
1393
		}else {
1394
			champs = champs.replaceAll(":longitude", "");
1395
		}
1396
 
221 aurelien 1397
		champs = champs.replaceAll(":",", ");
1398
		if(champs.startsWith(",")) {
1399
			champs = champs.replaceFirst(",", "");
1400
		}
216 aurelien 1401
 
221 aurelien 1402
		String message = "Voulez vous modifier le(s) champ(s) suivant(s) : "+champs+"   pour les observations selectionnées ?" ;
1403
 
216 aurelien 1404
		if(champs.trim().equals("")) {
1405
			Window.alert("Aucun champ n'a été modifié");
1406
		} else {
221 aurelien 1407
			Observation obs = new Observation(especeM,numNomSelM,communeM,departementM,lieuDitM,stationM,milieuM, commM,dateM);
216 aurelien 1408
			obs.setNumeroOrdre(numeroOrdre);
264 aurelien 1409
			obs.setCoordonneeX(latM);
1410
			obs.setCoordonneeY(longM);
216 aurelien 1411
			if(Window.confirm(message)) {
1412
				observationMediateur.modifierObservationEnMasse(obs);
221 aurelien 1413
				reinitialiserValeurModifiees();
216 aurelien 1414
			}
1415
		}
1416
	}
1417
 
77 jpm 1418
	private void supprimerObservation() {
1419
 
216 aurelien 1420
		observationMediateur.supprimerObservation(this, numeroOrdre);
77 jpm 1421
	}
12 david 1422
 
71 jpm 1423
 
1424
	public void afficherDetailsObservation(Observation obs)
1425
	{
104 jpm 1426
		raz() ;
216 aurelien 1427
		String idLoc ;
1428
		if(obs.getIdentifiantLocalite() != VALEURS_MULTIPLES) {
1429
			idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
1430
			idLoc = idLoc.replaceAll("%","");
1431
			idLoc = idLoc.replaceAll("\"","");
1432
			idLoc = idLoc.replace('\\',' ');
1433
			idLoc = idLoc.trim();
1434
		} else {
1435
			idLoc = obs.getIdentifiantLocalite();
1436
		}
71 jpm 1437
 
221 aurelien 1438
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null") && !obs.getDate().equals(VALEURS_MULTIPLES)) {
71 jpm 1439
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 1440
			if(verifierFormatDate(dateEtHeure[0])) {
1441
				date.setValue(dateEtHeure[0]) ;
1442
			}
1443
			else
1444
			{
1445
				date.setRawValue("");
1446
			}
221 aurelien 1447
		} else {
1448
			date.setRawValue(VALEURS_MULTIPLES);
1449
			date.clearInvalid();
71 jpm 1450
		}
1451
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
1452
			lieudit.setValue(obs.getLieudit()) ;
1453
		}
1454
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
1455
			station.setValue(obs.getStation()) ;
1456
		}
1457
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
1458
			milieu.setValue(obs.getMilieu()) ;
1459
		}
1460
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
1461
			comment.setValue(obs.getCommentaire()) ;
1462
		}
1463
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
221 aurelien 1464
			if(!idLoc.equals("000null")) {
1465
				if(!idLoc.equals(VALEURS_MULTIPLES)) {
1466
					commune.setValue(obs.getLocalite()+" ("+idLoc+")") ;
1467
				} else {
1468
					commune.setValue(VALEURS_MULTIPLES);
1469
				}
140 aurelien 1470
			}
1471
			else
1472
			{
1473
				commune.setValue(obs.getLocalite());
1474
			}
71 jpm 1475
		}
1476
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
140 aurelien 1477
			departement = idLoc;
71 jpm 1478
		}
1479
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
1480
			espece.setValue(obs.getNomSaisi()) ;
1481
		}
1482
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
1483
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
1484
		}
83 david 1485
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
74 david 1486
			numeroOrdre = obs.getNumeroOrdre() ;
1487
		}
1488
 
264 aurelien 1489
		if(!obs.getCoordonneeX().equals("null") && !obs.getCoordonneeX().equals("000null")
1490
				&& !obs.getCoordonneeY().equals("null") && !obs.getCoordonneeY().equals("000null")) {
1491
			latitude.setValue(obs.getCoordonneeX()) ;
1492
			longitude.setValue(obs.getCoordonneeY()) ;
1493
		}
71 jpm 1494
	}
1495
 
118 david 1496
 
104 jpm 1497
	public void raz()
71 jpm 1498
	{
118 david 1499
		raz(Champs.TOUT);
1500
 
1501
	}
1502
	public void raz(Champs champs)
1503
	{
1504
		switch (champs) {
1505
 
1506
 
1507
			case DATE:
1508
				date.reset() ;
1509
				break;
1510
 
1511
			case LIEUDIT:
1512
				lieudit.reset() ;
1513
				break;
1514
 
1515
			case STATION:
1516
				station.reset() ;
1517
				break;
1518
 
1519
			case MILIEU:
1520
				milieu.reset() ;
1521
				break;
1522
 
1523
			case COMMENT:
1524
				comment.reset() ;
1525
				break;
1526
 
1527
 
1528
			case COMMUNE:
172 aurelien 1529
				commune.reset() ;
118 david 1530
				departement ="";
268 aurelien 1531
				latitude.reset();
1532
				longitude.reset();
118 david 1533
				break;
1534
 
1535
			case ESPECE:
1536
				espece.reset();
1537
				numeroNom = "" ;
1538
				numeroOrdre = "";
1539
				break;
1540
 
264 aurelien 1541
			case LATITUDE:
1542
				latitude.reset();
268 aurelien 1543
				afficherIndicationCommune(null);
264 aurelien 1544
				break;
1545
 
1546
			case LONGITUDE:
1547
				longitude.reset();
268 aurelien 1548
				afficherIndicationCommune(null);
264 aurelien 1549
				break;
1550
 
118 david 1551
			case TOUT:
132 aurelien 1552
				commune.reset();
118 david 1553
				date.reset() ;
1554
				lieudit.reset() ;
1555
				station.reset() ;
1556
				milieu.reset() ;
1557
				comment.reset() ;
1558
				milieu.reset() ;
248 aurelien 1559
				latitude.reset();
1560
				longitude.reset();
118 david 1561
				departement ="";
1562
				espece.reset();
1563
				numeroNom = "" ;
1564
				numeroOrdre = "";
268 aurelien 1565
				afficherIndicationCommune(null);
118 david 1566
				break;
1567
 
1568
		}
71 jpm 1569
 
1570
	}
1571
 
1572
	private void setModification(String mode)
1573
	{
1574
		if(mode.equals("true")) {
1575
 
1576
			boutonOK.setText("Modifier") ;
1577
			setTitle("Modification") ;
77 jpm 1578
			boutonAnnuler.setText("Supprimer") ;
71 jpm 1579
			modification = true ;
97 jpm 1580
			selecteurMode.removeClass("x-selec-crea") ;
1581
			selecteurMode.setCls("x-selec-modif") ;
216 aurelien 1582
			observationMediateur.onModeModification();
71 jpm 1583
		}
1584
		else
1585
		{
264 aurelien 1586
			boutonOK.setText("Créer") ;
71 jpm 1587
			setTitle("Saisir") ;
77 jpm 1588
			boutonAnnuler.setText("Réinitialiser") ;
71 jpm 1589
			modification = false ;
97 jpm 1590
			selecteurMode.removeClass("x-selec-modif") ;
1591
			selecteurMode.setCls("x-selec-crea") ;
246 aurelien 1592
			observationMediateur.onModeCreation();
132 aurelien 1593
		}
71 jpm 1594
	}
1595
 
1596
	/**
1597
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
1598
	 * @return
1599
	 */
1600
	public boolean getModification()
1601
	{
1602
		return modification ;
1603
	}
110 aurelien 1604
 
216 aurelien 1605
	/**
1606
	 * renvoie vrai si on est en mode modification de masse, faux sinon
1607
	 * @return
1608
	 */
1609
	public boolean getMasseModification()
1610
	{
1611
		return masseModification ;
1612
	}
1613
 
110 aurelien 1614
	public boolean verifierFormatDate(String date) {
1615
 
132 aurelien 1616
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 1617
		if(date.matches(regex) && !date.equals("0000-00-00")) {
1618
			return true ;
1619
		}
1620
		else {
1621
			return false;
1622
		}
1623
	}
216 aurelien 1624
 
1625
	public void setMasseModification(boolean masseModification) {
1626
		this.masseModification = masseModification;
1627
		if(masseModification) {
1628
			reinitialiserValeurModifiees();
1629
		}
1630
	}
132 aurelien 1631
 
216 aurelien 1632
	private void calculerAfficherDifferences(ListeObservation listeObs) {
1633
 
1634
		String departement = null;
1635
		String commune = null;
1636
		String lieuDit = null;
1637
		String station = null;
1638
		String milieu = null;
1639
		String espece = null;
1640
		String date = null;
1641
		String notes = null;
264 aurelien 1642
		String lat = null;
1643
		String lon = null;
216 aurelien 1644
 
1645
		String ordreObs = "";
1646
 
1647
		for(Iterator<String> it = listeObs.keySet().iterator();it.hasNext();) {
1648
			Observation obsEnCours = listeObs.get(it.next());
1649
			departement = comparerDifferencesChamps(departement, obsEnCours.getIdentifiantLocalite());
1650
			commune = comparerDifferencesChamps(commune, obsEnCours.getLocalite());
1651
			lieuDit = comparerDifferencesChamps(lieuDit, obsEnCours.getLieudit());
1652
			station = comparerDifferencesChamps(station, obsEnCours.getStation());
1653
			milieu = comparerDifferencesChamps(milieu, obsEnCours.getMilieu());
1654
			espece = comparerDifferencesChamps(espece, obsEnCours.getNomSaisi());
1655
			date = comparerDifferencesChamps(date, obsEnCours.getDate());
1656
			notes = comparerDifferencesChamps(notes, obsEnCours.getCommentaire());
264 aurelien 1657
			lat = comparerDifferencesChamps(lat, obsEnCours.getCoordonneeX());
1658
			lon = comparerDifferencesChamps(lon, obsEnCours.getCoordonneeY());
216 aurelien 1659
 
1660
			ordreObs += obsEnCours.getNumeroOrdre()+",";
1661
		}
1662
 
1663
		Observation obs=new Observation(espece,numeroNom,commune,departement,lieuDit,station,milieu, notes,date);
1664
		obs.setNumeroOrdre(ordreObs);
264 aurelien 1665
		obs.setCoordonneeX(lat);
1666
		obs.setCoordonneeY(lon);
216 aurelien 1667
		rafraichir(obs, false);
1668
 
1669
	}
1670
 
1671
	private String comparerDifferencesChamps(String valeurActuelle, String nouvelleValeur) {
1672
 
1673
		String retour = "000null";
1674
 
1675
			if(valeurActuelle == null) {
1676
				retour = nouvelleValeur;
1677
			} else {
1678
				if(valeurActuelle.equals(nouvelleValeur)) {
1679
					retour = valeurActuelle;
1680
				} else {
1681
					retour = VALEURS_MULTIPLES;
1682
				}
1683
			}
1684
		return retour;
1685
	}
1686
 
1687
	private void reinitialiserValeurModifiees() {
1688
 
1689
		communeModifiee = false;
221 aurelien 1690
		lieuDitModifie = false;
1691
		stationModifiee = false;
216 aurelien 1692
		milieuModifie = false;
1693
		dateModifiee = false;
1694
		especeModifiee = false;
1695
		commModifie = false;
264 aurelien 1696
		latModifiee = false;
1697
		longModifiee = false;
216 aurelien 1698
	}
1699
 
248 aurelien 1700
	public void saisieTabindex()
1701
	{
1702
 
1703
		selecteurMode.setTabIndex(0);
1704
		commune.setTabIndex(1);
268 aurelien 1705
		lieudit.setTabIndex(3);
1706
		station.setTabIndex(4);
1707
		milieu.setTabIndex(5);
248 aurelien 1708
		coordonnees.setTabIndex(-1);
1709
		coordonnees.addListener(new TextFieldListenerAdapter() {
1710
 
1711
			public void onFocus(Field field) {
1712
				if(coordPanel.isVisible()) {
264 aurelien 1713
					latitude.focus();
248 aurelien 1714
				} else {
1715
					Ext.get("lien_carto").focus();
1716
				}
1717
			}
1718
		});
1719
 
268 aurelien 1720
		latitude.setTabIndex(7);
1721
		longitude.setTabIndex(8);
248 aurelien 1722
		comment.setTabIndex(10);
1723
		date.setTabIndex(11);
1724
		espece.setTabIndex(12);
1725
		boutonOK.setTabIndex(13);
1726
		boutonAnnuler.setTabIndex(14);
1727
 
1728
	}
1729
 
1730
	private void obtenirInformationCoord() {
1731
		if(coordonneesValides() != null) {
1732
			observationMediateur.obtenirInformationCoord(LatLng.newInstance(coordonneesValides()[0],coordonneesValides()[1]));
1733
		} else {
1734
			Window.alert("Les coordonnées saisies sont invalides");
1735
		}
1736
 
1737
	}
1738
 
1739
	private void obtenirInformationCommune() {
1740
		observationMediateur.obtenirInformationCommune(commune.getValue(), obtenirDepartementAPartirChampCommune());
1741
	}
1742
 
1743
	private double[] coordonneesValides() {
1744
 
1745
		try {
1746
 
1747
			double lat = Double.parseDouble(latitude.getValueAsString().replaceAll(",", "."));
1748
			double lon = Double.parseDouble(longitude.getValueAsString().replaceAll(",", "."));
1749
 
1750
			double[] coord = {lat, lon};
1751
			return coord;
1752
 
1753
		} catch (NumberFormatException ne) {
1754
			return null;
1755
		}
1756
	}
1757
 
264 aurelien 1758
	private String[] getValeurCoordonnees() {
1759
		double[] coDouble = coordonneesValides();
1760
 
1761
		if(coDouble != null) {
1762
			String[] coord = {coDouble[0]+"",coDouble[1]+""};
1763
			return coord;
1764
		} else {
1765
			String[] coord = {"000null","000null" };
1766
			return coord;
1767
		}
1768
	}
1769
 
248 aurelien 1770
	private String obtenirDepartementAPartirChampCommune() {
264 aurelien 1771
 
1772
		String dep = "";
1773
 
248 aurelien 1774
		if(departement.equals("000null") || departement.equals("")) {
264 aurelien 1775
 
248 aurelien 1776
			String[] depCom = commune.getText().split(" ");
1777
			if(depCom.length > 1) {
264 aurelien 1778
				dep = depCom[1].replace('(', ' ');
1779
			} else {
1780
				dep = "";
248 aurelien 1781
			}
264 aurelien 1782
		} else {
1783
			dep = departement;
248 aurelien 1784
		}
1785
 
264 aurelien 1786
		dep = dep.replace(')', ' ');
1787
		dep = dep.trim();
1788
		dep = dep.replace('\\',' ');
1789
		dep = dep.trim();
1790
 
1791
		try
1792
		{
1793
			int nDep = Integer.parseInt(dep);
1794
			if(nDep > 0 && nDep < 110) {
1795
				departement = dep ;
1796
			}
1797
 
1798
			if(departement.length() == 1) {
1799
				departement = "0"+departement;
1800
			}
1801
		}
1802
		catch(NumberFormatException e)
1803
		{
1804
			departement = "" ;
1805
		}
1806
 
248 aurelien 1807
		return departement;
1808
	}
1809
 
268 aurelien 1810
	public String getCommune() {
1811
		return commune.getValue();
1812
	}
1813
 
1814
	public String getDepartement() {
1815
		return obtenirDepartementAPartirChampCommune();
1816
	}
1817
 
1818
	public boolean communeInitialisee() {
1819
		return communeModifiee;
1820
	}
12 david 1821
}