Subversion Repositories eFlore/Applications.cel

Rev

Rev 2392 | 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;
1549 aurelien 6
import java.util.HashMap;
13 david 7
import java.util.Iterator;
1967 aurelien 8
import java.util.List;
1549 aurelien 9
import java.util.Map;
13 david 10
 
318 aurelien 11
import org.tela_botanica.client.CarnetEnLigneMediateur;
13 david 12
import org.tela_botanica.client.interfaces.Rafraichissable;
2392 aurelien 13
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
1572 aurelien 14
import org.tela_botanica.client.modeles.objets.ChampEtendu;
989 aurelien 15
import org.tela_botanica.client.modeles.objets.Configuration;
16
import org.tela_botanica.client.modeles.objets.EntiteGeographiqueObservation;
17
import org.tela_botanica.client.modeles.objets.ListeObservation;
18
import org.tela_botanica.client.modeles.objets.ListeReferentielCommune;
19
import org.tela_botanica.client.modeles.objets.ListeReferentielNom;
20
import org.tela_botanica.client.modeles.objets.Observation;
1489 aurelien 21
import org.tela_botanica.client.modeles.objets.Ontologies;
989 aurelien 22
import org.tela_botanica.client.modeles.objets.ReferentielCommune;
23
import org.tela_botanica.client.modeles.objets.ReferentielNom;
24
import org.tela_botanica.client.modeles.objets.ListeReferentielPerso.TypesReferentiels;
12 david 25
import org.tela_botanica.client.observation.ObservationMediateur;
728 aurelien 26
import org.tela_botanica.client.util.AutoCompletionRefComboBox;
1940 aurelien 27
import org.tela_botanica.client.util.ChampSaisieEtendu;
28
import org.tela_botanica.client.util.FormulaireSaisieChampEtendu;
708 aurelien 29
import org.tela_botanica.client.util.Util;
132 aurelien 30
 
1597 aurelien 31
import com.google.gwt.event.dom.client.ClickEvent;
32
import com.google.gwt.event.dom.client.ClickHandler;
268 aurelien 33
import com.google.gwt.user.client.Timer;
216 aurelien 34
import com.google.gwt.user.client.Window;
248 aurelien 35
import com.google.gwt.user.client.ui.HTML;
1940 aurelien 36
import com.google.gwt.user.client.ui.PopupPanel;
13 david 37
import com.gwtext.client.core.EventCallback;
38
import com.gwtext.client.core.EventObject;
218 david 39
import com.gwtext.client.core.Ext;
248 aurelien 40
import com.gwtext.client.core.ExtElement;
13 david 41
import com.gwtext.client.core.ListenerConfig;
12 david 42
import com.gwtext.client.core.Position;
13 david 43
import com.gwtext.client.data.ArrayReader;
44
import com.gwtext.client.data.FieldDef;
45
import com.gwtext.client.data.MemoryProxy;
46
import com.gwtext.client.data.RecordDef;
47
import com.gwtext.client.data.Store;
48
import com.gwtext.client.data.StringFieldDef;
132 aurelien 49
import com.gwtext.client.widgets.BoxComponent;
12 david 50
import com.gwtext.client.widgets.Button;
132 aurelien 51
import com.gwtext.client.widgets.Container;
221 aurelien 52
import com.gwtext.client.widgets.DatePicker;
12 david 53
import com.gwtext.client.widgets.Panel;
248 aurelien 54
import com.gwtext.client.widgets.ToolTip;
71 jpm 55
import com.gwtext.client.widgets.Toolbar;
20 david 56
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
132 aurelien 57
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
221 aurelien 58
import com.gwtext.client.widgets.event.DatePickerListenerAdapter;
201 david 59
import com.gwtext.client.widgets.event.PanelListenerAdapter;
13 david 60
import com.gwtext.client.widgets.form.ComboBox;
12 david 61
import com.gwtext.client.widgets.form.DateField;
216 aurelien 62
import com.gwtext.client.widgets.form.Field;
12 david 63
import com.gwtext.client.widgets.form.FormPanel;
268 aurelien 64
import com.gwtext.client.widgets.form.Label;
248 aurelien 65
import com.gwtext.client.widgets.form.MultiFieldPanel;
128 aurelien 66
import com.gwtext.client.widgets.form.TextArea;
12 david 67
import com.gwtext.client.widgets.form.TextField;
13 david 68
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
248 aurelien 69
import com.gwtext.client.widgets.form.event.TextFieldListenerAdapter;
201 david 70
import com.gwtext.client.widgets.layout.AnchorLayoutData;
12 david 71
import com.gwtext.client.widgets.layout.ColumnLayout;
72
import com.gwtext.client.widgets.layout.ColumnLayoutData;
73
import com.gwtext.client.widgets.layout.FormLayout;
230 david 74
import com.gwtext.client.widgets.layout.RowLayout;
13 david 75
import com.gwtext.client.data.Record;
12 david 76
 
77
/**
78
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
79
 * @author aurelien
80
 *
81
 */
13 david 82
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 83
 
84
 
85
	/**
86
	 * Le médiateur associé à la vue
87
	 */
88
	private ObservationMediateur	observationMediateur		= null;
1858 raphael 89
 
205 aurelien 90
	FormPanel panneauFormulaire = null;
20 david 91
 
13 david 92
	private DateField date = null;
708 aurelien 93
	private ComboBox lieudit = null;
94
	private ComboBox station = null;
95
	private ComboBox milieu = null;
12 david 96
	private TextField comment = null;
13 david 97
	private ComboBox  commune = null;
39 david 98
	private String departement = null;
20 david 99
	private ComboBox  espece = null;
39 david 100
	private String numeroNom = null;
74 david 101
	private String numeroOrdre = null;
962 aurelien 102
	private String codeInseeCommune = null;
1542 aurelien 103
	private String referentielTaxo = null;
264 aurelien 104
	private String referentielGeo = null;
20 david 105
 
118 david 106
	// Pour remise a zero partielle lors d'une validation
1858 raphael 107
 
118 david 108
	private  enum Champs {
1572 aurelien 109
	    DATE, LIEUDIT, STATION, MILIEU, COMMENT, COMMUNE, ESPECE, TOUT, LATITUDE, LONGITUDE, ALTITUDE, ABONDANCE, CERTITUDE, REFERENTIELTAXO, PHENOLOGIE;
1858 raphael 110
 
1292 aurelien 111
	    @Override
112
		public String toString() {
1858 raphael 113
 
216 aurelien 114
	    	switch(this) {
115
	    	case DATE:
116
	    		return "date";
1858 raphael 117
 
216 aurelien 118
	    	case COMMUNE:
119
	    		return "commune";
1858 raphael 120
 
216 aurelien 121
    		case LIEUDIT:
122
    			return "lieu dit";
1858 raphael 123
 
216 aurelien 124
    		case STATION:
125
    			return "station";
1858 raphael 126
 
216 aurelien 127
    		case MILIEU:
128
    			return "milieu";
1858 raphael 129
 
216 aurelien 130
    		case COMMENT:
131
    			return "commentaire";
1858 raphael 132
 
216 aurelien 133
	    	case ESPECE:
134
	    		return "espèce";
1858 raphael 135
 
264 aurelien 136
	    	case LATITUDE:
137
	    		return "latitude";
1858 raphael 138
 
264 aurelien 139
	    	case LONGITUDE:
140
	    		return "longitude";
1858 raphael 141
 
1572 aurelien 142
	    	case ALTITUDE:
143
	    		return "altitude";
1858 raphael 144
 
1488 aurelien 145
	    	case ABONDANCE:
146
	    		return "abondance";
1858 raphael 147
 
1488 aurelien 148
	    	case CERTITUDE:
1489 aurelien 149
	    		return "identification";
1858 raphael 150
 
1542 aurelien 151
	    	case REFERENTIELTAXO:
152
	    		return "referentiel";
1858 raphael 153
 
1542 aurelien 154
	    	case PHENOLOGIE:
155
	    		return "phenologie";
1858 raphael 156
 
216 aurelien 157
	    	case TOUT:
1572 aurelien 158
	    		return "date, commune, lieu dit, station, milieu, espèce, commentaire, latitude, longitude, altitude, abondance, identification, referentiel, phenologie";
216 aurelien 159
	    	}
160
			return TOUT.toString();
161
	    }
118 david 162
	};
1858 raphael 163
 
110 aurelien 164
	private String formatDate = null ;
1820 aurelien 165
	private Button boutonOK = new Button("Créer");
1641 aurelien 166
	private Button boutonModifier = new Button("Modifier");
167
	private Button boutonSupprimer = new Button("Supprimer");
77 jpm 168
	private Button boutonAnnuler = new Button("Réinitialiser");
20 david 169
 
13 david 170
	private boolean selectionCommune=false;
20 david 171
	private boolean selectionEspece=false;
1488 aurelien 172
	private boolean selectionAbondance = false;
173
	private boolean selectionCertitude = false;
1542 aurelien 174
	private boolean selectionPhenologie = false;
1858 raphael 175
 
71 jpm 176
	private Toolbar bt = null ;
1858 raphael 177
 
216 aurelien 178
	private final String VALEURS_MULTIPLES = "(Valeurs multiples)";
1572 aurelien 179
	private final String modeleMessageModif = "commune:lieu-dit:station:milieu:latitude:longitude:altitude:date:espece:commentaire:abondance:identification:referentiel:phenologie";
216 aurelien 180
	private boolean communeModifiee = false;
221 aurelien 181
	private boolean lieuDitModifie = false;
182
	private boolean stationModifiee = false;
216 aurelien 183
	private boolean milieuModifie = false;
184
	private boolean dateModifiee = false;
185
	private boolean especeModifiee = false;
186
	private boolean commModifie = false;
1488 aurelien 187
	private boolean abondanceModifiee = false;
188
	private boolean certitudeModifiee = false;
1542 aurelien 189
	private boolean referentielTaxoModifie = false;
190
	private boolean phenologieModifiee = false;;
1858 raphael 191
 
20 david 192
	private final int KEY_ALT = 18;
193
	private final int KEY_BACKSPACE = 8;
194
	private final int KEY_CTRL = 17;
195
	private final int KEY_DELETE = 46;
196
	private final int KEY_DOWN = 40;
197
	private final int KEY_END = 35;
198
	private final int KEY_ENTER = 13;
199
	private final int KEY_ESCAPE = 27;
200
	private final int KEY_HOME = 36;
201
	private final int KEY_LEFT = 37;
202
	private final int KEY_PAGEDOWN = 34;
203
	private final int KEY_PAGEUP = 33;
204
	private final int KEY_RIGHT = 39;
205
	private final int KEY_SHIFT = 16;
206
	private final int KEY_TAB = 9;
207
	private final int KEY_UP = 38;
1858 raphael 208
 
71 jpm 209
	/**
12 david 210
	 * Booleen d'instanciation
211
	 */
212
	boolean estInstancie = false ;
205 aurelien 213
 
214
	private Panel panneauIntermediaire;
215
 
216
	private Panel panneauPremierColonne;
217
 
218
	private Panel panneauSecondeColonne;
216 aurelien 219
 
248 aurelien 220
	private TextField longitude;
221
 
222
	private TextField latitude;
1858 raphael 223
 
1572 aurelien 224
	private TextField altitude;
1858 raphael 225
 
681 aurelien 226
	private MultiFieldPanel htmlCommunePanel = null;
248 aurelien 227
 
228
	private MultiFieldPanel coordPanel;
229
 
230
	private TextField coordonnees;
1858 raphael 231
 
268 aurelien 232
	private Label lienSelectionCommune = null;
248 aurelien 233
 
681 aurelien 234
	private HTML afficherFormulaireLatLon;
248 aurelien 235
 
236
	private HTML basculerverscarto;
1858 raphael 237
 
248 aurelien 238
	private boolean longlatAjoutee;
264 aurelien 239
 
240
	private boolean latModifiee;
241
 
242
	private boolean longModifiee;
1858 raphael 243
 
1572 aurelien 244
	private boolean altModifiee;
268 aurelien 245
 
246
	protected boolean rechercheCommuneEnCours = false;
247
 
248
	private Timer tCoord;
1858 raphael 249
 
250
	final String resultTplRefPerso = "<div class=\"search-item-commune\">{element_referentiel}</div>";
251
 
252
	private ComboBox selecteurAbondance = null;
253
 
254
	private ComboBox selecteurCertitude = null;
255
 
1542 aurelien 256
	private ComboBox selecteurReferentielTaxo = null;
1858 raphael 257
 
1542 aurelien 258
	private ComboBox selecteurStadePheno = null;
1858 raphael 259
 
1641 aurelien 260
	private boolean selectionMultiple = false;
1858 raphael 261
 
1597 aurelien 262
	private HTML lienAfficherChampsEtendus = null;
1940 aurelien 263
	private HTML lienAjouterChampsEtendus = null;
1858 raphael 264
 
1810 aurelien 265
	Panel conteneurChampEtenduGauche = null;
266
	Panel conteneurChampEtenduDroite = null;
1858 raphael 267
 
1597 aurelien 268
	private boolean afficherChampsEtendus = false;
1940 aurelien 269
	private boolean afficherLienAjoutChampsEtendus = false;
1597 aurelien 270
	private boolean premierAffichage = true;
1858 raphael 271
 
1940 aurelien 272
	private PopupPanel popUpAjoutChampEtendu = new PopupPanel();
273
 
274
	private Map<String, ChampSaisieEtendu> listeChampsEtendus;
1858 raphael 275
 
12 david 276
	/**
277
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
278
	 */
71 jpm 279
	@SuppressWarnings("unused")
