Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
12 david 1
package org.tela_botanica.client.vues;
2
 
3
 
4
 
13 david 5
import java.util.Iterator;
6
 
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.ListeReferentielCommune;
9
import org.tela_botanica.client.modeles.ReferentielCommune;
12 david 10
import org.tela_botanica.client.observation.ObservationMediateur;
11
 
12
 
13 david 13
import com.google.gwt.user.client.Window;
14
import com.gwtext.client.core.EventCallback;
15
import com.gwtext.client.core.EventObject;
16
import com.gwtext.client.core.ListenerConfig;
12 david 17
import com.gwtext.client.core.Position;
13 david 18
import com.gwtext.client.data.ArrayReader;
19
import com.gwtext.client.data.FieldDef;
20
import com.gwtext.client.data.MemoryProxy;
21
import com.gwtext.client.data.RecordDef;
22
import com.gwtext.client.data.Store;
23
import com.gwtext.client.data.StringFieldDef;
12 david 24
import com.gwtext.client.widgets.Button;
25
import com.gwtext.client.widgets.Panel;
13 david 26
import com.gwtext.client.widgets.form.ComboBox;
12 david 27
import com.gwtext.client.widgets.form.DateField;
28
import com.gwtext.client.widgets.form.FormPanel;
29
import com.gwtext.client.widgets.form.TextField;
13 david 30
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
12 david 31
import com.gwtext.client.widgets.layout.ColumnLayout;
32
import com.gwtext.client.widgets.layout.ColumnLayoutData;
33
import com.gwtext.client.widgets.layout.FormLayout;
13 david 34
import com.gwtext.client.data.Record;
12 david 35
 
36
/**
37
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
38
 * @author aurelien
39
 *
40
 */
13 david 41
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 42
 
43
 
44
	/**
45
	 * Le médiateur associé à la vue
46
	 */
47
	private ObservationMediateur	observationMediateur		= null;
48
 
49
 
50
	private TextField nameAssistant = null;
13 david 51
	private DateField date = null;
12 david 52
	private TextField lieudit = null;
53
	private TextField station = null;
54
	private TextField milieu = null;
55
	private TextField comment = null;
13 david 56
	private ComboBox  commune = null;
12 david 57
 
13 david 58
	private boolean selectionCommune=false;
12 david 59
 
13 david 60
	  public static final int KEY_ALT = 18;
61
	  public static final int KEY_BACKSPACE = 8;
62
	  public static final int KEY_CTRL = 17;
63
	  public static final int KEY_DELETE = 46;
64
	  public static final int KEY_DOWN = 40;
65
	  public static final int KEY_END = 35;
66
	  public static final int KEY_ENTER = 13;
67
	  public static final int KEY_ESCAPE = 27;
68
	  public static final int KEY_HOME = 36;
69
	  public static final int KEY_LEFT = 37;
70
	  public static final int KEY_PAGEDOWN = 34;
71
	  public static final int KEY_PAGEUP = 33;
72
	  public static final int KEY_RIGHT = 39;
73
	  public static final int KEY_SHIFT = 16;
74
	  public static final int KEY_TAB = 9;
75
	  public static final int KEY_UP = 38;
76
 
77
	/**
78
	 * Store combobox communes
79
	 */
80
	private Store			store				= null;
81
 
12 david 82
 
13 david 83
 
84
 
12 david 85
	/**
86
	 * Booleen d'instanciation
87
	 */
88
	boolean estInstancie = false ;
89
 
90
	/**
91
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
92
	 */
93
	private FormulaireSaisieObservationVue()
94
	{
95
		super() ;
96
	}
97
 
98
	/**
99
	 * Constructeur avec argument
100
	 * @param im
101
	 */
