Subversion Repositories eFlore/Applications.cel

Rev

Rev 104 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 104 Rev 107
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
 
3
 
4
 
4
 
5
import java.util.Iterator;
5
import java.util.Iterator;
6
 
6
 
7
import org.tela_botanica.client.interfaces.Rafraichissable;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.ListeReferentielCommune;
8
import org.tela_botanica.client.modeles.ListeReferentielCommune;
9
import org.tela_botanica.client.modeles.ListeReferentielNom;
9
import org.tela_botanica.client.modeles.ListeReferentielNom;
10
import org.tela_botanica.client.modeles.Observation;
10
import org.tela_botanica.client.modeles.Observation;
11
import org.tela_botanica.client.modeles.ReferentielCommune;
11
import org.tela_botanica.client.modeles.ReferentielCommune;
12
import org.tela_botanica.client.modeles.ReferentielNom;
12
import org.tela_botanica.client.modeles.ReferentielNom;
13
import org.tela_botanica.client.observation.ObservationMediateur;
13
import org.tela_botanica.client.observation.ObservationMediateur;
14
 
14
 
15
 
15
 
16
import com.google.gwt.user.client.Window;
16
import com.google.gwt.user.client.Window;
17
import com.gwtext.client.core.EventCallback;
17
import com.gwtext.client.core.EventCallback;
18
import com.gwtext.client.core.EventObject;
18
import com.gwtext.client.core.EventObject;
19
import com.gwtext.client.core.ListenerConfig;
19
import com.gwtext.client.core.ListenerConfig;
20
import com.gwtext.client.core.Position;
20
import com.gwtext.client.core.Position;
21
import com.gwtext.client.core.Template;
21
import com.gwtext.client.core.Template;
22
import com.gwtext.client.data.ArrayReader;
22
import com.gwtext.client.data.ArrayReader;
23
import com.gwtext.client.data.FieldDef;
23
import com.gwtext.client.data.FieldDef;
24
import com.gwtext.client.data.MemoryProxy;
24
import com.gwtext.client.data.MemoryProxy;
25
import com.gwtext.client.data.RecordDef;
25
import com.gwtext.client.data.RecordDef;
26
import com.gwtext.client.data.SimpleStore;
26
import com.gwtext.client.data.SimpleStore;
27
import com.gwtext.client.data.Store;
27
import com.gwtext.client.data.Store;
28
import com.gwtext.client.data.StringFieldDef;
28
import com.gwtext.client.data.StringFieldDef;
29
import com.gwtext.client.widgets.Button;
29
import com.gwtext.client.widgets.Button;
30
import com.gwtext.client.widgets.Panel;
30
import com.gwtext.client.widgets.Panel;
31
import com.gwtext.client.widgets.Toolbar;
31
import com.gwtext.client.widgets.Toolbar;
32
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
32
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
33
import com.gwtext.client.widgets.form.ComboBox;
33
import com.gwtext.client.widgets.form.ComboBox;
34
import com.gwtext.client.widgets.form.DateField;
34
import com.gwtext.client.widgets.form.DateField;
35
import com.gwtext.client.widgets.form.FormPanel;
35
import com.gwtext.client.widgets.form.FormPanel;
36
import com.gwtext.client.widgets.form.Hidden;
36
import com.gwtext.client.widgets.form.Hidden;
37
import com.gwtext.client.widgets.form.TextField;
37
import com.gwtext.client.widgets.form.TextField;
38
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
38
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
39
import com.gwtext.client.widgets.layout.ColumnLayout;
39
import com.gwtext.client.widgets.layout.ColumnLayout;
40
import com.gwtext.client.widgets.layout.ColumnLayoutData;
40
import com.gwtext.client.widgets.layout.ColumnLayoutData;
41
import com.gwtext.client.widgets.layout.FormLayout;
41
import com.gwtext.client.widgets.layout.FormLayout;
42
import com.gwtext.client.data.Record;
42
import com.gwtext.client.data.Record;
43
 
43
 
44
/**
44
/**
45
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
45
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
46
 * @author aurelien
46
 * @author aurelien
47
 *
47
 *
48
 */
48
 */
49
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
49
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
50
 
50
 
51
 
51
 
52
	/**
52
	/**
53
	 * Le médiateur associé à la vue
53
	 * Le médiateur associé à la vue
54
	 */
54
	 */
55
	private ObservationMediateur	observationMediateur		= null;
55
	private ObservationMediateur	observationMediateur		= null;
56
	
56
	
57
	
57
	
58
 
58
 
59
	private DateField date = null;
59
	private DateField date = null;
60
	private TextField lieudit = null;
60
	private TextField lieudit = null;
61
	private TextField station = null;
61
	private TextField station = null;
62
	private TextField milieu = null;
62
	private TextField milieu = null;
63
	private TextField comment = null;
63
	private TextField comment = null;
64
	private ComboBox  commune = null;
64
	private ComboBox  commune = null;
65
	private String departement = null;
65
	private String departement = null;
66
	private ComboBox  espece = null;
66
	private ComboBox  espece = null;
67
	private String numeroNom = null;
67
	private String numeroNom = null;
68
	private String numeroOrdre = null;
68
	private String numeroOrdre = null;
69
 
69
 
70
 
70
 
71
	private Button boutonOK = new Button("Créer");
71
	private Button boutonOK = new Button("Créer");
72
	private Button boutonAnnuler = new Button("Réinitialiser");
