Subversion Repositories eFlore/Applications.cel

Rev

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

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