12 david 280
	private FormulaireSaisieObservationVue()
281
	{
282
		super() ;
283
	}
1858 raphael 284
 
12 david 285
	/**
286
	 * Constructeur avec argument
287
	 * @param im
288
	 */
289
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
1858 raphael 290
	{
246 aurelien 291
		super("Saisie");
12 david 292
		// on associe le médiateur
293
		observationMediateur = obs ;
1858 raphael 294
 
1542 aurelien 295
		referentielTaxo = obs.getRefTaxSelectionne().getCode();
1858 raphael 296
 
205 aurelien 297
		panneauFormulaire = new FormPanel(Position.RIGHT);
12 david 298
		panneauFormulaire.setBorder(false);
1858 raphael 299
 
12 david 300
		// Panneau intermediaire qui contient deux colonnes de formulaire
1858 raphael 301
		panneauIntermediaire = new Panel();
302
 
230 david 303
		if (Window.getClientWidth()> Window.getClientHeight()) {
1858 raphael 304
			panneauIntermediaire.setLayout(new ColumnLayout());
230 david 305
		}
306
		else {
1858 raphael 307
			panneauIntermediaire.setLayout(new RowLayout());
230 david 308
		}
1858 raphael 309
 
12 david 310
		panneauIntermediaire.setBorder(false);
218 david 311
 
282 aurelien 312
		//création du panneau formulaire de gauche auquels on ajoute les champs
1858 raphael 313
		panneauPremierColonne = new Panel();
314
		panneauPremierColonne.setLayout(new FormLayout());
12 david 315
		panneauPremierColonne.setBorder(false);
316
 
282 aurelien 317
		//création du panneau formulaire de droite
1858 raphael 318
	    panneauSecondeColonne = new Panel();
319
		panneauSecondeColonne.setLayout(new FormLayout());
12 david 320
		panneauSecondeColonne.setBorder(false);
1858 raphael 321
 
42 jpm 322
		this.setPaddings(5) ;
1858 raphael 323
 
195 david 324
		// Accesskey pour debugging
2392 aurelien 325
		commune = new ComboBox("Commune","commune\" accesskey=\"1");
1858 raphael 326
 
327
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
20 david 328
		commune.setTpl(resultTplCommune);
13 david 329
		commune.setMode(ComboBox.REMOTE);
20 david 330
		commune.setItemSelector("div.search-item-commune");
1858 raphael 331
		commune.setTypeAhead(true);
332
		commune.setLoadingText("Recherche...");
13 david 333
		commune.setHideTrigger(true);
1858 raphael 334
 
335
		  //création du lien "Accès carto" dans le formulaire
681 aurelien 336
		basculerverscarto = new HTML(" <a id=\"lien_carto\" href=\"#\" tabindex=\"2\">Localiser la commune</a>");
268 aurelien 337
		basculerverscarto.addStyleName("lien_actif");
1858 raphael 338
 
268 aurelien 339
		//création info bulle sur le lien "accès carto"
1858 raphael 340
		ToolTip tip2 = new ToolTip();
341
		tip2.setHtml("Via une carte, obtenez les coordonnées (latitude/longitude) de votre observation ");
268 aurelien 342
		tip2.applyTo(basculerverscarto.getElement());
1858 raphael 343
 
268 aurelien 344
		//Sur une meme ligne, ajout de plusieurs champs
1858 raphael 345
		htmlCommunePanel = new MultiFieldPanel();
346
 
708 aurelien 347
		int largeurCommune = Window.getClientWidth()/4;
348
		htmlCommunePanel.addToRow(commune, largeurCommune);
1858 raphael 349
		htmlCommunePanel.addToRow(basculerverscarto, 160);
276 aurelien 350
 
268 aurelien 351
		htmlCommunePanel.setBorder(false);
1858 raphael 352
		htmlCommunePanel.setId("x-commune-panel");
13 david 353
 
268 aurelien 354
		panneauPremierColonne.add(htmlCommunePanel);
355
 
728 aurelien 356
	    station = new AutoCompletionRefComboBox("Station", "station", observationMediateur, TypesReferentiels.REFERENTIEL_STATION) {
268 aurelien 357
 
1292 aurelien 358
			@Override
728 aurelien 359
			public void onModificationValeur() {
360
				stationModifiee = true;
361
			}
362
 
1292 aurelien 363
			@Override
728 aurelien 364
			public void onValidationSaisie() {
365
				validerSaisie(Champs.STATION);
1858 raphael 366
			}
728 aurelien 367
	    };
1858 raphael 368
	    panneauPremierColonne.add(station, new AnchorLayoutData("95%"));
369
 
781 aurelien 370
		latitude = new TextField("Lat", "lat");
282 aurelien 371
		latitude.setGrowMax(70);
264 aurelien 372
		latitude.setAllowBlank(true);
1858 raphael 373
 
781 aurelien 374
	    longitude = new TextField("Lon", "lon");
282 aurelien 375
	    longitude.setGrowMax(70);
248 aurelien 376
		longitude.setAllowBlank(true);
1858 raphael 377
 
1572 aurelien 378
		altitude = new TextField("Alt (mètres)", "alt");
379
		altitude.setGrowMax(70);
380
		altitude.setAllowBlank(true);
1858 raphael 381
 
276 aurelien 382
		lienSelectionCommune = new Label("");
1858 raphael 383
 
384
 
268 aurelien 385
		lienSelectionCommune.setId("conteneur_selection_commune");
386
		lienSelectionCommune.setStyleName("conteneur_selection_commune");
276 aurelien 387
		lienSelectionCommune.addStyleName("lien_actif");
1858 raphael 388
 
783 aurelien 389
		// Panneau de type plusieurs champs de formulaire sur une meme ligne, où seront renseignés Lat/Lon
1858 raphael 390
		coordPanel = new MultiFieldPanel();
282 aurelien 391
		coordPanel.setPaddings(0, 0, 0, 10);
248 aurelien 392
		coordPanel.setVisible(false);
1858 raphael 393
 
276 aurelien 394
		final double largeur ;
282 aurelien 395
		largeur = 120;
1858 raphael 396
 
397
		coordPanel.addToRow(latitude, new ColumnLayoutData(largeur));
398
		coordPanel.addToRow(longitude, new ColumnLayoutData(largeur));
399
		coordPanel.addToRow(lienSelectionCommune, new ColumnLayoutData(largeur));
282 aurelien 400
		lienSelectionCommune.addClass("lien_decale");
248 aurelien 401
		coordPanel.setBorder(false);
1858 raphael 402
 
1572 aurelien 403
		coordPanel.addToRow(altitude, new ColumnLayoutData(largeur));
1858 raphael 404
 
405
		  //création du champs coordonnées
264 aurelien 406
		referentielGeo = Configuration.getReferentielGeo();
1858 raphael 407
 
268 aurelien 408
		coordonnees = new TextField("Coordonnées", "", 0);
248 aurelien 409
		coordonnees.setMaxLength(0);
410
		coordonnees.setReadOnly(true);
411
		coordonnees.setCls("fieldname");
1858 raphael 412
 
276 aurelien 413
		//création du lien "saisie X/Y" dans le formulaire
681 aurelien 414
		afficherFormulaireLatLon = new HTML("<span style=\"padding-left:30px;\" class=\"conteneur_lien_afficher_lat_lon\">" +
415
				"<a title=\"Lat / Lon sont les latitudes / longitudes, à remplir en degrés décimaux\" class=\"lien_actif\" id=\"lien_coord\" href=\"#\" tabindex=\"6\">Saisie Lat/Lon ("+referentielGeo+")</a>" +
416
				"<span><span style=\"padding-left:20px\" class=\"conteneur_lien_localiser_lat_lon\">"+
417
				"<a title=\"Cliquez pour obtenir les coordonnées de votre observation à partir de la carte\" class=\"lien_actif\" id=\"lien_carto_coord\" href=\"#\" tabindex=\"7\">Localiser sur la carte</a>"+
418
				"</span>");
1858 raphael 419
 
420
			//ajout d'un listener sur le lien "saisie X/Y"
248 aurelien 421
			coordPanel.addListener(new PanelListenerAdapter() {
1858 raphael 422
 
1292 aurelien 423
				@Override
248 aurelien 424
				public void onAfterLayout(Container c) {
1542 aurelien 425
					surPremierAffichageCoordPanel(largeur);
248 aurelien 426
				}
427
			});
1858 raphael 428
 
276 aurelien 429
		//Sur une meme ligne, ajout de plusieurs champs
1858 raphael 430
		final MultiFieldPanel htmlPanel = new MultiFieldPanel();
431
 
432
		htmlPanel.addToRow(coordonnees, 100);
433
		htmlPanel.addToRow(afficherFormulaireLatLon, new ColumnLayoutData(0.9));
276 aurelien 434
		htmlPanel.setBorder(false);
435
		htmlPanel.setId("x-coord-panel");
1858 raphael 436
 
248 aurelien 437
		panneauPremierColonne.add(htmlPanel);
438
		panneauPremierColonne.add(coordPanel);
1858 raphael 439
 
440
	    date = new DateField("Date", "date", 250);
12 david 441
	    date.setAllowBlank(true);
110 aurelien 442
	    formatDate = "d/m/Y";
443
	    date.setFormat(formatDate) ;
681 aurelien 444
	    date.setTitle("Date de l'observation au format jj/mm/aaaa");
1628 raphael 445
	    date.setMaxValue(new Date());
248 aurelien 446
	    //date.setTabIndex(5);
1858 raphael 447
	    panneauPremierColonne.add(date, new AnchorLayoutData("55%"));
448
 
449
 
450
	    final String champsListeTpl = "<div class=\"x-combo-list-item search-item-tpl\" title=\"{label}\">{label}</div>";
451
 
1542 aurelien 452
	    // Selection d'un référentiel par défaut (le premier spécifié dans la config)
453
	    referentielTaxo = Configuration.getReferentielsDispos().get(0).getCode();
454
	    selecteurReferentielTaxo = new ComboBox();
455
	    selecteurReferentielTaxo.setCls("champ-separation");
456
	    selecteurReferentielTaxo.setLabel("Référentiel");
457
	    selecteurReferentielTaxo.setStore(Ontologies.getValeursReferentiel());
458
	    selecteurReferentielTaxo.setValue(referentielTaxo);
459
	    selecteurReferentielTaxo.setDisplayField("label") ;
460
	    selecteurReferentielTaxo.setValueField("valeur");
461
	    selecteurReferentielTaxo.setEditable(false);
462
	    selecteurReferentielTaxo.setHideTrigger(false);
463
	    selecteurReferentielTaxo.setForceSelection(true);
1559 aurelien 464
	    selecteurReferentielTaxo.setTpl(champsListeTpl);
1858 raphael 465
 
466
		espece=new ComboBox("Espèce","nom");
467
		final String resultTplEspece = "<div class=\"search-item-espece {indicateurNomRetenu}\">{nom}</div>";
20 david 468
 
1858 raphael 469
 
20 david 470
		espece.setTpl(resultTplEspece);
471
		espece.setMode(ComboBox.REMOTE);
472
		espece.setItemSelector("div.search-item-espece");
1858 raphael 473
		espece.setTypeAhead(true);
474
		espece.setLoadingText("Recherche...");
475
 
20 david 476
		espece.setHideTrigger(true);
477
 
1489 aurelien 478
	    Panel panelSeparationPp = new Panel();
479
	    panelSeparationPp.setHeight(15);
480
	    panelSeparationPp.setBorder(false);
1858 raphael 481
 
1489 aurelien 482
	    panneauPremierColonne.add(panelSeparationPp);
1858 raphael 483
	    panneauPremierColonne.add(selecteurReferentielTaxo, new AnchorLayoutData("85%"));
484
	    panneauPremierColonne.add(espece, new AnchorLayoutData("95%"));
485
 
1488 aurelien 486
	    selecteurAbondance = new ComboBox();
1489 aurelien 487
	    selecteurAbondance.setCls("champ-separation");
1488 aurelien 488
	    selecteurAbondance.setLabel("Abondance");
1489 aurelien 489
	    selecteurAbondance.setStore(Ontologies.getValeursAbondance());
1488 aurelien 490
	    selecteurAbondance.setDisplayField("label") ;
491
	    selecteurAbondance.setValueField("valeur");
492
	    selecteurAbondance.setEditable(true);
493
	    selecteurAbondance.setHideTrigger(false);
494
	    selecteurAbondance.setForceSelection(false);
1559 aurelien 495
	    selecteurAbondance.setTpl(champsListeTpl);
1858 raphael 496
	    panneauPremierColonne.add(selecteurAbondance,  new AnchorLayoutData("95%"));
497
 
728 aurelien 498
	    lieudit = new AutoCompletionRefComboBox("Lieu-dit", "lieudit",observationMediateur,TypesReferentiels.REFERENTIEL_LIEU_DIT) {
499
 
1292 aurelien 500
			@Override
728 aurelien 501
			public void onModificationValeur() {
1858 raphael 502
				lieuDitModifie = true;
728 aurelien 503
			}
504
 
1292 aurelien 505
			@Override
728 aurelien 506
			public void onValidationSaisie() {
507
				validerSaisie(Champs.LIEUDIT);
508
			}
509
	    };
1858 raphael 510
	    panneauSecondeColonne.add(lieudit,  new AnchorLayoutData("95%"));
511
 
728 aurelien 512
	    milieu = new AutoCompletionRefComboBox("Milieu","milieu",observationMediateur,TypesReferentiels.REFERENTIEL_MILIEU) {
513
 
1292 aurelien 514
			@Override
728 aurelien 515
			public void onModificationValeur() {
516
				milieuModifie = true;
517
			}
518
 
1292 aurelien 519
			@Override
728 aurelien 520
			public void onValidationSaisie() {
521
				validerSaisie(Champs.MILIEU);
522
			}
1858 raphael 523
 
728 aurelien 524
	    };
201 david 525
	    panneauSecondeColonne.add(milieu,  new AnchorLayoutData("95%"));
1858 raphael 526
 
527
	    comment = new TextArea("Notes", "comment");
128 aurelien 528
	    comment.setAllowBlank(true);
529
	    comment.setHeight(50);
1858 raphael 530
 
201 david 531
	    panneauSecondeColonne.add(comment, new AnchorLayoutData("95%") );
1858 raphael 532
 
1489 aurelien 533
	    Panel panelSeparationPs = new Panel();
1542 aurelien 534
	    panelSeparationPs.setHeight(39);
1489 aurelien 535
	    panelSeparationPs.setBorder(false);
1858 raphael 536
 
1489 aurelien 537
	    panneauSecondeColonne.add(panelSeparationPs);
1858 raphael 538
 
1489 aurelien 539
	    selecteurCertitude = new ComboBox();
540
	    selecteurCertitude.setLabel("Identification");
541
	    selecteurCertitude.setStore(Ontologies.getValeursCertitude());
542
	    selecteurCertitude.setDisplayField("label") ;
543
	    selecteurCertitude.setValueField("valeur");
544
	    selecteurCertitude.setEditable(true);
545
	    selecteurCertitude.setHideTrigger(false);
546
	    selecteurCertitude.setForceSelection(false);
1559 aurelien 547
	    selecteurCertitude.setTpl(champsListeTpl);
1858 raphael 548
	    panneauSecondeColonne.add(selecteurCertitude, new AnchorLayoutData("95%"));
549
 
1542 aurelien 550
	    selecteurStadePheno = new ComboBox();
551
	    selecteurStadePheno.setLabel("Phénologie");
552
	    selecteurStadePheno.setStore(Ontologies.getValeursPhenologie());
553
	    selecteurStadePheno.setDisplayField("label") ;
554
	    selecteurStadePheno.setValueField("valeur");
555
	    selecteurStadePheno.setEditable(true);
556
	    selecteurStadePheno.setHideTrigger(false);
557
	    selecteurStadePheno.setForceSelection(false);
1559 aurelien 558
	    selecteurStadePheno.setTpl(champsListeTpl);
1858 raphael 559
	    panneauSecondeColonne.add(selecteurStadePheno, new AnchorLayoutData("95%"));
560
 
276 aurelien 561
	    if (Window.getClientWidth() > Window.getClientHeight() || Window.getClientWidth() < 800) {
230 david 562
			panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
563
			panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
564
	    }
565
	    else {
566
			panneauIntermediaire.add(panneauPremierColonne);
1858 raphael 567
			panneauIntermediaire.add(panneauSecondeColonne);
230 david 568
	    }
1858 raphael 569
 
12 david 570
		panneauFormulaire.add(panneauIntermediaire);
1940 aurelien 571
 
276 aurelien 572
		if (Ext.isIE()) {
218 david 573
			panneauPremierColonne.setButtonAlign(Position.RIGHT);
574
			panneauPremierColonne.addButton(boutonOK);
1641 aurelien 575
			panneauPremierColonne.addButton(boutonModifier);
576
			panneauPremierColonne.addButton(boutonSupprimer);
218 david 577
			panneauSecondeColonne.setButtonAlign(Position.LEFT);
276 aurelien 578
			panneauPremierColonne.addButton(boutonAnnuler);
218 david 579
		}
1858 raphael 580
		else {
218 david 581
			panneauFormulaire.addButton(boutonOK);
1641 aurelien 582
			panneauFormulaire.addButton(boutonModifier);
583
			panneauFormulaire.addButton(boutonSupprimer);
1858 raphael 584
			panneauFormulaire.addButton(boutonAnnuler);
218 david 585
		}
1858 raphael 586
 
12 david 587
		this.add(panneauFormulaire) ;
1858 raphael 588
 
120 aurelien 589
		this.setAutoScroll(true);
1858 raphael 590
 
591
 
201 david 592
		panneauFormulaire.addListener(new PanelListenerAdapter() {
1292 aurelien 593
	        @Override
594
			public void onResize(BoxComponent component, int adjWidth, int adjHeight, int rawWidth, int rawHeight) {
201 david 595
	        	panneauIntermediaire.setWidth(rawWidth);
596
	        	panneauIntermediaire.setHeight(rawHeight);
1858 raphael 597
 
276 aurelien 598
	        	panneauPremierColonne.doLayout();
599
	        	panneauSecondeColonne.doLayout();
1858 raphael 600
 
276 aurelien 601
	        	htmlCommunePanel.doLayout();
602
	        	htmlPanel.doLayout();
1858 raphael 603
 
318 aurelien 604
	        	doLayout();
1542 aurelien 605
	        }
606
	    });
1858 raphael 607
 
1597 aurelien 608
		lienAfficherChampsEtendus = new HTML("Afficher les champs étendus");
609
		lienAfficherChampsEtendus.setStyleName("img-curseur-depl");
610
		lienAfficherChampsEtendus.setStyleName("lienAfficherChampsEtendus");
611
		lienAfficherChampsEtendus.setVisible(false);
612
 
613
		lienAfficherChampsEtendus.addClickHandler(new ClickHandler() {
614
			@Override
615
			public void onClick(ClickEvent event) {
616
				if(afficherChampsEtendus) {
617
					afficherChampsEtendus = false;
618
					if(conteneurChampEtenduGauche != null && conteneurChampEtenduDroite != null) {
619
						conteneurChampEtenduGauche.hide();
620
						conteneurChampEtenduDroite.hide();
621
					}
622
					lienAfficherChampsEtendus.setText("Afficher les champs étendus");
1858 raphael 623
 
1597 aurelien 624
				} else {
625
					afficherChampsEtendus = true;
626
					if(conteneurChampEtenduGauche != null && conteneurChampEtenduDroite != null) {
627
						conteneurChampEtenduGauche.show();
628
						conteneurChampEtenduDroite.show();
629
					}
630
					lienAfficherChampsEtendus.setText("Cacher les champs étendus");
631
				}
632
			}
633
		});
1940 aurelien 634
 
635
		if(Configuration.saisieChampsEtendusActivee()) {
2392 aurelien 636
			// Chargement du cache des correspondances cles/labels du catalogue
637
			ListeReferentielChampsEtendusDAO lrceDao = new ListeReferentielChampsEtendusDAO(null);
638
			lrceDao.obtenirGroupesChampsEtendus(this);
639
			lrceDao.obtenirCatalogueChampsEtendus(this);
640
 
1940 aurelien 641
			lienAjouterChampsEtendus = new HTML("Ajouter un champ étendu");
642
			lienAjouterChampsEtendus.addStyleName("lienAjouterChampEtendu");
643
			lienAjouterChampsEtendus.setVisible(true);
644
			panneauPremierColonne.add(lienAjouterChampsEtendus);
645
			gererLienAjoutChampsEtendus();
646
		}
647
 
1597 aurelien 648
		panneauPremierColonne.add(lienAfficherChampsEtendus);
649
		panneauPremierColonne.addListener(new PanelListenerAdapter() {
650
			@Override
651
			public void onAfterLayout(Container c) {
652
				if(premierAffichage) {
653
					lienAfficherChampsEtendus.setVisible(false);
654
					premierAffichage = false;
655
				}
656
			}
657
		});
1641 aurelien 658
 
12 david 659
		ajouterListeners() ;
1641 aurelien 660
		ajouterToolTipsBoutons();
248 aurelien 661
		saisieTabindex();
12 david 662
	}