72
	private Button boutonAnnuler = new Button("Réinitialiser");
73
 
73
 
74
	private boolean selectionCommune=false;
74
	private boolean selectionCommune=false;
75
	private boolean selectionEspece=false;
75
	private boolean selectionEspece=false;
76
	
76
	
77
	private boolean modification = false ;
77
	private boolean modification = false ;
78
	private Toolbar bt = null ;
78
	private Toolbar bt = null ;
79
	
79
	
80
	private final int KEY_ALT = 18;
80
	private final int KEY_ALT = 18;
81
	private final int KEY_BACKSPACE = 8;
81
	private final int KEY_BACKSPACE = 8;
82
	private final int KEY_CTRL = 17;
82
	private final int KEY_CTRL = 17;
83
	private final int KEY_DELETE = 46;
83
	private final int KEY_DELETE = 46;
84
	private final int KEY_DOWN = 40;
84
	private final int KEY_DOWN = 40;
85
	private final int KEY_END = 35;
85
	private final int KEY_END = 35;
86
	private final int KEY_ENTER = 13;
86
	private final int KEY_ENTER = 13;
87
	private final int KEY_ESCAPE = 27;
87
	private final int KEY_ESCAPE = 27;
88
	private final int KEY_HOME = 36;
88
	private final int KEY_HOME = 36;
89
	private final int KEY_LEFT = 37;
89
	private final int KEY_LEFT = 37;
90
	private final int KEY_PAGEDOWN = 34;
90
	private final int KEY_PAGEDOWN = 34;
91
	private final int KEY_PAGEUP = 33;
91
	private final int KEY_PAGEUP = 33;
92
	private final int KEY_RIGHT = 39;
92
	private final int KEY_RIGHT = 39;
93
	private final int KEY_SHIFT = 16;
93
	private final int KEY_SHIFT = 16;
94
	private final int KEY_TAB = 9;
94
	private final int KEY_TAB = 9;
95
	private final int KEY_UP = 38;
95
	private final int KEY_UP = 38;
96
	
96
	
97
	/**
97
	/**
98
	 * Combobox permettant de selectionner le mode
98
	 * Combobox permettant de selectionner le mode
99
	 * modification ou bien création
99
	 * modification ou bien création
100
	 */
100
	 */
101
	private ComboBox selecteurMode = new ComboBox();
101
	private ComboBox selecteurMode = new ComboBox();
102
	
102
	
103
	Store storeMode = null ;
103
	Store storeMode = null ;
104
 
104
 
105
	/**
105
	/**
106
	 * Booleen d'instanciation
106
	 * Booleen d'instanciation
107
	 */
107
	 */
108
	boolean estInstancie = false ;
108
	boolean estInstancie = false ;
109
	
109
	
110
	/**
110
	/**
111
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
111
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
112
	 */
112
	 */
113
	@SuppressWarnings("unused")
113
	@SuppressWarnings("unused")
114
	private FormulaireSaisieObservationVue()
114
	private FormulaireSaisieObservationVue()
115
	{
115
	{
116
		super() ;
116
		super() ;
117
	}
117
	}
118
	
118
	
119
	/**
119
	/**
120
	 * Constructeur avec argument
120
	 * Constructeur avec argument
121
	 * @param im
121
	 * @param im
122
	 */
122
	 */