102
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
103
	{
104
 
105
 
106
		// on associe le médiateur
107
		observationMediateur = obs ;
108
 
109
		this.setHeader(true);
110
		this.setTitle("Saisie");
111
 
112
 
113
		this.setCollapsible(true) ;
114
 
115
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
116
		panneauFormulaire.setBorder(false);
117
 
118
		// Panneau intermediaire qui contient deux colonnes de formulaire
119
 
120
		Panel panneauIntermediaire = new Panel();
121
		panneauIntermediaire.setLayout(new ColumnLayout());
122
		panneauIntermediaire.setBorder(false);
123
 
124
		//create first panel and add fields to it
125
		Panel panneauPremierColonne = new Panel();
126
		panneauPremierColonne.setLayout(new FormLayout());
127
		panneauPremierColonne.setBorder(false);
128
 
129
		//create second panel and add fields to it
130
	    Panel panneauSecondeColonne = new Panel();
131
		panneauSecondeColonne.setLayout(new FormLayout());
132
		panneauSecondeColonne.setBorder(false);
133
 
13 david 134
	/*
135
	    //	  creation du store
136
		FieldDef defCommune = new StringFieldDef("commune");
137
		FieldDef defDepartement = new StringFieldDef("departement");
12 david 138
 
13 david 139
 
140
		FieldDef[] defTab = { defCommune, defDepartement};
141
 
142
		RecordDef rd = new RecordDef(defTab);
143
 
144
 
145
		store = new Store(rd);
146
 
147
		//store.load();*/
148
 
149
		commune=new ComboBox("Commune","commune",275 );
150
 
151
 
152
		//commune.setStore(store);
153
 
154
		final String resultTpl = "<div class=\"search-item\">{commune}</div>";
155
 
156
 
157
		commune.setTpl(resultTpl);
158
		commune.setMode(ComboBox.REMOTE);
159
		// commune.setPageSize(10); // Ne fonctionne pas
160
		commune.setItemSelector("div.search-item");
161
 
162
 
163
		//commune.setDisplayField("title");
164
 
165
		commune.setTypeAhead(true);
166
		commune.setLoadingText("Recherche...");
167
 
168
		commune.setHideTrigger(true);
169
 
170
 
171
		/*
172
		final String resultTpl = "<div class=\"search-item\"><h3><span>{lastPost:date(\"M j, Y\")}"
173
			                                 +  "<br/>by {author}</span>{title}</h3>{excerpt}</div>";
174
 
175
		commune.setTpl(resultTpl);
176
		*/
177
 
178
		//commune.setMode(ComboBox.REMOTE);
179
 
180
		/*
181
		commune.setTitle("ExtJS Forums");
182
		commune.setHideLabel(true);
183
		commune.setItemSelector("div.search-item");
184
 
185
		  */
186
 
187
 
12 david 188
 
13 david 189
 
190
        commune.addListener(new ComboBoxListenerAdapter() {
191
             public void onSelect(ComboBox comboBox, Record record, int index) {
192
                 commune.setValue(record.getAsString("commune"));
193
                 selectionCommune=true;
194
             }
195
         });
196
 
197
 
198
//      Selection parmi la liste déroulante
199
 
200
 
201
		ListenerConfig listenerConfig=new ListenerConfig();
202
		listenerConfig.setDelay(10);
203
		listenerConfig.setStopPropagation(false);
204
		listenerConfig.setStopEvent(false);
205
 
206
 
207
 
208
	    commune.addKeyPressListener(new EventCallback()	{
209
 
210
	    	    public void execute(EventObject e) {
211
 
212
 
213
	    	    		  switch(e.getKey()) {
214
 
215
 
216
	    	    		  case KEY_ALT:
217
	    	    	      case KEY_CTRL:
218
	    	    	      case KEY_DOWN:
219
	    	    	      case KEY_END:
220
 
221
	    	    	      case KEY_ESCAPE:
222
	    	    	      case KEY_HOME:
223
	    	    	      case KEY_LEFT:
224
	    	    	      case KEY_PAGEDOWN:
225
	    	    	      case KEY_PAGEUP:
226
	    	    	      case KEY_RIGHT:
227
	    	    	      case KEY_SHIFT:
228
	    	    	      case KEY_TAB:
229
	    	    	      case KEY_UP:
230
 
231
	    	    	        break;
232
 
233
	    	    	      case KEY_ENTER:
234
 
235
	    	    	    	 if (selectionCommune) {
236
	    	    	    		 selectionCommune=false;
237
	    	    	    	 }
238
	    	    	    	 else {
239
	    	    	    		// lancer mise a jour
240
	    	    	    	 }
241
 
242
 
243
	    	    	    	  break;
244
 
245
	    	    	      default:
246
 
247
	    	    	    	  obtenirListeReferentielCommune();
248
 
249
	    	    	        break;
250
	    	    	    }
251
 
252
 
253
 
254
	     		}
255
 
256
	    		},    listenerConfig
257
 
258
		);
259
 
260
 
261
 
262
 
263
 
264
	    panneauPremierColonne.add(commune);
265
 
266
 
267
 
12 david 268
	    station = new TextField("Station", "station", 275);
269
	    station.setAllowBlank(true);
270
	    panneauPremierColonne.add(station);
271
 
272
	    date = new DateField("Date", "date", 100);
273
	    date.setAllowBlank(true);
274
	    date.setFormat("d/m/yyyy") ;
275
	    panneauPremierColonne.add(date);
276
 
277
		nameAssistant = new TextField("Espèce", "espece", 275);
278
		nameAssistant.setAllowBlank(false);
279
		panneauPremierColonne.add(nameAssistant);
280
 
281
	    comment = new TextField("Notes", "comment", 275);
282
	    comment.setAllowBlank(true);
283
	    panneauPremierColonne.add(comment);
284
 
285
 
286
	    lieudit = new TextField("Lieu-dit", "lieudit", 275);
287
	    lieudit.setAllowBlank(true);
288
	    panneauSecondeColonne.add(lieudit);
289
 
290
 
291
	    milieu = new TextField("Milieu", "milieu", 275);
292
	    milieu.setAllowBlank(true);
293
	    panneauSecondeColonne.add(milieu);
294
 
13 david 295
 
12 david 296
 
297
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
298
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
299
 
300
		panneauFormulaire.add(panneauIntermediaire);
301
 
302
		Button boutonOK = new Button("Ok");
303
		panneauFormulaire.addButton(boutonOK);
304
 
305
		Button boutonAnnuler = new Button("Annuler");
306
		panneauFormulaire.addButton(boutonAnnuler);
307
 
308
 
309
		this.add(panneauFormulaire) ;
310
 
311
 
312
		this.setAutoHeight(true);
313
 
314
 
315
 
316
		// on ajoute les listeners
317
		ajouterListeners() ;
318
 
319
 
320
 
321
	}