1940 aurelien 663
 
664
	private void gererLienAjoutChampsEtendus() {
665
		popUpAjoutChampEtendu.setStylePrimaryName("popup_champ_etendu");
666
		lienAjouterChampsEtendus.addClickHandler(new ClickHandler() {
667
			@Override
668
			public void onClick(ClickEvent event) {
1945 aurelien 669
				FormulaireSaisieChampEtendu formChamp = new FormulaireSaisieChampEtendu() {
670
 
1940 aurelien 671
					@Override
672
					public void surValidation(ChampSaisieEtendu champ) {
1945 aurelien 673
						ajouterChampEtenduAuFormulaire(champ, true);
1967 aurelien 674
						popUpAjoutChampEtendu.clear();
675
						popUpAjoutChampEtendu.hide();
1940 aurelien 676
					}
1945 aurelien 677
 
678
					@Override
679
					public void surAjout(ChampSaisieEtendu champ) {
680
						ajouterChampEtenduAuFormulaire(champ, false);
681
					}
1858 raphael 682
 
1940 aurelien 683
					@Override
684
					public void surAnnulation() {
685
						popUpAjoutChampEtendu.clear();
686
						popUpAjoutChampEtendu.hide();
687
					}
1967 aurelien 688
 
689
					@Override
690
					public void surAjoutMultiple(List<ChampSaisieEtendu> champs) {
691
						for (Iterator<ChampSaisieEtendu> iterator = champs.iterator(); iterator.hasNext();) {
692
							ChampSaisieEtendu champSaisieEtendu = (ChampSaisieEtendu) iterator.next();
693
							ajouterChampEtenduAuFormulaire(champSaisieEtendu, false);
694
						}
695
					}
696
 
697
					@Override
698
					public void surValidationMultiple(List<ChampSaisieEtendu> champs) {
699
						for (Iterator<ChampSaisieEtendu> iterator = champs.iterator(); iterator.hasNext();) {
700
							ChampSaisieEtendu champSaisieEtendu = (ChampSaisieEtendu) iterator.next();
701
							ajouterChampEtenduAuFormulaire(champSaisieEtendu, false);
702
						}
703
						popUpAjoutChampEtendu.clear();
704
						popUpAjoutChampEtendu.hide();
705
					}
1940 aurelien 706
				};
707
				popUpAjoutChampEtendu.add(formChamp);
708
				popUpAjoutChampEtendu.center();
1945 aurelien 709
				popUpAjoutChampEtendu.setModal(true);
1940 aurelien 710
				popUpAjoutChampEtendu.show();
711
			}
712
		});
713
	}
714
 
1945 aurelien 715
	private void ajouterChampEtenduAuFormulaire(ChampSaisieEtendu nChamp, boolean fermerPopup) {
1940 aurelien 716
		ChampEtendu chet = new ChampEtendu(nChamp.getName(), nChamp.getFieldLabel(), "");
717
		Map<String, ChampEtendu> champsEt = getValeursChampsEtendus();
1945 aurelien 718
		if(!champsEt.containsKey(chet.getCle())) {
719
			champsEt.put(chet.getCle(), chet);
720
			afficherChampsEtendus = true;
721
			if(fermerPopup) {
722
				afficherChampsEtendus(champsEt, chet);
723
				popUpAjoutChampEtendu.clear();
724
				popUpAjoutChampEtendu.hide();
725
			} else {
726
				afficherChampsEtendus(champsEt, null);
727
			}
728
		} else {
729
			Window.alert("Le champ "+chet.getLabel()+" est déjà présent dans le formulaire");
730
		}
1940 aurelien 731
	}
732
 
1641 aurelien 733
	private void ajouterToolTipsBoutons() {
734
		boutonOK.setTitle("Crée une nouvelle observation à partir des champs saisis dans le formulaire");
735
		boutonModifier.setTitle("Modifie la ou les observations sélectionnées");
736
		boutonSupprimer.setTitle("Supprime la ou les observations sélectionnées");
1858 raphael 737
		boutonAnnuler.setTitle("Vide tous les champs du formulaire");
1641 aurelien 738
	}
1858 raphael 739
 
1542 aurelien 740
	private void surPremierAffichageCoordPanel(final double largeur) {
741
		ExtElement lienCoord = Ext.get("lien_coord");
742
		lienCoord.removeAllListeners();
743
		lienCoord.addListener("click", new EventCallback() {
744
			@Override
745
			public void execute(EventObject e) {
1858 raphael 746
 
1542 aurelien 747
				coordPanel.setVisible(!coordPanel.isVisible());
1858 raphael 748
 
1542 aurelien 749
				if(Ext.isIE()) {
750
					latitude.focus();
120 aurelien 751
				}
1858 raphael 752
 
1542 aurelien 753
				CarnetEnLigneMediateur.fireResize();
754
			}
755
		}) ;
1858 raphael 756
 
1542 aurelien 757
		ExtElement lienCartoCoord = Ext.get("lien_carto_coord");
758
		lienCartoCoord.removeAllListeners();
759
		lienCartoCoord.addListener("click", new EventCallback() {
760
			@Override
761
			public void execute(EventObject e) {
762
				obtenirInformationCoord();
763
			}
764
		}) ;
1858 raphael 765
 
1542 aurelien 766
		ExtElement lienCarto = Ext.get("lien_carto");
767
		lienCarto.removeAllListeners();
768
		lienCarto.addListener("click", new EventCallback() {
20 david 769
 
1542 aurelien 770
			@Override
771
			public void execute(EventObject e) {
1858 raphael 772
 
1542 aurelien 773
				if(commune.getValue() != null && !commune.getValue().equals("") && !getDepartement().equals("")) {
774
					obtenirInformationCommune();
775
					longlatAjoutee = true;
1858 raphael 776
 
1542 aurelien 777
				} else {
778
					Window.alert("Veuillez renseigner une commune et un numéro de département sous la forme : Commune (departement)");
264 aurelien 779
				}
1542 aurelien 780
			}
781
		});
1858 raphael 782
 
1542 aurelien 783
		if(!Ext.isIE() && Window.getClientWidth() < 1200) {
1858 raphael 784
 
1542 aurelien 785
			int largeurN = (int)largeur;
1858 raphael 786
 
1542 aurelien 787
			latitude.setWidth(largeurN+"px");
788
			longitude.setWidth(largeurN+"px");
1858 raphael 789
			lienSelectionCommune.setWidth(largeurN+"px");
1542 aurelien 790
		}
791
	}