123
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
123
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
124
	{
124
	{
125
 
125
 
126
		
126
		
127
		// on associe le médiateur
127
		// on associe le médiateur
128
		observationMediateur = obs ;
128
		observationMediateur = obs ;
129
		
129
		
130
		
130
		
131
		setHeader(true);
131
		setHeader(true);
132
		
132
		
133
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
133
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
134
		panneauFormulaire.setBorder(false);
134
		panneauFormulaire.setBorder(false);
135
		
135
		
136
		// Panneau intermediaire qui contient deux colonnes de formulaire
136
		// Panneau intermediaire qui contient deux colonnes de formulaire
137
		
137
		
138
		Panel panneauIntermediaire = new Panel();  
138
		Panel panneauIntermediaire = new Panel();  
139
		panneauIntermediaire.setLayout(new ColumnLayout());  
139
		panneauIntermediaire.setLayout(new ColumnLayout());  
140
		panneauIntermediaire.setBorder(false);
140
		panneauIntermediaire.setBorder(false);
141
		   
141
		   
142
		//create first panel and add fields to it  
142
		//create first panel and add fields to it  
143
		Panel panneauPremierColonne = new Panel();  
143
		Panel panneauPremierColonne = new Panel();  
144
		panneauPremierColonne.setLayout(new FormLayout());  
144
		panneauPremierColonne.setLayout(new FormLayout());  
145
		panneauPremierColonne.setBorder(false);
145
		panneauPremierColonne.setBorder(false);
146
 
146
 
147
		//create second panel and add fields to it  
147
		//create second panel and add fields to it  
148
	    Panel panneauSecondeColonne = new Panel();  
148
	    Panel panneauSecondeColonne = new Panel();  
149
		panneauSecondeColonne.setLayout(new FormLayout());  
149
		panneauSecondeColonne.setLayout(new FormLayout());  
150
		panneauSecondeColonne.setBorder(false);
150
		panneauSecondeColonne.setBorder(false);
151
		
151
		
152
		this.setPaddings(5) ;
152
		this.setPaddings(5) ;
153
	
153
	
154
 
154
 
155
 
155
 
156
		commune=new ComboBox("Commune","commune",275 );  
156
		commune=new ComboBox("Commune","commune",275 );  
157
		
157
		
158
		
158
		
159
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";  
159
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";  
160
 
160
 
161
		
161
		
162
		commune.setTpl(resultTplCommune);
162
		commune.setTpl(resultTplCommune);
163
		commune.setMode(ComboBox.REMOTE);
163
		commune.setMode(ComboBox.REMOTE);
164
		// commune.setPageSize(10); // Ne fonctionne pas 
164
		// commune.setPageSize(10); // Ne fonctionne pas 
165
		commune.setItemSelector("div.search-item-commune");
165
		commune.setItemSelector("div.search-item-commune");
166
		commune.setTypeAhead(true);  
166
		commune.setTypeAhead(true);  
167
		commune.setLoadingText("Recherche...");  
167
		commune.setLoadingText("Recherche...");  
168
		  
168
		  
169
		commune.setHideTrigger(true);
169
		commune.setHideTrigger(true);
170
		
170
		
171
		
171
		
172
     
172
     
173
 
173
 
174
 
174
 
175
	    panneauPremierColonne.add(commune);  
175
	    panneauPremierColonne.add(commune);  
176
 
176
 
177
		
177
		
178
	    
178
	    
179
	    station = new TextField("Station", "station", 275);  
179
	    station = new TextField("Station", "station", 275);  
180
	    station.setAllowBlank(true);  
180
	    station.setAllowBlank(true);  
181
	    panneauPremierColonne.add(station);  
181
	    panneauPremierColonne.add(station);  
182
	    
182
	    
183
	    date = new DateField("Date", "date", 100);  
183
	    date = new DateField("Date", "date", 100);  
184
	    date.setAllowBlank(true);
184
	    date.setAllowBlank(true);
185
	    date.setFormat("d/m/Y") ;
185
	    date.setFormat("d/m/Y") ;
186
	    panneauPremierColonne.add(date);  
186
	    panneauPremierColonne.add(date);  
187
 
187
 
188
	 	
188
	 	
189
		espece=new ComboBox("Espèce","nom",275 );  
189
		espece=new ComboBox("Espèce","nom",275 );  
190
		
190
		
191
		
191
		
192
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";  
192
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";  
193
 
193
 
194
		
194
		
195
		espece.setTpl(resultTplEspece);
195
		espece.setTpl(resultTplEspece);
196
		espece.setMode(ComboBox.REMOTE);
196
		espece.setMode(ComboBox.REMOTE);
197
		// commune.setPageSize(10); // Ne fonctionne pas 
197
		// commune.setPageSize(10); // Ne fonctionne pas 
198
		espece.setItemSelector("div.search-item-espece");
198
		espece.setItemSelector("div.search-item-espece");
199
		espece.setTypeAhead(true);  
199
		espece.setTypeAhead(true);  
200
		espece.setLoadingText("Recherche...");  
200
		espece.setLoadingText("Recherche...");  
201
		  
201
		  
202
		espece.setHideTrigger(true);
202
		espece.setHideTrigger(true);
203
		
203
		
204
 
204
 
205
 
205
 
206
	    panneauPremierColonne.add(espece);  
206
	    panneauPremierColonne.add(espece);  
207
	    
207
	    
208
	    comment = new TextField("Notes", "comment", 275);  
208
	    comment = new TextField("Notes", "comment", 275);  
209
	    comment.setAllowBlank(true);  
209
	    comment.setAllowBlank(true);  
210
	    panneauPremierColonne.add(comment); 
210
	    panneauPremierColonne.add(comment); 
211
	    
211
	    
212
	    
212
	    
213
	    lieudit = new TextField("Lieu-dit", "lieudit", 275);  
213
	    lieudit = new TextField("Lieu-dit", "lieudit", 275);  
214
	    lieudit.setAllowBlank(true);  
214
	    lieudit.setAllowBlank(true);  
215
	    panneauSecondeColonne.add(lieudit);  
215
	    panneauSecondeColonne.add(lieudit);  
216
	       
216
	       
217
	
217
	
218
	    milieu = new TextField("Milieu", "milieu", 275);  
218
	    milieu = new TextField("Milieu", "milieu", 275);  
219
	    milieu.setAllowBlank(true);  
219
	    milieu.setAllowBlank(true);  
220
	    panneauSecondeColonne.add(milieu);  
220
	    panneauSecondeColonne.add(milieu);  
221
	   
221
	   
222
	 
222
	 
223
		
223
		
224
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
224
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
225
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
225
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
226
		
226
		
227
		panneauFormulaire.add(panneauIntermediaire);
227
		panneauFormulaire.add(panneauIntermediaire);
228
		
228
		
229
		Object[][] mode = {{"création",false} , {"modification", true} };
229
		Object[][] mode = {{"création",false} , {"modification", true} };
230
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
230
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
231
				mode);
231
				mode);
232
		storeMode.load();
232
		storeMode.load();
233
		selecteurMode.setStore(storeMode);
233
		selecteurMode.setStore(storeMode);
234
		selecteurMode.setDisplayField("nom_mode") ;
234
		selecteurMode.setDisplayField("nom_mode") ;
235
		selecteurMode.setLabel("mode ") ;
235
		selecteurMode.setLabel("mode ") ;
236
		selecteurMode.setForceSelection(true) ;
236
		selecteurMode.setForceSelection(true) ;
237
		selecteurMode.setValue("création") ;
237
		selecteurMode.setValue("création") ;