322
 
323
	private void ajouterListeners()
324
	{
325
		// on ajoute un écouteur
326
		/*validerInfo.addListener(new ButtonListenerAdapter() {
327
 
328
			// gestion du clic
329
 
330
			public void onClick(Button button, EventObject e) {
331
 
332
				// lors du clic sur le bouton valider on met à jour les commentaires et la date
333
		//	getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ;
334
 
335
			}
336
		});
337
		*/
338
 
339
 
340
	}
341
 
342
	/**
343
	 * Desactive visuellement ce panneau
344
	 */
345
	public void desactiverPanneau()
346
	{
347
		this.setDisabled(true) ;
348
	}
349
 
350
	/**
351
	 * Active visuellement ce panneau
352
	 */
353
	public void activerPanneau()
354
	{
355
		this.setDisabled(false) ;
356
	}
13 david 357
 
358
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
359
		//
360
 
361
 
362
		// si l'on a reçu une liste de commune
363
			if(nouvelleDonnees instanceof ListeReferentielCommune)
364
			{
365
 
366
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
367
					Object[][] communeData = new Object[data.size()][2];
368
					int i = 0 ;
369
 
370
					// on la parse et on récupère les informations quiç nous interessent
371
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
372
					{
373
 
374
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
375
 
376
						communeData[i][0]= ref.getCommune();
377
						communeData[i][1]= ref.getDepartement();
378
 
379
 
380
						i++ ;
381
					}
382
 
383
					   //	  creation du store
384
					FieldDef defCommune = new StringFieldDef("commune");
385
					FieldDef defDepartement = new StringFieldDef("departement");
386
 
387
 
388
					FieldDef[] defTab = { defCommune, defDepartement};
389
 
390
					RecordDef rd = new RecordDef(defTab);
391
 
392
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
393
					final ArrayReader reader = new ArrayReader(rd);
394
 
395
					store=new Store(dataProxy,reader);
396
					store.load() ;
397
 
398
					commune.setStore(store);
399
 
400
 
401
 
402
			}
403
	}
12 david 404
 
405
 
13 david 406
	public void obtenirListeReferentielCommune() {
407
	  observationMediateur.obtenirListeReferentielCommune(this,commune.getText());
408
 
409
	}
410
 
12 david 411
 
412
 
413
 
414
}