Subversion Repositories eFlore/Applications.cel

Rev

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