238
		selecteurMode.setEditable(false) ;
238
		selecteurMode.setEditable(false) ;
239
		selecteurMode.setCls("x-selec-crea") ;
239
		selecteurMode.setCls("x-selec-crea") ;
240
		
240
		
241
		bt = new Toolbar() ;
241
		bt = new Toolbar() ;
242
		bt.addSpacer() ;
242
		bt.addSpacer() ;
243
		bt.addText("Mode de saisie ") ;
243
		bt.addText("Mode de saisie ") ;
244
		bt.addField(selecteurMode) ;
244
		bt.addField(selecteurMode) ;
245
		
245
		
246
		
246
		
247
		
247
		
248
		
248
		
249
		panneauFormulaire.addButton(boutonOK);
249
		panneauFormulaire.addButton(boutonOK);
250
		    
250
		    
251
		panneauFormulaire.addButton(boutonAnnuler);
251
		panneauFormulaire.addButton(boutonAnnuler);
252
		
252
		
253
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
253
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
254
 
254
 
255
			public void onSelect(ComboBox comboBox, Record record, int index) {
255
			public void onSelect(ComboBox comboBox, Record record, int index) {
256
				
256
				
257
				// et on met la valeur à jour dans la combobox
257
				// et on met la valeur à jour dans la combobox
258
				comboBox.setValue(record.getAsString("nom_mode"));
258
				comboBox.setValue(record.getAsString("nom_mode"));
259
				setModification(record.getAsString("mode")) ;
259
				setModification(record.getAsString("mode")) ;
260
			}
260
			}
261
 
261
 
262
		});
262
		});
263
	
263
	
264
		this.add(panneauFormulaire) ;
264
		this.add(panneauFormulaire) ;
265
		this.setTopToolbar(bt) ;
265
		this.setTopToolbar(bt) ;
266
		
266
		
267
		
267
		
268
		this.setAutoHeight(true);
268
		this.setAutoHeight(true);
269
	
269
	
270
	
270
	
271
		// on ajoute les listeners
271
		// on ajoute les listeners
272
		ajouterListeners() ;
272
		ajouterListeners() ;
273
		
273
		
274
		
274
		
275
 
275
 
276
	}
276
	}
277
	
277
	
278
	private void ajouterListeners()
278
	private void ajouterListeners()