1858 raphael 792
 
1542 aurelien 793
	private void ajouterListeners()
1858 raphael 794
	{
795
		// Listener completion communne
1542 aurelien 796
		final Rafraichissable r = this;
1858 raphael 797
 
1542 aurelien 798
		ListenerConfig listenerConfigCommune=new ListenerConfig();
799
		listenerConfigCommune.setDelay(200);
800
		listenerConfigCommune.setStopPropagation(false);
801
		listenerConfigCommune.setStopEvent(false);
1488 aurelien 802
 
1542 aurelien 803
	    date.addListener(new DatePickerListenerAdapter() {
1488 aurelien 804
 
1542 aurelien 805
			@Override
806
			public void onSelect(DatePicker dataPicker, Date date) {
807
				dateModifiee = true;
808
			}
809
	    });
1858 raphael 810
 
1542 aurelien 811
	    ListenerConfig listenerConfigAutocompletion=new ListenerConfig();
812
	    listenerConfigAutocompletion.setDelay(200);
813
	    listenerConfigAutocompletion.setStopPropagation(false);
814
	    listenerConfigAutocompletion.setStopEvent(false);
1858 raphael 815
 
1542 aurelien 816
		ListenerConfig listenerConfigEspece=new ListenerConfig();
817
		listenerConfigEspece.setDelay(10);
818
		listenerConfigEspece.setStopPropagation(false);
819
		listenerConfigEspece.setStopEvent(false);
1858 raphael 820
 
1542 aurelien 821
		tCoord = new Timer() {
1488 aurelien 822
 
1542 aurelien 823
			@Override
824
			public void run() {
825
	        	double[] coord = coordonneesValides();
826
	        	if(!rechercheCommuneEnCours && coord != null && (longModifiee || latModifiee)) {
827
	        		rechercheCommuneEnCours = true;
828
	        		Ext.get(lienSelectionCommune.getElement()).mask("recherche");
1958 aurelien 829
	        		observationMediateur.obtenirInformationCoord(r,coord[0], coord[1]);
1542 aurelien 830
	        	}
831
			}
1858 raphael 832
 
1542 aurelien 833
		};
1858 raphael 834
 
1542 aurelien 835
		ajouterListenerChampEvenementsClavier(commune, listenerConfigCommune);
836
	    ajouterListenerChampEvenementsClavier(date);
837
		ajouterListenerChampEvenementsClavier(selecteurReferentielTaxo);
838
		ajouterListenerChampEvenementsClavier(espece, listenerConfigEspece);
839
		ajouterListenerChampEvenementsClavier(comment);
840
		ajouterListenerChampEvenementsClavier(latitude);
841
		ajouterListenerChampEvenementsClavier(longitude);
1572 aurelien 842
		ajouterListenerChampEvenementsClavier(altitude);
1858 raphael 843
		ajouterListenerChampEvenementsClavier(selecteurAbondance);
844
		ajouterListenerChampEvenementsClavier(selecteurCertitude);
1542 aurelien 845
		ajouterListenerChampEvenementsClavier(selecteurStadePheno);
846
		ajouterListenerChampsCombobox();
1858 raphael 847
 
20 david 848
		boutonOK.addListener(new ButtonListenerAdapter() {
1292 aurelien 849
			@Override
1858 raphael 850
			public void onClick(Button button, EventObject e) {
1641 aurelien 851
				ajouterObservation();
1858 raphael 852
			}
1641 aurelien 853
		});
1858 raphael 854
 
1641 aurelien 855
		boutonModifier.addListener(new ButtonListenerAdapter() {
856
			@Override
1858 raphael 857
			public void onClick(Button button, EventObject e) {
1641 aurelien 858
				if(selectionMultiple) {
859
						modifierObservationEnMasse(null);
860
				} else {
861
					modifierObservation() ;
71 jpm 862
				}
1858 raphael 863
			}
1641 aurelien 864
		});
1858 raphael 865
 
1641 aurelien 866
		boutonSupprimer.addListener(new ButtonListenerAdapter() {
867
			@Override
1858 raphael 868
			public void onClick(Button button, EventObject e) {
1641 aurelien 869
				if(!selectionMultiple) {
870
					supprimerObservation();
871
				} else {
872
					observationMediateur.supprimerObservations();
71 jpm 873
				}
1858 raphael 874
			}
20 david 875
		});
1858 raphael 876
 
877
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
1292 aurelien 878
			@Override
1858 raphael 879
			public void onClick(Button button, EventObject e) {
1641 aurelien 880
					setSelectionMultiple(false);
104 jpm 881
					raz();
1858 raphael 882
			}
12 david 883
		});
1858 raphael 884
 
132 aurelien 885
		this.addListener(new ContainerListenerAdapter() {
1292 aurelien 886
			@Override
132 aurelien 887
			public void onAfterLayout(Container self) {
888
				commune.focus();
889
			}
1858 raphael 890
		});
12 david 891
	}
1858 raphael 892
 
1542 aurelien 893
	private void ajouterListenerChampsCombobox() {
1858 raphael 894
		commune.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 895
            @Override
1858 raphael 896
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 897
                commune.setValue(record.getAsString("commune"));
898
                departement=record.getAsString("departement");
899
                codeInseeCommune=record.getAsString("codeInsee");
900
                selectionCommune=true;
901
                commune.collapse();
1858 raphael 902
            }
903
 
1542 aurelien 904
            @Override
905
			public void onExpand(ComboBox comboBox) {
906
           	 comboBox.focus();
907
            }
1858 raphael 908
        });
909
 
910
		selecteurReferentielTaxo.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 911
             @Override
1672 aurelien 912
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 913
            	 referentielTaxo = record.getAsString("valeur");
914
                 observationMediateur.setRefTaxSelectionne(index);
915
                 referentielTaxoModifie = true;
1858 raphael 916
             }
917
         });
918
 
919
		espece.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 920
             @Override
1858 raphael 921
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 922
            	 espece.setValue(record.getAsString("nom"));
923
            	 numeroNom=record.getAsString("numeroNom");
924
                 selectionEspece=true;
925
                 observationMediateur.obtenirImageInformationExternes(referentielTaxo, numeroNom);
1858 raphael 926
             }
927
         });
928
 
929
		selecteurAbondance.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 930
			@Override
1858 raphael 931
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 932
                 selectionAbondance=true;
933
                 abondanceModifiee = true;
934
             }
935
         });
708 aurelien 936
 
1858 raphael 937
		selecteurCertitude.addListener(new ComboBoxListenerAdapter() {
938
 
1542 aurelien 939
			@Override
1858 raphael 940
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 941
                 selectionCertitude=true;
942
                 certitudeModifiee = true;
943
             }
1858 raphael 944
         });
945
 
946
		selecteurStadePheno.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 947
			@Override
1858 raphael 948
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 949
                 selectionPhenologie=true;
950
                 phenologieModifiee = true;
951
             }
1858 raphael 952
         });
1542 aurelien 953
	}
1858 raphael 954
 
1542 aurelien 955
	private void ajouterListenerChampEvenementsClavier(final TextField champ) {
956
		champ.addKeyPressListener(new EventCallback() {
957
			@Override
958
			public void execute(EventObject e) {
959
				surEvenementClavier(e, champ);
960
			}
961
	    });
962
	}
1858 raphael 963
 
1542 aurelien 964
	private void ajouterListenerChampEvenementsClavier(final TextField champ, final ListenerConfig config) {
965
		champ.addKeyPressListener(new EventCallback() {
966
			@Override
967
			public void execute(EventObject e) {
968
				surEvenementClavier(e, champ);
969
			}
970
	    }, config);
971
	}
1858 raphael 972
 
1542 aurelien 973
	private void surEvenementClavier(EventObject e, TextField champ) {
1858 raphael 974
		switch(e.getKey()) {
1542 aurelien 975
			case KEY_ALT:
976
			case KEY_CTRL:
977
			case KEY_DOWN:
978
			case KEY_END:
979
			case KEY_ESCAPE:
980
			case KEY_HOME:
981
			case KEY_LEFT:
982
			case KEY_PAGEDOWN:
983
			case KEY_PAGEUP:
984
			case KEY_RIGHT:
985
			case KEY_SHIFT:
986
			case KEY_TAB:
987
			case KEY_UP:
988
	        break;
1858 raphael 989
 
1542 aurelien 990
		    case KEY_ENTER:
991
		    	surEvenementClavierToucheEntree(champ);
992
		    	break;
1858 raphael 993
 
1542 aurelien 994
	        default:
995
	        	gererEvenementClavierDefaut(champ);
996
	        break;
997
		}
998
	}
1858 raphael 999
 
1542 aurelien 1000
	private void surEvenementClavierToucheEntree(TextField champ) {
1001
		//TODO: faire un switch ou une enum
1002
		if(champ.equals(selecteurStadePheno)) {
1858 raphael 1003
			if(!selectionPhenologie) {
1004
  	    		validerSaisie(Champs.PHENOLOGIE);
1542 aurelien 1005
	    	} else {
1006
	    		selectionPhenologie = false;
1007
	    	}
1008
		}
1858 raphael 1009
 
1542 aurelien 1010
		if(champ.equals(selecteurCertitude)) {
1858 raphael 1011
			if(!selectionCertitude) {
1012
		    		validerSaisie(Champs.CERTITUDE);
1542 aurelien 1013
	    	} else {
1014
	    		selectionCertitude = false;
1015
	    	}
1016
		}
1858 raphael 1017
 
1542 aurelien 1018
		if(champ.equals(selecteurAbondance)) {
1858 raphael 1019
			if(!selectionAbondance) {
1020
		    	validerSaisie(Champs.ABONDANCE);
1542 aurelien 1021
	    	} else {
1022
	    		selectionAbondance = false;
1023
	    	}
1024
		}
1858 raphael 1025
 
1542 aurelien 1026
		if(champ.equals(longitude)) {
1027
			validerSaisie(Champs.LONGITUDE);
1028
		}
1858 raphael 1029
 
1030
		if(champ.equals(latitude)) {
1031
	    	validerSaisie(Champs.LATITUDE);
1542 aurelien 1032
		}
1858 raphael 1033
 
1034
		if(champ.equals(altitude)) {
1035
	    	validerSaisie(Champs.ALTITUDE);
1572 aurelien 1036
		}
1858 raphael 1037
 
1542 aurelien 1038
		if(champ.equals(espece)) {
1039
			if(selectionEspece) {
1040
	    		especeModifiee = true;
1041
	    		selectionEspece=false;
1042
	    	}
1043
	    	else {
1858 raphael 1044
	    		validerSaisie(Champs.ESPECE);
1542 aurelien 1045
	    	}
1046
		}
1858 raphael 1047
 
1542 aurelien 1048
		if(champ.equals(selecteurReferentielTaxo)) {
1858 raphael 1049
			validerSaisie(Champs.REFERENTIELTAXO);
1542 aurelien 1050
		}
1858 raphael 1051
 
1542 aurelien 1052
		if(champ.equals(date)) {
1858 raphael 1053
			validerSaisie(Champs.DATE);
1542 aurelien 1054
		}
1858 raphael 1055
 
1056
		if(champ.equals(commune)) {
1542 aurelien 1057
			if(champ.equals(commune)) {
1058
				if (selectionCommune) {
1059
		    		 communeModifiee= true;
1060
		    		 selectionCommune=false;
1061
		    	 }
1062
		    	else {
1858 raphael 1063
		    		validerSaisie(Champs.COMMUNE);
1542 aurelien 1064
		    	 }
1065
			}
1066
		}
1067
	}
1858 raphael 1068
 
1542 aurelien 1069
	private void gererEvenementClavierDefaut(TextField champ) {
1070
		//TODO: faire un switch ou une enum
1071
		if(champ.equals(selecteurStadePheno)) {
1072
			selecteurStadePheno.setRawValue(selecteurStadePheno.getRawValue());
1073
			selecteurStadePheno.setValue(selecteurStadePheno.getRawValue());
1074
			phenologieModifiee = true;
1075
			selectionPhenologie = false;
1076
		}
1858 raphael 1077
 
1542 aurelien 1078
		if(champ.equals(selecteurCertitude)) {
1079
			selecteurCertitude.setRawValue(selecteurCertitude.getRawValue());
1080
	    	selecteurCertitude.setValue(selecteurCertitude.getRawValue());
1081
	    	certitudeModifiee = true;
1082
	    	selectionCertitude = false;
1083
		}
1858 raphael 1084
 
1542 aurelien 1085
		if(champ.equals(selecteurAbondance)) {
1086
			selecteurAbondance.setRawValue(selecteurAbondance.getRawValue());
1087
	    	selecteurAbondance.setValue(selecteurAbondance.getRawValue());
1088
	    	abondanceModifiee = true;
1089
	    	selectionAbondance = false;
1090
		}
1858 raphael 1091
 
1542 aurelien 1092
		if(champ.equals(longitude)) {
1093
			longModifiee = true;
1094
        	tCoord.cancel();
1095
        	tCoord.schedule(250);
1096
		}
1858 raphael 1097
 
1098
		if(champ.equals(latitude)) {
1542 aurelien 1099
			latModifiee = true;
1100
	      	tCoord.cancel();
1101
	      	tCoord.schedule(250);
1102
		}
1858 raphael 1103
 
1104
		if(champ.equals(altitude)) {
1105
			altModifiee = true;
1572 aurelien 1106
		}
1858 raphael 1107
 
1542 aurelien 1108
		if(champ.equals(comment)) {
1109
			commModifie = true;
1110
		}
1858 raphael 1111
 
1542 aurelien 1112
		if(champ.equals(espece)) {
1113
			numeroNom="";
1114
	    	obtenirListeReferentielNom();
1115
	    	especeModifiee = true;
1116
		}
1858 raphael 1117
 
1542 aurelien 1118
		if(champ.equals(selecteurReferentielTaxo)) {
1119
			referentielTaxoModifie = true;
1120
		}
1858 raphael 1121
 
1542 aurelien 1122
		if(champ.equals(date)) {
1123
			dateModifiee = true;
1124
		}
1858 raphael 1125
 
1542 aurelien 1126
		if(champ.equals(commune)) {
1127
			departement="";
1858 raphael 1128
	    	commune.collapse();
1542 aurelien 1129
	    	obtenirListeReferentielCommune();
1858 raphael 1130
	    	communeModifiee= true;
1542 aurelien 1131
		}
1132
	}
