Subversion Repositories eFlore/Applications.cel

Rev

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

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