279
	{	
279
	{	
280
		// Listener completion communne 
280
		// Listener completion communne 
281
		
281
		
282
		   commune.addListener(new ComboBoxListenerAdapter() {  
282
		   commune.addListener(new ComboBoxListenerAdapter() {  
283
	             public void onSelect(ComboBox comboBox, Record record, int index) {  
283
	             public void onSelect(ComboBox comboBox, Record record, int index) {  
284
	                 commune.setValue(record.getAsString("commune"));
284
	                 commune.setValue(record.getAsString("commune"));
285
	                 departement=record.getAsString("departement");
285
	                 departement=record.getAsString("departement");
286
	                 selectionCommune=true;
286
	                 selectionCommune=true;
287
	             }  
287
	             }  
288
	         });  
288
	         });  
289
	         
289
	         
290
	        
290
	        
291
			ListenerConfig listenerConfigCommune=new ListenerConfig();
291
			ListenerConfig listenerConfigCommune=new ListenerConfig();
292
			listenerConfigCommune.setDelay(10);
292
			listenerConfigCommune.setDelay(10);
293
			listenerConfigCommune.setStopPropagation(false);
293
			listenerConfigCommune.setStopPropagation(false);
294
			listenerConfigCommune.setStopEvent(false);
294
			listenerConfigCommune.setStopEvent(false);
295
			
295
			
296
 
296
 
297
		
297
		
298
		    commune.addKeyPressListener(new EventCallback()	{
298
		    commune.addKeyPressListener(new EventCallback()	{
299
		    	
299
		    	
300
		    	    public void execute(EventObject e) {
300
		    	    public void execute(EventObject e) {
301
		    	    	
301
		    	    	
302
		    	    		  
302
		    	    		  
303
		    	    		  switch(e.getKey()) {
303
		    	    		  switch(e.getKey()) {
304
		    	    	      	    		  
304
		    	    	      	    		  
305
		    	    		  
305
		    	    		  
306
		    	    		  case KEY_ALT:
306
		    	    		  case KEY_ALT:
307
		    	    	      case KEY_CTRL:
307
		    	    	      case KEY_CTRL:
308
		    	    	      case KEY_DOWN:
308
		    	    	      case KEY_DOWN:
309
		    	    	      case KEY_END:
309
		    	    	      case KEY_END:
310
		    	    	      case KEY_ESCAPE:
310
		    	    	      case KEY_ESCAPE:
311
		    	    	      case KEY_HOME:
311
		    	    	      case KEY_HOME:
312
		    	    	      case KEY_LEFT:
312
		    	    	      case KEY_LEFT:
313
		    	    	      case KEY_PAGEDOWN:
313
		    	    	      case KEY_PAGEDOWN:
314
		    	    	      case KEY_PAGEUP:
314
		    	    	      case KEY_PAGEUP:
315
		    	    	      case KEY_RIGHT:
315
		    	    	      case KEY_RIGHT:
316
		    	    	      case KEY_SHIFT:
316
		    	    	      case KEY_SHIFT:
317
		    	    	      case KEY_TAB:
317
		    	    	      case KEY_TAB:
318
		    	    	      case KEY_UP:
318
		    	    	      case KEY_UP:
319
		    	    	    	
319
		    	    	    	
320
		    	    	        break;
320
		    	    	        break;
321
		    	    	      
321
		    	    	      
322
		    	    	      case KEY_ENTER:
322
		    	    	      case KEY_ENTER:
323
		    	    	    	  
323
		    	    	    	  
324
		    	    	    	 if (selectionCommune) {
324
		    	    	    	 if (selectionCommune) {
325
		    	    	    		 selectionCommune=false;
325
		    	    	    		 selectionCommune=false;
326
		    	    	    	 }
326
		    	    	    	 }
327
		    	    	    	 else {
327
		    	    	    	 else {
328
		    	    	    		// lancer mise a jour 	    	    	    		 
328
		    	    	    		// lancer mise a jour 	    	    	    		 
329
		    	    	    	 }
329
		    	    	    	 }
330
		    	    	    	
330
		    	    	    	
331
		    	    	    	
331
		    	    	    	
332
		    	    	    	  break;
332
		    	    	    	  break;
333
		    	    	       
333
		    	    	       
334
		    	    	      default:
334
		    	    	      default:
335
		    	    	    	  
335
		    	    	    	  
336
		    	    	    	  departement="";
336
		    	    	    	  departement="";
337
		    	    	    	  obtenirListeReferentielCommune();
337
		    	    	    	  obtenirListeReferentielCommune();
338
		    	    	    	  	    	    	        
338
		    	    	    	  	    	    	        
339
		    	    	        break;
339
		    	    	        break;
340
		    	    	    }
340
		    	    	    }
341
 
341
 
342
		    	    	 
342
		    	    	 
343
		    	    	
343
		    	    	
344
		     		}
344
		     		}
345
		    	 
345
		    	 
346
		    		},    listenerConfigCommune
346
		    		},    listenerConfigCommune
347
		    	
347
		    	
348
			);
348
			);
349
		    
349
		    
350
			// Listener completion espece 
350
			// Listener completion espece 
351
 
351
 
352
			
352
			
353
			espece.addListener(new ComboBoxListenerAdapter() {  
353
			espece.addListener(new ComboBoxListenerAdapter() {  
354
	             public void onSelect(ComboBox comboBox, Record record, int index) {  
354
	             public void onSelect(ComboBox comboBox, Record record, int index) {  
355
	            	 espece.setValue(record.getAsString("nom"));
355
	            	 espece.setValue(record.getAsString("nom"));
356
	            	 numeroNom=record.getAsString("numeroNom");
356
	            	 numeroNom=record.getAsString("numeroNom");
357
	                 selectionEspece=true;
357
	                 selectionEspece=true;
358
	             }  
358
	             }  
359
	         });  
359
	         });  
360
	         
360
	         
361
 
361
 
362
			ListenerConfig listenerConfigEspece=new ListenerConfig();
362
			ListenerConfig listenerConfigEspece=new ListenerConfig();
363
			listenerConfigEspece.setDelay(10);
363
			listenerConfigEspece.setDelay(10);
364
			listenerConfigEspece.setStopPropagation(false);
364
			listenerConfigEspece.setStopPropagation(false);
365
			listenerConfigEspece.setStopEvent(false);			
365
			listenerConfigEspece.setStopEvent(false);			
366
 
366
 
367
		
367
		
368
			espece.addKeyPressListener(new EventCallback()	{
368
			espece.addKeyPressListener(new EventCallback()	{
369
		    	
369
		    	
370
		    	    public void execute(EventObject e) {
370
		    	    public void execute(EventObject e) {
371
		    	    	
371
		    	    	
372
		    	    		  
372
		    	    		  
373
		    	    		  switch(e.getKey()) {
373
		    	    		  switch(e.getKey()) {
374
		    	    	      	    		  
374
		    	    	      	    		  
375
		    	    		  
375
		    	    		  
376
		    	    		  case KEY_ALT:
376
		    	    		  case KEY_ALT:
377
		    	    	      case KEY_CTRL:
377
		    	    	      case KEY_CTRL:
378
		    	    	      case KEY_DOWN:
378
		    	    	      case KEY_DOWN:
379
		    	    	      case KEY_END:
379
		    	    	      case KEY_END:
380
		    	    	      case KEY_ESCAPE:
380
		    	    	      case KEY_ESCAPE:
381
		    	    	      case KEY_HOME:
381
		    	    	      case KEY_HOME:
382
		    	    	      case KEY_LEFT:
382
		    	    	      case KEY_LEFT:
383
		    	    	      case KEY_PAGEDOWN:
383
		    	    	      case KEY_PAGEDOWN:
384
		    	    	      case KEY_PAGEUP:
384
		    	    	      case KEY_PAGEUP:
385
		    	    	      case KEY_RIGHT:
385
		    	    	      case KEY_RIGHT:
386
		    	    	      case KEY_SHIFT:
386
		    	    	      case KEY_SHIFT:
387
		    	    	      case KEY_TAB:
387
		    	    	      case KEY_TAB:
388
		    	    	      case KEY_UP:
388
		    	    	      case KEY_UP:
389
		    	    	    	
389
		    	    	    	
390
		    	    	        break;
390
		    	    	        break;
391
		    	    	      
391
		    	    	      
392
		    	    	      case KEY_ENTER:
392
		    	    	      case KEY_ENTER:
393
		    	    	    	  
393
		    	    	    	  
394
		    	    	    	 if (selectionEspece) {
394
		    	    	    	 if (selectionEspece) {
395
		    	    	    		 selectionEspece=false;
395
		    	    	    		 selectionEspece=false;
396
		    	    	    	 }
396
		    	    	    	 }
397
		    	    	    	 else {
397
		    	    	    	 else {
398
		    	    	    		// lancer mise a jour 	    	    	    		 
398
		    	    	    		// lancer mise a jour 	    	    	    		 
399
		    	    	    	 }
399
		    	    	    	 }
400
		    	    	    	
400
		    	    	    	
401
		    	    	    	
401
		    	    	    	
402
		    	    	    	  break;
402
		    	    	    	  break;
403
		    	    	       
403
		    	    	       
404
		    	    	      default:
404
		    	    	      default:
405
		    	    	    	  
405
		    	    	    	  
406
		    	    	    	  numeroNom="";
406
		    	    	    	  numeroNom="";
407
		    	    	    	  obtenirListeReferentielNom();
407
		    	    	    	  obtenirListeReferentielNom();
408
		    	    	    	  	    	    	        
408
		    	    	    	  	    	    	        
409
		    	    	        break;
409
		    	    	        break;
410
		    	    	    }
410
		    	    	    }
411
 
411
 
412
		    	    	 
412
		    	    	 
413
		    	    	
413
		    	    	
414
		     		}
414
		     		}
415
		    	 
415
		    	 
416
		    		},    listenerConfigEspece
416
		    		},    listenerConfigEspece
417
		    	
417
		    	
418
			);
418
			);
419
		    
419
		    
420
 
420
 
421
		  
421
		  
422
 
422
 
423
		boutonOK.addListener(new ButtonListenerAdapter() {
423
		boutonOK.addListener(new ButtonListenerAdapter() {
424
			
424
			
425
			public void onClick(Button button, EventObject e) {
425
			public void onClick(Button button, EventObject e) {
426
				
426
				
427
				if(modification)
427
				if(modification)
428
				{
428
				{
429
					modifierObservation() ;
429
					modifierObservation() ;
430
				}
430
				}
431
				else
431
				else
432
				{
432
				{
433
					ajouterObservation();
433
					ajouterObservation();
434
				}
434
				}
435
				
435
				
436
				
436
				
437
			}
437
			}
438
			
438
			
439
		});
439
		});
440
		
440
		
441
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
441
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
442
			
442
			
443
			public void onClick(Button button, EventObject e) {
443
			public void onClick(Button button, EventObject e) {
444
				
444
				
445
				if(modification)
445
				if(modification)
446
				{
446
				{
447
					supprimerObservation() ;
447
					supprimerObservation() ;
448
				}
448
				}
449
				else
449
				else
450
				{
450
				{
451
					raz();
451
					raz();
452
				}
452
				}
453
				
453
				
454
				
454
				
455
			}
455
			}
456
			
456
			
457
		});