1133
 
12 david 1134
	/**
1858 raphael 1135
	 * Validation de la saisie
118 david 1136
	 */
1858 raphael 1137
 
118 david 1138
	private void validerSaisie(Champs champs) {
1641 aurelien 1139
		if(!selectionMultiple) {
118 david 1140
			ajouterObservation();
1141
			raz(champs);
1641 aurelien 1142
		} else {
1143
			modifierObservationEnMasse(champs);
118 david 1144
		}
1145
	}
1858 raphael 1146
 
118 david 1147
	/**
12 david 1148
	 * Desactive visuellement ce panneau
1149
	 */
1150
	public void desactiverPanneau()
1151
	{
1152
		this.setDisabled(true) ;
1153
	}
1858 raphael 1154
 
12 david 1155
	/**
1156
	 * Active visuellement ce panneau
1157
	 */
1158
	public void activerPanneau()
1159
	{
1160
		this.setDisabled(false) ;
1161
	}
13 david 1162
 
1292 aurelien 1163
	@Override
13 david 1164
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
1858 raphael 1165
 
49 david 1166
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
1672 aurelien 1167
		if(nouvelleDonnees instanceof ListeReferentielCommune)
1168
		{
1169
			ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
1170
			Object[][] communeData = new Object[data.size()][3];
1171
			int i = 0 ;
1858 raphael 1172
 
1672 aurelien 1173
			// on la parse et on récupère les informations quiç nous interessent
1858 raphael 1174
			for (Iterator it = data.keySet().iterator(); it.hasNext();)
1175
			{
1672 aurelien 1176
				ReferentielCommune ref=data.get(it.next());
1858 raphael 1177
 
1672 aurelien 1178
				communeData[i][0]= ref.getCommune();
1179
				communeData[i][1]= ref.getDepartement();
1180
				communeData[i][2]= ref.getCodeInsee();
1181
				i++ ;
13 david 1182
			}
1858 raphael 1183
 
1672 aurelien 1184
			// creation du store
1185
			FieldDef defCommune = new StringFieldDef("commune");
1186
			FieldDef defDepartement = new StringFieldDef("departement");
1187
			FieldDef defCodeInsee = new StringFieldDef("codeInsee");
1858 raphael 1188
 
1672 aurelien 1189
			FieldDef[] defTab = { defCommune, defDepartement, defCodeInsee};
1858 raphael 1190
 
1672 aurelien 1191
			RecordDef rd = new RecordDef(defTab);
1858 raphael 1192
 
1672 aurelien 1193
			final MemoryProxy dataProxy = new MemoryProxy(communeData);
1858 raphael 1194
			final ArrayReader reader = new ArrayReader(rd);
1195
 
1196
			Store store=new Store(dataProxy,reader);
1672 aurelien 1197
			commune.setStore(store);
1198
			store.load();
1858 raphael 1199
 
1672 aurelien 1200
		}
1858 raphael 1201
 
1672 aurelien 1202
		// si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
1203
		if(nouvelleDonnees instanceof ListeReferentielNom)
1204
		{
1205
			ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
1206
			Object[][] nomData = new Object[data.size()][3];
1207
			int i = 0 ;
1208
 
1209
			// on la parse et on récupère les informations qui nous interessent
1858 raphael 1210
			for (Iterator it = data.keySet().iterator(); it.hasNext();)
71 jpm 1211
			{
1858 raphael 1212
 
1672 aurelien 1213
				ReferentielNom ref=data.get(it.next());
1858 raphael 1214
 
1672 aurelien 1215
				nomData[i][0]= ref.getNom();
1216
				nomData[i][1]= ref.getNumeroNom();
1217
				if (ref.getStatut().equals("3")) {
1218
					nomData[i][2]="nom_retenu";
1219
				}
1220
				else {
1221
					nomData[i][2]="";
1858 raphael 1222
				}
1672 aurelien 1223
				i++ ;
216 aurelien 1224
			}
1672 aurelien 1225
 
1226
			FieldDef defNom = new StringFieldDef("nom");
1227
			FieldDef defNumeroNom = new StringFieldDef("numeroNom");
1228
			FieldDef indicateurNomRetenu = new StringFieldDef("indicateurNomRetenu");
1858 raphael 1229
 
1672 aurelien 1230
			FieldDef[] defTab = { defNom, defNumeroNom, indicateurNomRetenu};
1858 raphael 1231
 
1672 aurelien 1232
			RecordDef rd = new RecordDef(defTab);
1858 raphael 1233
 
1672 aurelien 1234
			final MemoryProxy dataProxy = new MemoryProxy(nomData);
1858 raphael 1235
			final ArrayReader reader = new ArrayReader(rd);
1236
 
1237
			Store store=new Store(dataProxy,reader);
1672 aurelien 1238
			espece.setStore(store);
1239
			store.load() ;
1240
		}
1858 raphael 1241
 
1242
		// On recoit une observation dont on veut afficher le detail
1243
 
1672 aurelien 1244
		if(nouvelleDonnees instanceof Observation)
1245
		{
1246
			Observation obs = (Observation)nouvelleDonnees ;
1247
			setSelectionMultiple(false);
1248
			afficherDetailsObservation(obs) ;
1249
		}
1858 raphael 1250
 
1672 aurelien 1251
		if(nouvelleDonnees instanceof ListeObservation) {
1858 raphael 1252
 
1672 aurelien 1253
			ListeObservation listeObs = (ListeObservation)nouvelleDonnees;
1254
			setSelectionMultiple(true);
1255
			calculerAfficherDifferences(listeObs);
1256
		}
1858 raphael 1257
 
1672 aurelien 1258
		if(nouvelleDonnees instanceof String)
1259
		{
1260
			String str = (String)nouvelleDonnees ;
1261
			observationMediateur.obtenirNombreObservation() ;
1262
		}
1858 raphael 1263
 
1672 aurelien 1264
		if(nouvelleDonnees instanceof String[]) {
1265
			String[] anumNom = (String[])nouvelleDonnees ;
1266
			numeroNom = anumNom[1];
1267
			espece.setValue(anumNom[0]);
1268
		}
1858 raphael 1269
 
1672 aurelien 1270
		if(nouvelleDonnees instanceof EntiteGeographiqueObservation)
1271
		{
1272
			EntiteGeographiqueObservation infosComm = (EntiteGeographiqueObservation)nouvelleDonnees ;
1273
			if(rechercheCommuneEnCours) {
1274
				afficherIndicationCommune(infosComm);
1275
			} else {
1276
				rafraichirCommuneEtCoord(infosComm);
248 aurelien 1277
			}
1672 aurelien 1278
		}
13 david 1279
	}
1858 raphael 1280
 
268 aurelien 1281
	private void afficherIndicationCommune(
1282
			final EntiteGeographiqueObservation infosCom) {
1858 raphael 1283
 
248 aurelien 1284
		String nCommune = "";
962 aurelien 1285
		if(infosCom != null && !infosCom.getZoneGeo().trim().equals("")){
1286
			nCommune += infosCom.getZoneGeo();
1287
			if(!infosCom.getIdZoneGeo().trim().equals(""))
1332 aurelien 1288
			nCommune += " ("+Util.convertirChaineZoneGeoVersDepartement(infosCom.getIdZoneGeo())+")";
1858 raphael 1289
 
681 aurelien 1290
			lienSelectionCommune.setHtml("<a id=\"lien_selection_commune\" tabindex=\"9\">"+nCommune+"</a>");
1291
			lienSelectionCommune.setStyleName("img-curseur-depl");
1858 raphael 1292
 
681 aurelien 1293
			Ext.get("lien_selection_commune").addListener("click",new EventCallback() {
1292 aurelien 1294
				@Override
681 aurelien 1295
				public void execute(EventObject e) {
1296
					rafraichirCommune(infosCom);
1858 raphael 1297
				}
681 aurelien 1298
			});
1858 raphael 1299
 
681 aurelien 1300
			Ext.get("lien_selection_commune").addListener("keypress",new EventCallback() {
1292 aurelien 1301
				@Override
681 aurelien 1302
				public void execute(EventObject e) {
1303
					if(e.getCharCode() == KEY_ENTER) {
1304
						rafraichirCommune(infosCom);
1305
					}
1858 raphael 1306
				}
681 aurelien 1307
			});
1858 raphael 1308
 
681 aurelien 1309
			Ext.get("lien_selection_commune").addListener("focus",new EventCallback() {
1292 aurelien 1310
				@Override
681 aurelien 1311
				public void execute(EventObject e) {
1312
					Ext.get("lien_selection_commune").toggleClass("lien_sel");
1858 raphael 1313
				}
681 aurelien 1314
			});
1858 raphael 1315
 
681 aurelien 1316
			Ext.get("lien_selection_commune").addListener("blur",new EventCallback() {
1292 aurelien 1317
				@Override
681 aurelien 1318
				public void execute(EventObject e) {
1319
					Ext.get("lien_selection_commune").toggleClass("lien_sel");
1858 raphael 1320
				}
681 aurelien 1321
			});
1858 raphael 1322
 
681 aurelien 1323
		} else {
1324
			if(rechercheCommuneEnCours) {
1325
				lienSelectionCommune.setHtml("<span id=\"aucune_selection_commune\"> Erreur de localisation </span>");
1326
			} else {
1327
				lienSelectionCommune.setHtml("<span id=\"aucune_selection_commune\"> </span>");
1328
			}
268 aurelien 1329
		}
248 aurelien 1330
 
268 aurelien 1331
		Ext.get(lienSelectionCommune.getElement()).unmask();
1332
		rechercheCommuneEnCours = false;
1333
	}
1858 raphael 1334
 
268 aurelien 1335
	private void rafraichirCommune(EntiteGeographiqueObservation infosCom) {
1336
		String nCommune = "";
1858 raphael 1337
 
962 aurelien 1338
		if(infosCom.getZoneGeo() != null && !infosCom.getZoneGeo().equals("")) {
1339
			nCommune += infosCom.getZoneGeo();
248 aurelien 1340
		}
1858 raphael 1341
 
962 aurelien 1342
		if(infosCom.getIdZoneGeo() != null && !infosCom.getIdZoneGeo().equals("")) {
1332 aurelien 1343
			String codeGeoFormate = Util.convertirChaineZoneGeoVersDepartement(infosCom.getIdZoneGeo());
962 aurelien 1344
			nCommune += " ("+codeGeoFormate+")";
1332 aurelien 1345
			departement = Util.convertirChaineZoneGeoVersDepartement(infosCom.getIdZoneGeo());
248 aurelien 1346
		}
2270 mathias 1347
		if (! nCommune.equals("")) {
1348
			commune.setValue(nCommune);
1349
			communeModifiee = true;
1350
		}
268 aurelien 1351
	}
248 aurelien 1352
 
2276 mathias 1353
	// Se déclenche au retour de la "localisation sur la carte"
268 aurelien 1354
	private void rafraichirCommuneEtCoord(EntiteGeographiqueObservation infosCom) {
2276 mathias 1355
 
2073 aurelien 1356
		rafraichirCommune(infosCom);
248 aurelien 1357
		if(infosCom.getLat() != null && !infosCom.getLat().equals("")) {
2276 mathias 1358
			latitude.setValue(Util.tronquerNombrePourAffichage("" + infosCom.getLat(), 5));
248 aurelien 1359
		}
1360
 
1361
		if(infosCom.getLon() != null && !infosCom.getLon().equals("")) {
2276 mathias 1362
			longitude.setValue(Util.tronquerNombrePourAffichage("" + infosCom.getLon(), 5));
248 aurelien 1363
		}
1858 raphael 1364
 
357 aurelien 1365
		latModifiee = true;
1366
		longModifiee = true;
1858 raphael 1367
 
264 aurelien 1368
		coordPanel.setVisible(true);
248 aurelien 1369
	}
1370
 
13 david 1371
	public void obtenirListeReferentielCommune() {
1858 raphael 1372
 
268 aurelien 1373
	 String com=commune.getText();
20 david 1374
	 com=com.replaceAll("%","");
1858 raphael 1375
 
20 david 1376
	 observationMediateur.obtenirListeReferentielCommune(this,com);
1858 raphael 1377
 
13 david 1378
	}
1858 raphael 1379
 
1380
	public void obtenirListeReferentielNom() {
1940 aurelien 1381
		String esp=espece.getText().replaceAll(" ","/*");
1382
		esp=esp.replaceAll("%","");
1383
		String referentiel = this.referentielTaxo;
1384
 
1385
		observationMediateur.obtenirListeReferentielNom(this,referentiel ,esp);
20 david 1386
	}
