Subversion Repositories eFlore/Applications.cel

Rev

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