457
		});
458
	
458
	
459
	
459
	
460
	}
460
	}
461
	
461
	
462
	/**
462
	/**
463
	 * Desactive visuellement ce panneau
463
	 * Desactive visuellement ce panneau
464
	 */
464
	 */
465
	public void desactiverPanneau()
465
	public void desactiverPanneau()
466
	{
466
	{
467
		this.setDisabled(true) ;
467
		this.setDisabled(true) ;
468
	}
468
	}
469
	
469
	
470
	/**
470
	/**
471
	 * Active visuellement ce panneau
471
	 * Active visuellement ce panneau
472
	 */
472
	 */
473
	public void activerPanneau()
473
	public void activerPanneau()
474
	{
474
	{
475
		this.setDisabled(false) ;
475
		this.setDisabled(false) ;
476
	}
476
	}
477
 
477
 
478
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
478
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
479
		
479
		
480
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
480
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
481
			if(nouvelleDonnees instanceof ListeReferentielCommune)
481
			if(nouvelleDonnees instanceof ListeReferentielCommune)
482
			{
482
			{
483
				
483
				
484
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
484
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
485
					Object[][] communeData = new Object[data.size()][2];
485
					Object[][] communeData = new Object[data.size()][2];
486
					int i = 0 ;
486
					int i = 0 ;
487
				
487
				
488
					// on la parse et on récupère les informations quiç nous interessent
488
					// on la parse et on récupère les informations quiç nous interessent
489
					for (Iterator it = data.keySet().iterator(); it.hasNext();) 
489
					for (Iterator it = data.keySet().iterator(); it.hasNext();) 
490
					{
490
					{
491
						
491
						
492
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
492
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
493
						
493
						
494
						communeData[i][0]= ref.getCommune();
494
						communeData[i][0]= ref.getCommune();
495
						communeData[i][1]= ref.getDepartement();
495
						communeData[i][1]= ref.getDepartement();
496
						
496
						
497
																	
497
																	
498
						i++ ;
498
						i++ ;
499
					}
499
					}
500
					
500
					
501
					   //	  creation du store
501
					   //	  creation du store
502
					FieldDef defCommune = new StringFieldDef("commune");
502
					FieldDef defCommune = new StringFieldDef("commune");
503
					FieldDef defDepartement = new StringFieldDef("departement");
503
					FieldDef defDepartement = new StringFieldDef("departement");
504
					
504
					
505
					
505
					
506
					FieldDef[] defTab = { defCommune, defDepartement};
506
					FieldDef[] defTab = { defCommune, defDepartement};
507
					
507
					
508
					RecordDef rd = new RecordDef(defTab);
508
					RecordDef rd = new RecordDef(defTab);
509
					
509
					
510
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
510
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
511
					final ArrayReader reader = new ArrayReader(rd);		
511
					final ArrayReader reader = new ArrayReader(rd);		
512
					
512
					
513
					Store store=new Store(dataProxy,reader);
513
					Store store=new Store(dataProxy,reader);
514
					store.load() ;
514
					store.load() ;
515
		
515
		
516
					commune.setStore(store);					
516
					commune.setStore(store);					
517
							
517
							
518
			}
518
			}