1858 raphael 1387
 
1388
	protected void obtenirReferentielStation() {
708 aurelien 1389
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_STATION,station.getText());
1390
	}
1858 raphael 1391
 
708 aurelien 1392
	protected void obtenirListeReferentielMilieu() {
1393
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_MILIEU,milieu.getText());
1394
	}
1395
 
1396
	protected void obtenirReferentielLieuDit() {
1397
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_LIEU_DIT,lieudit.getText());
1398
	}
1858 raphael 1399
 
39 david 1400
	public void ajouterObservation() {
1858 raphael 1401
 
1672 aurelien 1402
		if(date.getRawValue() != null && !date.getRawValue().equals("") && !Util.verifierDateFormatCel(date.getRawValue())) {
681 aurelien 1403
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1404
			date.setInvalidText("Date invalide");
1405
			return;
1406
		}
1858 raphael 1407
 
1542 aurelien 1408
		if(departement != null) {
389 david 1409
			if(departement.equals("000null") || departement.equals("")) {
1410
				String[] depCom = commune.getText().split(" ");
1411
				if(depCom.length > 1) {
1412
					String dep = depCom[1].replace('(', ' ');
1413
					dep =dep.replace(')', ' ');
1414
					dep = dep.trim();
1415
					dep = dep.replace('\\',' ');
1416
					dep = dep.trim();
1858 raphael 1417
 
389 david 1418
					try
1419
					{
1420
						int nDep = Integer.parseInt(dep);
1421
						if(nDep > 0 && nDep < 110) {
1422
							departement = dep ;
1423
						}
140 aurelien 1424
					}
389 david 1425
					catch(NumberFormatException e)
1426
					{
1427
						departement = "" ;
1428
					}
140 aurelien 1429
				}
1430
			}
1431
		}
1542 aurelien 1432
 
681 aurelien 1433
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
39 david 1434
 
1858 raphael 1435
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
1436
 
264 aurelien 1437
		String[] coords = getValeurCoordonnees();
971 aurelien 1438
		obs.setLatitude(coords[0]);
1439
		obs.setLongitude(coords[1]);
1572 aurelien 1440
		obs.setAltitude(altitude.getText());
1542 aurelien 1441
 
1488 aurelien 1442
		obs.setAbondance(getAbondance());
1443
		obs.setCertitude(getCertitude());
1542 aurelien 1444
		obs.setPhenologie(getPhenologie());
1858 raphael 1445
 
1542 aurelien 1446
		obs.setReferentielTaxo(Ontologies.getInfosReferentielNomParCode(referentielTaxo).getCodeVersionComplet());
1549 aurelien 1447
		obs.setChampsEtendus(getValeursChampsEtendus());
1858 raphael 1448
 
46 david 1449
		observationMediateur.ajouterObservation(obs);
39 david 1450
	}
1542 aurelien 1451
 
71 jpm 1452
	private void modifierObservation() {
1858 raphael 1453
 
1672 aurelien 1454
		if(!Window.confirm("Êtes-vous sur de vouloir modifier l'observation sélectionnée ?")) {
1455
			return;
1456
		}
1858 raphael 1457
 
1672 aurelien 1458
		if(date.getRawValue() != null && !date.getRawValue().equals("") && !Util.verifierDateFormatCel(date.getRawValue())) {
681 aurelien 1459
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1460
			date.setInvalidText("Date invalide");
1461
			return;
1462
		}
1858 raphael 1463
 
229 aurelien 1464
		if(departement.equals("000null") || departement.equals("")) {
1465
			String[] depCom = commune.getText().split(" ");
1466
			if(depCom.length > 1) {
1467
				String dep = depCom[1].replace('(', ' ');
1468
				dep =dep.replace(')', ' ');
1469
				dep = dep.trim();
1470
				dep = dep.replace('\\',' ');
1471
				dep = dep.trim();
1858 raphael 1472
 
229 aurelien 1473
				try
1474
				{
1475
					int nDep = Integer.parseInt(dep);
1476
					if(nDep > 0 && nDep < 110) {
1477
						departement = dep ;
1478
					}
1479
				}
1480
				catch(NumberFormatException e)
1481
				{
1482
					departement = "" ;
1483
				}
1484
			}
1485
		}
1858 raphael 1486
 
681 aurelien 1487
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
1858 raphael 1488
 
681 aurelien 1489
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
79 david 1490
		obs.setNumeroOrdre(numeroOrdre);
1858 raphael 1491
 
264 aurelien 1492
		String[] coords = getValeurCoordonnees();
1858 raphael 1493
 
971 aurelien 1494
		obs.setLatitude(coords[0]);
1495
		obs.setLongitude(coords[1]);
1572 aurelien 1496
		obs.setAltitude(altitude.getText());
1858 raphael 1497
 
1488 aurelien 1498
		obs.setAbondance(getAbondance());
1499
		obs.setCertitude(getCertitude());
1542 aurelien 1500
		obs.setPhenologie(getPhenologie());
1501
		obs.setReferentielTaxo(getReferentielTaxo());
1549 aurelien 1502
		obs.setChampsEtendus(getValeursChampsEtendus());
1858 raphael 1503
 
79 david 1504
		observationMediateur.modifierObservation(obs);
71 jpm 1505
	}
1858 raphael 1506
 
216 aurelien 1507
	private void modifierObservationEnMasse(Champs champModifie) {
1858 raphael 1508
 
1542 aurelien 1509
		//TODO: factoriser
216 aurelien 1510
		String communeM = null;
1511
		String departementM = null;
221 aurelien 1512
		String numNomSelM = null;
216 aurelien 1513
		String lieuDitM = null;
1514
		String stationM = null;
1515
		String milieuM = null;
1516
		String dateM = null;
1517
		String especeM = null;
1858 raphael 1518
		String commM = null;
264 aurelien 1519
		String latM = null;
1520
		String longM = null;
1572 aurelien 1521
		String altM = null;
1488 aurelien 1522
		String abondanceM = null;
1523
		String certitudeM = null;
1542 aurelien 1524
		String referentielTaxoM = null;
1525
		String phenologieM = null;
1858 raphael 1526
 
216 aurelien 1527
		String champs = modeleMessageModif;
1858 raphael 1528
 
1529
		if(communeModifiee && ! commune.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1530
			communeM = commune.getText();
1858 raphael 1531
 
221 aurelien 1532
			if(departement.equals("000null") || departement.equals("")) {
1533
				String[] depCom = commune.getText().split(" ");
1534
				if(depCom.length > 1) {
1535
					String dep = depCom[1].replace('(', ' ');
1536
					dep =dep.replace(')', ' ');
1537
					dep = dep.trim();
1538
					dep = dep.replace('\\',' ');
1539
					dep = dep.trim();
1858 raphael 1540
 
1541
					try {
221 aurelien 1542
						int nDep = Integer.parseInt(dep);
1543
						if(nDep > 0 && nDep < 110) {
1544
							departement = dep ;
1545
						}
1546
					}
1858 raphael 1547
					catch(NumberFormatException e) {
221 aurelien 1548
						departement = "" ;
1549
					}
1550
				}
1551
			}
1552
			departementM = departement;
1858 raphael 1553
		}
1554
		else {
221 aurelien 1555
			champs = champs.replaceAll("commune", "");
216 aurelien 1556
		}
1858 raphael 1557
 
1558
		if(lieuDitModifie && ! lieudit.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1559
			lieuDitM = lieudit.getText();
1858 raphael 1560
		} else {
221 aurelien 1561
			champs = champs.replaceAll(":lieu-dit", "");
216 aurelien 1562
		}
1858 raphael 1563
 
1564
		if(stationModifiee && ! station.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1565
			stationM = station.getText();
1858 raphael 1566
		} else {
221 aurelien 1567
			champs = champs.replaceAll(":station", "");
216 aurelien 1568
		}
1569
 
1858 raphael 1570
		if(milieuModifie && ! milieu.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1571
			milieuM = milieu.getText();
1858 raphael 1572
		} else {
221 aurelien 1573
			champs = champs.replaceAll(":milieu", "");
216 aurelien 1574
		}
1575
 
1858 raphael 1576
		if(dateModifiee && ! date.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1577
			dateM = date.getRawValue();
681 aurelien 1578
			dateM = Util.remplacerSeparateursDateFormatCel(dateM);
1858 raphael 1579
		} else {
221 aurelien 1580
			champs = champs.replaceAll(":date", "");
216 aurelien 1581
		}
1582
 
1858 raphael 1583
		if(especeModifiee && ! espece.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1584
			especeM = espece.getText();
221 aurelien 1585
			numNomSelM = numeroNom;
1858 raphael 1586
		} else {
221 aurelien 1587
			champs = champs.replaceAll(":espece", "");
216 aurelien 1588
		}
1589
 
1858 raphael 1590
		if(commModifie && ! comment.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1591
			commM = comment.getText();
1858 raphael 1592
		} else {
221 aurelien 1593
			champs = champs.replaceAll(":commentaire", "");
216 aurelien 1594
		}
1858 raphael 1595
 
1596
		if(latModifiee && ! latitude.getRawValue().equals(VALEURS_MULTIPLES)) {
264 aurelien 1597
			latM = latitude.getText();
1858 raphael 1598
		} else {
264 aurelien 1599
			champs = champs.replaceAll(":latitude", "");
1600
		}
1858 raphael 1601
 
1602
		if(altModifiee && ! altitude.getRawValue().equals(VALEURS_MULTIPLES)) {
1572 aurelien 1603
			altM = altitude.getText();
1858 raphael 1604
		} else {
1572 aurelien 1605
			champs = champs.replaceAll(":altitude", "");
1606
		}
1858 raphael 1607
 
1608
		if(longModifiee && ! longitude.getRawValue().equals(VALEURS_MULTIPLES)) {
264 aurelien 1609
			longM = longitude.getText();
1858 raphael 1610
		} else {
264 aurelien 1611
			champs = champs.replaceAll(":longitude", "");
1612
		}
1858 raphael 1613
 
1488 aurelien 1614
		if(abondanceModifiee && !selecteurAbondance.getRawValue().equals(VALEURS_MULTIPLES)) {
1615
			abondanceM = getAbondance();
1616
		} else {
1617
			champs = champs.replaceAll(":abondance", "");
1618
		}
1858 raphael 1619
 
1488 aurelien 1620
		if(certitudeModifiee && !selecteurCertitude.getRawValue().equals(VALEURS_MULTIPLES)) {
1621
			certitudeM = getCertitude();
1622
		} else {
1489 aurelien 1623
			champs = champs.replaceAll(":identification", "");
1488 aurelien 1624
		}
1858 raphael 1625
 
1542 aurelien 1626
		if(referentielTaxoModifie && !selecteurReferentielTaxo.getRawValue().equals(VALEURS_MULTIPLES)) {
1627
			referentielTaxoM = getReferentielTaxo();
1628
		} else {
1629
			champs = champs.replaceAll(":referentiel", "");
1630
		}
1858 raphael 1631
 
1542 aurelien 1632
		if(phenologieModifiee && !selecteurStadePheno.getRawValue().equals(VALEURS_MULTIPLES)) {
1633
			phenologieM = getPhenologie();
1634
		} else {
1635
			champs = champs.replaceAll(":phenologie", "");
1636
		}
1858 raphael 1637
 
221 aurelien 1638
		champs = champs.replaceAll(":",", ");
1639
		if(champs.startsWith(",")) {
1640
			champs = champs.replaceFirst(",", "");
1641
		}
1858 raphael 1642
 
221 aurelien 1643
		String message = "Voulez vous modifier le(s) champ(s) suivant(s) : "+champs+"   pour les observations selectionnées ?" ;
1858 raphael 1644
 
216 aurelien 1645
		if(champs.trim().equals("")) {
1646
			Window.alert("Aucun champ n'a été modifié");
1647
		} else {
221 aurelien 1648
			Observation obs = new Observation(especeM,numNomSelM,communeM,departementM,lieuDitM,stationM,milieuM, commM,dateM);
216 aurelien 1649
			obs.setNumeroOrdre(numeroOrdre);
971 aurelien 1650
			obs.setLatitude(latM);
1651
			obs.setLongitude(longM);
1572 aurelien 1652
			obs.setAltitude(altM);
1488 aurelien 1653
			obs.setAbondance(abondanceM);
1654
			obs.setCertitude(certitudeM);
1542 aurelien 1655
			obs.setReferentielTaxo(referentielTaxoM);
1656
			obs.setPhenologie(phenologieM);
216 aurelien 1657
			if(Window.confirm(message)) {
1658
				observationMediateur.modifierObservationEnMasse(obs);
221 aurelien 1659
				reinitialiserValeurModifiees();
216 aurelien 1660
			}
1661
		}
1662
	}
1858 raphael 1663
 
1664
	private void supprimerObservation() {
216 aurelien 1665
		observationMediateur.supprimerObservation(this, numeroOrdre);
77 jpm 1666
	}
1858 raphael 1667
 
71 jpm 1668
	public void afficherDetailsObservation(Observation obs)
