Subversion Repositories eFlore/Applications.cel

Rev

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