519
			
519
			
520
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
520
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
521
			
521
			
522
			if(nouvelleDonnees instanceof ListeReferentielNom)
522
			if(nouvelleDonnees instanceof ListeReferentielNom)
523
			{
523
			{
524
				
524
				
525
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
525
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
526
					Object[][] nomData = new Object[data.size()][2];
526
					Object[][] nomData = new Object[data.size()][2];
527
					int i = 0 ;
527
					int i = 0 ;
528
				
528
				
529
					// on la parse et on récupère les informations quiç nous interessent
529
					// on la parse et on récupère les informations quiç nous interessent
530
					for (Iterator it = data.keySet().iterator(); it.hasNext();) 
530
					for (Iterator it = data.keySet().iterator(); it.hasNext();) 
531
					{
531
					{
532
						
532
						
533
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
533
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
534
						
534
						
535
						nomData[i][0]= ref.getNom();
535
						nomData[i][0]= ref.getNom();
536
						nomData[i][1]= ref.getNumeroNom();
536
						nomData[i][1]= ref.getNumeroNom();
537
						
537
						
538
																	
538
																	
539
						i++ ;
539
						i++ ;
540
					}
540
					}
541
					
541
					
542
					   //	  creation du store
542
					   //	  creation du store
543
					FieldDef defNom = new StringFieldDef("nom");
543
					FieldDef defNom = new StringFieldDef("nom");
544
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
544
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
545
					
545
					
546
					
546
					
547
					FieldDef[] defTab = { defNom, defNumeroNom};
547
					FieldDef[] defTab = { defNom, defNumeroNom};
548
					
548
					
549
					RecordDef rd = new RecordDef(defTab);
549
					RecordDef rd = new RecordDef(defTab);
550
					
550
					
551
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
551
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
552
					final ArrayReader reader = new ArrayReader(rd);		
552
					final ArrayReader reader = new ArrayReader(rd);		
553
					
553
					
554
					Store store=new Store(dataProxy,reader);
554
					Store store=new Store(dataProxy,reader);
555
					store.load() ;
555
					store.load() ;
556
		
556
		
557
					espece.setStore(store);
557
					espece.setStore(store);
558
				
558
				
559
					
559
					
560
							
560
							
561
			}
561
			}
562
			
562
			
563
			// On recoit une observation dont on veut afficher le detail 
563
			// On recoit une observation dont on veut afficher le detail 
564
			
564
			
565
			if(nouvelleDonnees instanceof Observation)
565
			if(nouvelleDonnees instanceof Observation)
566
			{
566
			{
567
				Observation obs = (Observation)nouvelleDonnees ;
567
				Observation obs = (Observation)nouvelleDonnees ;
568
				afficherDetailsObservation(obs) ;
568
				afficherDetailsObservation(obs) ;
569
			}
569
			}
570
			
570
			
571
			// Sur Mise à jour ou suppression d'une suppression ?
571
			// Sur Mise à jour ou suppression d'une suppression ?
572
			
572
			
573
			if(nouvelleDonnees instanceof String)
573
			if(nouvelleDonnees instanceof String)
574
			{
574
			{
575
				String str = (String)nouvelleDonnees ;
575
				String str = (String)nouvelleDonnees ;
576
				observationMediateur.obtenirListeObservation() ;
576
				observationMediateur.obtenirNombreObservation() ;
577
			}
577
			}
578
 
578
 
579
	}
579
	}
580
	
580
	
581
 
581
 
582
	public void obtenirListeReferentielCommune() {
582
	public void obtenirListeReferentielCommune() {
583
		
583
		
584
	 String com=commune.getText().replaceAll(" ","/");
584
	 String com=commune.getText().replaceAll(" ","/");
585
	 com=com.replaceAll("%","");
585
	 com=com.replaceAll("%","");
586
		  
586
		  
587
	 observationMediateur.obtenirListeReferentielCommune(this,com);
587
	 observationMediateur.obtenirListeReferentielCommune(this,com);
588
	 
588
	 
589
	}
589
	}
590
	
590
	
591
 
591
 
592
	public void obtenirListeReferentielNom() {
592
	public void obtenirListeReferentielNom() {
593
	 
593
	 
594
	  String esp=espece.getText().replaceAll(" ","/");
594
	  String esp=espece.getText().replaceAll(" ","/");
595
	  esp=esp.replaceAll("%","");
595
	  esp=esp.replaceAll("%","");
596
		
596
		
597
	  observationMediateur.obtenirListeReferentielNom(this,esp);
597
	  observationMediateur.obtenirListeReferentielNom(this,esp);
598
	 
598
	 
599
	}
599
	}
600
   
600
   
601
 
601
 
602
	public void ajouterObservation() {
602
	public void ajouterObservation() {
603
 
603
 
604
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());	
604
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());	
605
		observationMediateur.ajouterObservation(obs);
605
		observationMediateur.ajouterObservation(obs);