1669
	{
104 jpm 1670
		raz() ;
216 aurelien 1671
		String idLoc ;
1672
		if(obs.getIdentifiantLocalite() != VALEURS_MULTIPLES) {
1332 aurelien 1673
			idLoc = obs.getIdentifiantLocalite().replaceAll(" ","/");
216 aurelien 1674
			idLoc = idLoc.replaceAll("%","");
1675
			idLoc = idLoc.replaceAll("\"","");
1676
			idLoc = idLoc.replace('\\',' ');
1677
			idLoc = idLoc.trim();
1332 aurelien 1678
			if(idLoc.length() == 5) {
1679
				idLoc = idLoc.substring(0,2);
1680
			}
216 aurelien 1681
		} else {
1682
			idLoc = obs.getIdentifiantLocalite();
1332 aurelien 1683
			if(idLoc.length() == 5) {
1684
				idLoc = idLoc.substring(0,2);
1685
			}
216 aurelien 1686
		}
1858 raphael 1687
 
221 aurelien 1688
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null") && !obs.getDate().equals(VALEURS_MULTIPLES)) {
71 jpm 1689
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 1690
			if(verifierFormatDate(dateEtHeure[0])) {
1691
				date.setValue(dateEtHeure[0]) ;
1692
			}
1693
			else
1694
			{
1858 raphael 1695
				date.setRawValue("");
110 aurelien 1696
			}
221 aurelien 1697
		} else {
1698
			date.setRawValue(VALEURS_MULTIPLES);
1699
			date.clearInvalid();
71 jpm 1700
		}
1701
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
1702
			lieudit.setValue(obs.getLieudit()) ;
1703
		}
1704
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
1705
			station.setValue(obs.getStation()) ;
1706
		}
1707
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
1708
			milieu.setValue(obs.getMilieu()) ;
1709
		}
1710
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
461 aurelien 1711
 
681 aurelien 1712
			comment.setRawValue(Util.remplacerSautsDeligneMalEncodes(obs.getCommentaire()));
1858 raphael 1713
 
71 jpm 1714
		}
1715
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
962 aurelien 1716
			if(!idLoc.equals("000null") && !idLoc.equals("")) {
221 aurelien 1717
				if(!idLoc.equals(VALEURS_MULTIPLES)) {
1718
					commune.setValue(obs.getLocalite()+" ("+idLoc+")") ;
1719
				} else {
1720
					commune.setValue(VALEURS_MULTIPLES);
1721
				}
140 aurelien 1722
			}
1723
			else
1724
			{
1725
				commune.setValue(obs.getLocalite());
1726
			}
71 jpm 1727
		}
1728
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
140 aurelien 1729
			departement = idLoc;
71 jpm 1730
		}
1731
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
1732
			espece.setValue(obs.getNomSaisi()) ;
1733
		}
1734
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
1735
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
1736
		}
1332 aurelien 1737
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000null")) {
74 david 1738
			numeroOrdre = obs.getNumeroOrdre() ;
1739
		}
1858 raphael 1740
 
1572 aurelien 1741
		if(doitAfficherLatLon(obs)) {
1742
			latitude.setValue(Util.formaterNombre(obs.getLatitude())) ;
1743
			longitude.setValue(Util.formaterNombre(obs.getLongitude())) ;
391 aurelien 1744
		}
1858 raphael 1745
 
1572 aurelien 1746
		if(!obs.getAltitude().isEmpty() && !obs.getAltitude().equals("null") && !obs.getAltitude().equals("000null")) {
1747
			altitude.setValue(Util.formaterNombre(obs.getAltitude())) ;
1748
		}
1858 raphael 1749
 
1488 aurelien 1750
		selecteurAbondance.getStore().load();
1751
		selecteurAbondance.setValue(obs.getAbondance());
1858 raphael 1752
 
1488 aurelien 1753
		selecteurCertitude.getStore().load();
1754
		selecteurCertitude.setValue(obs.getCertitude());
1858 raphael 1755
 
1542 aurelien 1756
		selecteurStadePheno.getStore().load();
1757
		selecteurStadePheno.setValue(obs.getPhenologie());
1858 raphael 1758
 
1542 aurelien 1759
		selecteurReferentielTaxo.getStore().load();
1760
		if(obs.getReferentielTaxo() != VALEURS_MULTIPLES) {
1761
			referentielTaxo = obs.getCodeCourtReferentielTaxo();
1559 aurelien 1762
			if(referentielTaxo == null || referentielTaxo.isEmpty()) {
1763
			    referentielTaxo = Configuration.getReferentielsDispos().get(0).getCode();
1764
			}
1542 aurelien 1765
			selecteurReferentielTaxo.setValue(referentielTaxo);
1766
		} else {
1767
			referentielTaxo = "";
1768
			selecteurReferentielTaxo.setRawValue(VALEURS_MULTIPLES);
1769
		}
1858 raphael 1770
 
1940 aurelien 1771
		afficherChampsEtendus(obs.getChampsEtendus(), null);
71 jpm 1772
	}
1858 raphael 1773
 
1572 aurelien 1774
	private boolean doitAfficherLatLon(Observation obs) {
1775
		return !obs.getLatitude().isEmpty() &&
1858 raphael 1776
				!obs.getLatitude().equals("null") &&
1572 aurelien 1777
				!obs.getLatitude().equals("000null") &&
1858 raphael 1778
				!Util.estZero(obs.getLatitude()) &&
1779
				!obs.getLongitude().isEmpty() &&
1780
				!obs.getLongitude().equals("null") &&
1572 aurelien 1781
				!obs.getLongitude().equals("000null") &&
1782
				!Util.estZero(obs.getLongitude());
1783
	}
1858 raphael 1784
 
1549 aurelien 1785
	private void viderChampsEtendus() {
1786
		if(listeChampsEtendus != null) {
1787
			for (Iterator<String> it = listeChampsEtendus.keySet().iterator(); it.hasNext();) {
1788
				TextField champEtendu = listeChampsEtendus.get(it.next());
1789
				champEtendu.destroy();
1790
			}
1597 aurelien 1791
			if(conteneurChampEtenduGauche != null && conteneurChampEtenduDroite != null) {
1792
				conteneurChampEtenduGauche.clear();
1793
				conteneurChampEtenduDroite.clear();
1794
				panneauPremierColonne.remove(conteneurChampEtenduGauche);
1795
				panneauSecondeColonne.remove(conteneurChampEtenduDroite);
1796
			}
1549 aurelien 1797
			listeChampsEtendus = null;
1798
		}
1799
	}
1858 raphael 1800
 
1940 aurelien 1801
	private void afficherChampsEtendus(Map<String, ChampEtendu> champsEtendus, ChampEtendu champsAFocus) {
2392 aurelien 1802
		champsEtendus = Util.trierListeChampsEtendus(champsEtendus);
1549 aurelien 1803
		viderChampsEtendus();
1858 raphael 1804
 
1810 aurelien 1805
		FormLayout flmd = new FormLayout();
1806
		flmd.setLabelWidth(150);
1858 raphael 1807
 
1810 aurelien 1808
		FormLayout flmg = new FormLayout();
1809
		flmg.setLabelWidth(150);
1858 raphael 1810
 
1810 aurelien 1811
		conteneurChampEtenduGauche = new Panel();
1812
		conteneurChampEtenduGauche.setLayout(flmg);
1813
		conteneurChampEtenduDroite = new Panel();
1814
		conteneurChampEtenduDroite.setLayout(flmd);
1858 raphael 1815
 
1810 aurelien 1816
		conteneurChampEtenduGauche.setAutoWidth(true);
1817
		conteneurChampEtenduGauche.setStyle("conteneurChampsEtendus");
1818
		conteneurChampEtenduGauche.setBodyBorder(false);
1819
		conteneurChampEtenduDroite.setAutoWidth(true);
1820
		conteneurChampEtenduDroite.setStyle("conteneurChampsEtendus");
1821
		conteneurChampEtenduDroite.setBodyBorder(false);
1858 raphael 1822
 
1810 aurelien 1823
		// pour corriger le décalage sur le panneau induit par le lien d'affichage
1940 aurelien 1824
		conteneurChampEtenduDroite.setPaddings(42, 0, 0, 0);
1858 raphael 1825
 
1940 aurelien 1826
		if(champsEtendus != null && champsEtendus.size() > 0) {
1597 aurelien 1827
			lienAfficherChampsEtendus.setVisible(true);
1940 aurelien 1828
			listeChampsEtendus = new HashMap<String, ChampSaisieEtendu>(champsEtendus.size());
2392 aurelien 1829
			HashMap<String, String> correspondancesClesLabel = ListeReferentielChampsEtendusDAO.cacheClesLabels;
1810 aurelien 1830
			boolean gauche = true;
1940 aurelien 1831
			for (Iterator<String> iterator = champsEtendus.keySet().iterator(); iterator.hasNext();) {
2392 aurelien 1832
 
1810 aurelien 1833
				String id = iterator.next();
1940 aurelien 1834
				ChampEtendu champ = champsEtendus.get(id);
2392 aurelien 1835
 
1810 aurelien 1836
				String valeur = champ.getValeur();
2392 aurelien 1837
				String label = id;
1838
 
1839
				// Si le champ possède un clé déjà définie par le catalogue, elle lui sera affectée
1840
				// sinon on la formate en la "déchamotant" et en ajoutant des espaces
1841
				if(correspondancesClesLabel.containsKey(id)) {
1842
					label = correspondancesClesLabel.get(id);
1843
				} else {
1844
					label = Util.formaterCleChampsEtenduPourAffichage(label);
1845
				}
1858 raphael 1846
 
1940 aurelien 1847
				ChampSaisieEtendu champTexteEtendu = new ChampSaisieEtendu(label, id);
1848
				if(champ.equals(champsAFocus)) {
1849
					champTexteEtendu.focus();
1850
				}
2392 aurelien 1851
 
1810 aurelien 1852
				champTexteEtendu.setId(id);
1853
				champTexteEtendu.setValue(valeur);
1854
				if(gauche) {
1855
					conteneurChampEtenduGauche.add(champTexteEtendu);
1856
				} else {
1857
					conteneurChampEtenduDroite.add(champTexteEtendu);
1549 aurelien 1858
				}
1810 aurelien 1859
				listeChampsEtendus.put(id, champTexteEtendu);
1860
				gauche = !gauche;
1861
			}
1858 raphael 1862
 
1597 aurelien 1863
			panneauPremierColonne.add(conteneurChampEtenduGauche);
1864
			panneauSecondeColonne.add(conteneurChampEtenduDroite);
1858 raphael 1865
 
1597 aurelien 1866
			if(!afficherChampsEtendus) {
1867
				conteneurChampEtenduGauche.setVisible(false);
1868
				conteneurChampEtenduDroite.setVisible(false);
1549 aurelien 1869
			}
1597 aurelien 1870
		} else {
1871
			lienAfficherChampsEtendus.setVisible(false);
1549 aurelien 1872
		}
1873
		doLayout();
1874
	}
1858 raphael 1875
 
1572 aurelien 1876
	private Map<String, ChampEtendu> getValeursChampsEtendus() {
1877
		Map<String, ChampEtendu> valeursChampsEtendus = new HashMap<String, ChampEtendu>();
1549 aurelien 1878
		if(listeChampsEtendus != null) {
1879
			for (Iterator<String> it = listeChampsEtendus.keySet().iterator(); it.hasNext();) {
1572 aurelien 1880
				String cle = it.next();
1881
				TextField champTexteEtendu = listeChampsEtendus.get(cle);
1882
				String label = champTexteEtendu.getFieldLabel();
1883
				String valeur = champTexteEtendu.getValueAsString();
1884
				ChampEtendu champEtendu = new ChampEtendu(cle, label, valeur);
1885
				valeursChampsEtendus.put(cle, champEtendu);
1549 aurelien 1886
			}
1887
		}
1888
		return valeursChampsEtendus;
1889
	}
1858 raphael 1890
 
104 jpm 1891
	public void raz()
71 jpm 1892
	{
118 david 1893
		raz(Champs.TOUT);
1858 raphael 1894
 
118 david 1895
	}
1896
	public void raz(Champs champs)
1897
	{
1898
		switch (champs) {
1899
			case DATE:
1900
				date.reset() ;
1901
				break;
1858 raphael 1902
 
118 david 1903
			case LIEUDIT:
1904
				lieudit.reset() ;
1905
				break;
1858 raphael 1906
 
118 david 1907
			case STATION:
1908
				station.reset() ;
1909
				break;
1858 raphael 1910
 
118 david 1911
			case MILIEU:
1912
				milieu.reset() ;
1913
				break;
1858 raphael 1914
 
118 david 1915
			case COMMENT:
1916
				comment.reset() ;
1917
				break;
1918
 
1919
			case COMMUNE:
172 aurelien 1920
				commune.reset() ;
118 david 1921
				departement ="";
268 aurelien 1922
				latitude.reset();
1923
				longitude.reset();
118 david 1924
				break;
1858 raphael 1925
 
118 david 1926
			case ESPECE:
1927
				espece.reset();
1928
				numeroNom = "" ;
1929
				numeroOrdre = "";
1930
				break;
1858 raphael 1931
 
264 aurelien 1932
			case LATITUDE:
1933
				latitude.reset();
268 aurelien 1934
				afficherIndicationCommune(null);
264 aurelien 1935
				break;
1858 raphael 1936
 
264 aurelien 1937
			case LONGITUDE:
1938
				longitude.reset();
268 aurelien 1939
				afficherIndicationCommune(null);
264 aurelien 1940
				break;
1858 raphael 1941
 
1572 aurelien 1942
			case ALTITUDE:
1943
				altitude.reset();
1944
				break;
1858 raphael 1945
 
1488 aurelien 1946
			case ABONDANCE:
1947
				selecteurAbondance.setValue("");
1948
				break;
1858 raphael 1949
 
1488 aurelien 1950
			case CERTITUDE:
1951
				selecteurCertitude.setValue("");
1952
				break;
1858 raphael 1953
 
1542 aurelien 1954
			case REFERENTIELTAXO:
1955
				selecteurReferentielTaxo.setValue("");
1956
				break;
1858 raphael 1957
 
1542 aurelien 1958
			case PHENOLOGIE:
1959
				selecteurStadePheno.setValue("");
1960
				break;
1858 raphael 1961
 
118 david 1962
			case TOUT:
132 aurelien 1963
				commune.reset();
118 david 1964
				date.reset() ;
1965
				lieudit.reset() ;
1966
				station.reset() ;
1967
				milieu.reset() ;
1968
				comment.reset() ;
1969
				milieu.reset() ;
248 aurelien 1970
				latitude.reset();
1971
				longitude.reset();
1572 aurelien 1972
				altitude.reset();
118 david 1973
				departement ="";
1974
				espece.reset();
1488 aurelien 1975
				selecteurAbondance.clearValue();
1976
				selecteurCertitude.clearValue();
1542 aurelien 1977
				selecteurReferentielTaxo.clearValue();
1978
				selecteurStadePheno.clearValue();
1979
				referentielTaxo = "";
118 david 1980
				numeroNom = "" ;
1981
				numeroOrdre = "";
268 aurelien 1982
				afficherIndicationCommune(null);
118 david 1983
				break;
1984
 
1985
		}
1858 raphael 1986
 
71 jpm 1987
	}
