Subversion Repositories eFlore/Applications.cel

Rev

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