Subversion Repositories eFlore/Applications.cel

Rev

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