1858 raphael 1988
 
110 aurelien 1989
	public boolean verifierFormatDate(String date) {
1858 raphael 1990
 
132 aurelien 1991
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 1992
		if(date.matches(regex) && !date.equals("0000-00-00")) {
1993
			return true ;
1994
		}
1995
		else {
1996
			return false;
1997
		}
1998
	}
216 aurelien 1999
 
1641 aurelien 2000
	public void setSelectionMultiple(boolean selectionMultiple) {
2001
		this.selectionMultiple = selectionMultiple;
2002
		if(!selectionMultiple) {
2003
			boutonAnnuler.enable();
2004
			boutonOK.enable();
2005
		} else {
2006
			boutonAnnuler.disable();
2007
			boutonOK.disable();
216 aurelien 2008
		}
2009
	}
1858 raphael 2010
 
1641 aurelien 2011
	public boolean getSelectionMultiple() {
2012
		return selectionMultiple;
2013
	}
1858 raphael 2014
 
216 aurelien 2015
	private void calculerAfficherDifferences(ListeObservation listeObs) {
1858 raphael 2016
 
216 aurelien 2017
		String departement = null;
2018
		String commune = null;
2019
		String lieuDit = null;
2020
		String station = null;
2021
		String milieu = null;
2022
		String espece = null;
2023
		String date = null;
2024
		String notes = null;
264 aurelien 2025
		String lat = null;
2026
		String lon = null;
1572 aurelien 2027
		String alt = null;
1488 aurelien 2028
		String abondance = null;
2029
		String certitude = null;
1542 aurelien 2030
		String referentielTaxo = null;
2031
		String phenologie = null;
1858 raphael 2032
 
216 aurelien 2033
		String ordreObs = "";
1858 raphael 2034
 
216 aurelien 2035
		for(Iterator<String> it = listeObs.keySet().iterator();it.hasNext();) {
2036
			Observation obsEnCours = listeObs.get(it.next());
2037
			departement = comparerDifferencesChamps(departement, obsEnCours.getIdentifiantLocalite());
2038
			commune = comparerDifferencesChamps(commune, obsEnCours.getLocalite());
2039
			lieuDit = comparerDifferencesChamps(lieuDit, obsEnCours.getLieudit());
2040
			station = comparerDifferencesChamps(station, obsEnCours.getStation());
2041
			milieu = comparerDifferencesChamps(milieu, obsEnCours.getMilieu());
1858 raphael 2042
			espece = comparerDifferencesChamps(espece, obsEnCours.getNomSaisi());
216 aurelien 2043
			date = comparerDifferencesChamps(date, obsEnCours.getDate());
2044
			notes = comparerDifferencesChamps(notes, obsEnCours.getCommentaire());
962 aurelien 2045
			lat = comparerDifferencesChamps(lat, obsEnCours.getLatitude());
2046
			lon = comparerDifferencesChamps(lon, obsEnCours.getLongitude());
1572 aurelien 2047
			alt = comparerDifferencesChamps(alt, obsEnCours.getAltitude());
1488 aurelien 2048
			abondance = comparerDifferencesChamps(abondance, obsEnCours.getAbondance());
2049
			certitude = comparerDifferencesChamps(certitude, obsEnCours.getCertitude());
1542 aurelien 2050
			referentielTaxo = comparerDifferencesChamps(referentielTaxo, obsEnCours.getReferentielTaxo());
2051
			phenologie = comparerDifferencesChamps(phenologie, obsEnCours.getPhenologie());
1858 raphael 2052
 
216 aurelien 2053
			ordreObs += obsEnCours.getNumeroOrdre()+",";
2054
		}
1858 raphael 2055
 
216 aurelien 2056
		Observation obs=new Observation(espece,numeroNom,commune,departement,lieuDit,station,milieu, notes,date);
2057
		obs.setNumeroOrdre(ordreObs);
971 aurelien 2058
		obs.setLatitude(lat);
2059
		obs.setLongitude(lon);
1572 aurelien 2060
		obs.setAltitude(alt);
1488 aurelien 2061
		obs.setAbondance(abondance);
2062
		obs.setCertitude(certitude);
1542 aurelien 2063
		obs.setReferentielTaxo(referentielTaxo);
2064
		obs.setPhenologie(phenologie);
1858 raphael 2065
		afficherDetailsObservation(obs);
216 aurelien 2066
	}
1858 raphael 2067
 
216 aurelien 2068
	private String comparerDifferencesChamps(String valeurActuelle, String nouvelleValeur) {
1858 raphael 2069
 
2539 aurelien 2070
		String retour = "";
1858 raphael 2071
 
216 aurelien 2072
			if(valeurActuelle == null) {
2073
				retour = nouvelleValeur;
2074
			} else {
2075
				if(valeurActuelle.equals(nouvelleValeur)) {
2076
					retour = valeurActuelle;
2077
				} else {
2078
					retour = VALEURS_MULTIPLES;
2079
				}
2080
			}
2081
		return retour;
2082
	}
1858 raphael 2083
 
2084
	private void reinitialiserValeurModifiees() {
216 aurelien 2085
		communeModifiee = false;
221 aurelien 2086
		lieuDitModifie = false;
2087
		stationModifiee = false;
216 aurelien 2088
		milieuModifie = false;
2089
		dateModifiee = false;
2090
		especeModifiee = false;
2091
		commModifie = false;
264 aurelien 2092
		latModifiee = false;
2093
		longModifiee = false;
1572 aurelien 2094
		altModifiee = false;
1488 aurelien 2095
		abondanceModifiee = false;
2096
		certitudeModifiee = false;
1542 aurelien 2097
		referentielTaxoModifie = false;
2098
		phenologieModifiee = false;
216 aurelien 2099
	}
1858 raphael 2100
 
248 aurelien 2101
	public void saisieTabindex()
2102
	{
2103
		commune.setTabIndex(1);
268 aurelien 2104
		lieudit.setTabIndex(3);
2105
		station.setTabIndex(4);
2106
		milieu.setTabIndex(5);
248 aurelien 2107
		coordonnees.setTabIndex(-1);
2108
		coordonnees.addListener(new TextFieldListenerAdapter() {
2109
 
1292 aurelien 2110
			@Override
248 aurelien 2111
			public void onFocus(Field field) {
2112
				if(coordPanel.isVisible()) {
264 aurelien 2113
					latitude.focus();
248 aurelien 2114
				} else {
2115
					Ext.get("lien_carto").focus();
2116
				}
1858 raphael 2117
			}
248 aurelien 2118
		});
1858 raphael 2119
 
681 aurelien 2120
		latitude.setTabIndex(8);
2121
		longitude.setTabIndex(9);
1572 aurelien 2122
		altitude.setTabIndex(10);
2123
		comment.setTabIndex(11);
2124
		date.setTabIndex(12);
2125
		espece.setTabIndex(13);
2126
		selecteurCertitude.setTabIndex(14);
2127
		selecteurAbondance.setTabIndex(15);
2128
		selecteurStadePheno.setTabIndex(16);
2129
		boutonOK.setTabIndex(17);
2130
		boutonAnnuler.setTabIndex(18);
1858 raphael 2131
 
248 aurelien 2132
	}
1858 raphael 2133
 
248 aurelien 2134
	private void obtenirInformationCoord() {
2135
		if(coordonneesValides() != null) {
1958 aurelien 2136
			observationMediateur.obtenirInformationCoord(coordonneesValides()[0],coordonneesValides()[1]);
248 aurelien 2137
		} else {
681 aurelien 2138
			observationMediateur.afficherFenetreCarto();
248 aurelien 2139
		}
2140
	}
1858 raphael 2141
 
248 aurelien 2142
	private void obtenirInformationCommune() {
1542 aurelien 2143
		observationMediateur.obtenirInformationCommune(getCommuneSansDepartement(), Util.obtenirDepartementAPartirChaineCommune(departement, commune.getText()));
248 aurelien 2144
	}
1858 raphael 2145
 
391 aurelien 2146
	public double[] coordonneesValides() {
1858 raphael 2147
 
248 aurelien 2148
		try {
1858 raphael 2149
 
248 aurelien 2150
			double lat = Double.parseDouble(latitude.getValueAsString().replaceAll(",", "."));
2151
			double lon = Double.parseDouble(longitude.getValueAsString().replaceAll(",", "."));
1858 raphael 2152
 
248 aurelien 2153
			double[] coord = {lat, lon};
2154
			return coord;
1858 raphael 2155
 
248 aurelien 2156
		} catch (NumberFormatException ne) {
2157
			return null;
2158
		}
2159
	}
1858 raphael 2160
 
264 aurelien 2161
	private String[] getValeurCoordonnees() {
2162
		double[] coDouble = coordonneesValides();
1858 raphael 2163
 
264 aurelien 2164
		if(coDouble != null) {
2165
			String[] coord = {coDouble[0]+"",coDouble[1]+""};
2166
			return coord;
2167
		} else {
2539 aurelien 2168
			String[] coord = {"","" };
264 aurelien 2169
			return coord;
2170
		}
2171
	}
1858 raphael 2172
 
268 aurelien 2173
	public String getCommune() {
1858 raphael 2174
 
656 aurelien 2175
		String valeurCommune = "";
1858 raphael 2176
 
656 aurelien 2177
		if(commune.getValue() != null) {
1858 raphael 2178
			valeurCommune = commune.getValue();
656 aurelien 2179
		}
2180
		return valeurCommune;
268 aurelien 2181
	}
1858 raphael 2182
 
268 aurelien 2183
	public String getDepartement() {
1542 aurelien 2184
		return Util.obtenirDepartementAPartirChaineCommune(departement, commune.getText());
268 aurelien 2185
	}
1858 raphael 2186
 
656 aurelien 2187
	public String getCommuneSansDepartement() {
2188
		return Util.supprimerNumDepartementChaineLocalite(getCommune());
2189
	}
1858 raphael 2190
 
1542 aurelien 2191
	private String getValeurChampListeLibre(ComboBox champ) {
2192
		String valeurChamp = champ.getValue();
2193
		String valeurChampBrute = champ.getRawValue();
1858 raphael 2194
 
1488 aurelien 2195
		// Test idiot qui permet de savoir si l'on utilise la valeur saisie directement ou bien la valeur
1858 raphael 2196
		// selectionnee car lors du setValue sur le keypress, gwtext ne prends pas en compte le dernier
1488 aurelien 2197
		// caractère
1559 aurelien 2198
		if(valeurChampBrute.trim().length() == 0) {
2199
			valeurChamp = "";
2200
		} else {
2201
			if(valeurChamp != null && valeurChamp.length() > 0) {
2202
				if(valeurChamp.equals(valeurChampBrute.substring(0, valeurChampBrute.length() -1))) {
2203
					valeurChamp = champ.getRawValue();
2204
				}
1542 aurelien 2205
			}
1488 aurelien 2206
		}
1542 aurelien 2207
		return valeurChamp;
1488 aurelien 2208
	}
1542 aurelien 2209
 
2210
	public String getAbondance() {
2211
		return getValeurChampListeLibre(selecteurAbondance);
2212
	}
1858 raphael 2213
 
1488 aurelien 2214
	public String getCertitude() {
1542 aurelien 2215
		return getValeurChampListeLibre(selecteurCertitude);
1488 aurelien 2216
	}
1858 raphael 2217
 
1542 aurelien 2218
	public String getPhenologie() {
2219
		return getValeurChampListeLibre(selecteurStadePheno);
2220
	}
1858 raphael 2221
 
1542 aurelien 2222
	public String getReferentielTaxo() {
2223
		String codeCourt = getValeurChampListeLibre(selecteurReferentielTaxo);
2224
		return Ontologies.getInfosReferentielNomParCode(codeCourt).getCodeVersionComplet();
2225
	}
268 aurelien 2226
 
2227
	public boolean communeInitialisee() {
2228
		return communeModifiee;
2229
	}
1858 raphael 2230
 
318 aurelien 2231
	public void redimensionnerFormulaire() {
681 aurelien 2232
		afficherFormulaireLatLon.setWidth(panneauIntermediaire.getWidth()+"px");
2233
		panneauPremierColonne.doLayout();
2234
		panneauSecondeColonne.doLayout();
2235
		panneauIntermediaire.doLayout();
1858 raphael 2236
 
708 aurelien 2237
		doLayout();
318 aurelien 2238
	}
12 david 2239
}