606
	}
606
	}
607
	
607
	
608
	private void modifierObservation() {
608
	private void modifierObservation() {
609
		
609
		
610
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getText());
610
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getText());
611
		obs.setNumeroOrdre(numeroOrdre);
611
		obs.setNumeroOrdre(numeroOrdre);
612
		observationMediateur.modifierObservation(obs);
612
		observationMediateur.modifierObservation(obs);
613
		
613
		
614
	}
614
	}
615
	
615
	
616
	private void supprimerObservation() {
616
	private void supprimerObservation() {
617
		
617
		
618
			observationMediateur.supprimerObservation(this, numeroOrdre);
618
			observationMediateur.supprimerObservation(this, numeroOrdre);
619
	}
619
	}
620
 
620
 
621
	
621
	
622
	public void afficherDetailsObservation(Observation obs)
622
	public void afficherDetailsObservation(Observation obs)
623
	{
623
	{
624
		raz() ;
624
		raz() ;
625
		
625
		
626
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null")) {
626
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null")) {
627
			String[] dateEtHeure = obs.getDate().split(" ", 2);
627
			String[] dateEtHeure = obs.getDate().split(" ", 2);
628
			date.setValue(dateEtHeure[0]) ;
628
			date.setValue(dateEtHeure[0]) ;
629
		}
629
		}
630
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
630
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
631
			lieudit.setValue(obs.getLieudit()) ;
631
			lieudit.setValue(obs.getLieudit()) ;
632
		}
632
		}
633
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
633
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
634
			station.setValue(obs.getStation()) ;
634
			station.setValue(obs.getStation()) ;
635
		}
635
		}
636
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
636
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
637
			milieu.setValue(obs.getMilieu()) ;
637
			milieu.setValue(obs.getMilieu()) ;
638
		}
638
		}
639
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
639
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
640
			comment.setValue(obs.getCommentaire()) ;
640
			comment.setValue(obs.getCommentaire()) ;
641
		}
641
		}
642
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
642
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
643
			commune.setValue(obs.getLocalite()) ;
643
			commune.setValue(obs.getLocalite()) ;
644
		}
644
		}
645
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
645
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
646
			departement = obs.getIdentifiantLocalite();
646
			departement = obs.getIdentifiantLocalite();
647
		}
647
		}
648
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
648
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
649
			espece.setValue(obs.getNomSaisi()) ;
649
			espece.setValue(obs.getNomSaisi()) ;
650
		}
650
		}
651
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
651
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
652
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
652
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
653
		}
653
		}
654
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
654
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
655
			numeroOrdre = obs.getNumeroOrdre() ;
655
			numeroOrdre = obs.getNumeroOrdre() ;
656
		}
656
		}
657
		
657
		
658
	}
658
	}
659
	
659
	
660
	public void raz()
660
	public void raz()
661
	{
661
	{
662
 
662
 
663
		date.reset() ;
663
		date.reset() ;
664
		lieudit.reset() ;
664
		lieudit.reset() ;
665
		station.reset() ;
665
		station.reset() ;
666
		milieu.reset();
666
		milieu.reset();
667
		comment.reset();
667
		comment.reset();
668
		commune.reset();
668
		commune.reset();
669
		departement = "";
669
		departement = "";
670
		espece.reset();
670
		espece.reset();
671
		numeroNom = "" ;
671
		numeroNom = "" ;
672
		numeroOrdre = "";
672
		numeroOrdre = "";
673
		
673
		
674
	}
674
	}
675
	
675
	
676
	private void setModification(String mode)
676
	private void setModification(String mode)
677
	{
677
	{
678
		if(mode.equals("true")) {
678
		if(mode.equals("true")) {
679
 
679
 
680
			boutonOK.setText("Modifier") ;
680
			boutonOK.setText("Modifier") ;
681
			setTitle("Modification") ;
681
			setTitle("Modification") ;
682
			boutonAnnuler.setText("Supprimer") ;
682
			boutonAnnuler.setText("Supprimer") ;
683
			modification = true ;
683
			modification = true ;
684
			selecteurMode.removeClass("x-selec-crea") ;
684
			selecteurMode.removeClass("x-selec-crea") ;
685
			selecteurMode.setCls("x-selec-modif") ;
685
			selecteurMode.setCls("x-selec-modif") ;
686
			
686
			
687
		}
687
		}
688
		else
688
		else
689
		{
689
		{
690
 
690
 
691
			boutonOK.setText("Créer") ;
691
			boutonOK.setText("Créer") ;
692
			setTitle("Saisir") ;
692
			setTitle("Saisir") ;
693
			boutonAnnuler.setText("Réinitialiser") ;
693
			boutonAnnuler.setText("Réinitialiser") ;
694
			modification = false ;
694
			modification = false ;
695
			selecteurMode.removeClass("x-selec-modif") ;
695
			selecteurMode.removeClass("x-selec-modif") ;
696
			selecteurMode.setCls("x-selec-crea") ;
696
			selecteurMode.setCls("x-selec-crea") ;
697
			
697
			
698
		}
698
		}
699
		
699
		
700
	}
700
	}
701
	
701
	
702
	
702
	
703
	/**
703
	/**
704
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
704
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
705
	 * @return
705
	 * @return
706
	 */
706
	 */
707
	public boolean getModification()
707
	public boolean getModification()
708
	{
708
	{
709
		return modification ;
709
		return modification ;
710
	}
710
	}
711
 
711
 
712
}
712
}