Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
638 jp_milcent 1
package org.tela_botanica.client.vues;
2
 
687 jp_milcent 3
import java.util.ArrayList;
638 jp_milcent 4
import java.util.HashMap;
687 jp_milcent 5
import java.util.Iterator;
638 jp_milcent 6
import java.util.List;
7
 
8
import org.tela_botanica.client.Mediateur;
687 jp_milcent 9
import org.tela_botanica.client.RegistreId;
10
import org.tela_botanica.client.composants.ChampMultiValeurs;
11
import org.tela_botanica.client.images.Images;
638 jp_milcent 12
import org.tela_botanica.client.interfaces.Rafraichissable;
13
import org.tela_botanica.client.modeles.Collection;
687 jp_milcent 14
import org.tela_botanica.client.modeles.CollectionListe;
15
import org.tela_botanica.client.modeles.Configuration;
638 jp_milcent 16
import org.tela_botanica.client.modeles.Information;
17
import org.tela_botanica.client.modeles.MenuApplicationId;
687 jp_milcent 18
import org.tela_botanica.client.modeles.Projet;
19
import org.tela_botanica.client.modeles.ProjetListe;
638 jp_milcent 20
import org.tela_botanica.client.modeles.Structure;
687 jp_milcent 21
import org.tela_botanica.client.modeles.StructureListe;
638 jp_milcent 22
import org.tela_botanica.client.modeles.Valeur;
23
import org.tela_botanica.client.modeles.ValeurListe;
24
 
687 jp_milcent 25
import com.extjs.gxt.ui.client.Registry;
26
import com.extjs.gxt.ui.client.Style.SortDir;
27
import com.extjs.gxt.ui.client.event.BaseEvent;
638 jp_milcent 28
import com.extjs.gxt.ui.client.event.ButtonEvent;
29
import com.extjs.gxt.ui.client.event.ComponentEvent;
687 jp_milcent 30
import com.extjs.gxt.ui.client.event.EventType;
638 jp_milcent 31
import com.extjs.gxt.ui.client.event.Events;
32
import com.extjs.gxt.ui.client.event.Listener;
687 jp_milcent 33
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
34
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
638 jp_milcent 35
import com.extjs.gxt.ui.client.event.SelectionListener;
687 jp_milcent 36
import com.extjs.gxt.ui.client.event.WidgetListener;
37
import com.extjs.gxt.ui.client.store.ListStore;
38
import com.extjs.gxt.ui.client.store.Store;
39
import com.extjs.gxt.ui.client.store.StoreEvent;
40
import com.extjs.gxt.ui.client.store.StoreListener;
41
import com.extjs.gxt.ui.client.widget.Component;
638 jp_milcent 42
import com.extjs.gxt.ui.client.widget.Info;
687 jp_milcent 43
import com.extjs.gxt.ui.client.widget.LayoutContainer;
44
import com.extjs.gxt.ui.client.widget.MessageBox;
638 jp_milcent 45
import com.extjs.gxt.ui.client.widget.TabItem;
46
import com.extjs.gxt.ui.client.widget.TabPanel;
687 jp_milcent 47
import com.extjs.gxt.ui.client.widget.Text;
48
import com.extjs.gxt.ui.client.widget.button.Button;
49
import com.extjs.gxt.ui.client.widget.form.ComboBox;
50
import com.extjs.gxt.ui.client.widget.form.Field;
638 jp_milcent 51
import com.extjs.gxt.ui.client.widget.form.FieldSet;
52
import com.extjs.gxt.ui.client.widget.form.HiddenField;
687 jp_milcent 53
import com.extjs.gxt.ui.client.widget.form.LabelField;
54
import com.extjs.gxt.ui.client.widget.form.NumberField;
638 jp_milcent 55
import com.extjs.gxt.ui.client.widget.form.Radio;
687 jp_milcent 56
import com.extjs.gxt.ui.client.widget.form.TextArea;
648 jp_milcent 57
import com.extjs.gxt.ui.client.widget.form.TextField;
687 jp_milcent 58
import com.extjs.gxt.ui.client.widget.form.Validator;
59
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
638 jp_milcent 60
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
687 jp_milcent 61
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
62
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
648 jp_milcent 63
import com.extjs.gxt.ui.client.widget.layout.FormData;
687 jp_milcent 64
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
638 jp_milcent 65
import com.google.gwt.core.client.GWT;
687 jp_milcent 66
import com.google.gwt.i18n.client.NumberFormat;
638 jp_milcent 67
import com.google.gwt.user.client.ui.Widget;
68
 
69
public class CollectionForm extends Formulaire implements Rafraichissable {
70
 
71
	private Collection collection = null;
72
	private Collection collectionCollectee = null;
73
 
687 jp_milcent 74
	private HashMap<String,FieldSet> champsFs = new HashMap<String,FieldSet>();
75
	private HashMap<String,LayoutContainer> champsLc = new HashMap<String,LayoutContainer>();
76
	private HashMap<String,HiddenField<String>> champsHfs = new HashMap<String,HiddenField<String>>();
77
	private HashMap<String,TextField<String>> champsTfs = new HashMap<String,TextField<String>>();
78
	private HashMap<String,TextArea> champsTa = new HashMap<String,TextArea>();
79
	private HashMap<String,ChampMultiValeurs> champsCmv = new HashMap<String,ChampMultiValeurs>();
80
	private HashMap<String,Text> champsT = new HashMap<String,Text>();
81
	private HashMap<String,ComboBox<Valeur>> champsCbv = new HashMap<String,ComboBox<Valeur>>();
82
	private HashMap<String,ListStore<Valeur>> champsLsv = new HashMap<String,ListStore<Valeur>>();
638 jp_milcent 83
 
84
	private TabItem generalOnglet = null;
85
	private TabItem auteurOnglet = null;
687 jp_milcent 86
	private TabItem publicationOnglet = null;
638 jp_milcent 87
	private TabItem descriptionOnglet = null;
88
	private TabItem contenuOnglet = null;
89
	private TabItem documentOnglet = null;
90
	private TabItem inventaireOnglet = null;
687 jp_milcent 91
 
92
	private ListStore<Projet> projetsStore;
93
	private ComboBox<Projet> projetsCombo;
94
	private ListStore<Structure> structuresStore;
95
	private ComboBox<Structure> structuresCombo;
96
	private ListStore<Collection> collectionsStore;
97
	private ComboBox<Collection> collectionsCombo;
638 jp_milcent 98
 
687 jp_milcent 99
 
638 jp_milcent 100
	public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {
648 jp_milcent 101
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
638 jp_milcent 102
	}
103
 
104
	protected void creerOnglets() {
105
		onglets = new TabPanel();
106
		// NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner)
107
		onglets.setHeight("100%");
108
 
109
		// Onlget formulaire GENERAL
110
		onglets.add(creerOngletGeneral());
111
 
112
		// Onlget formulaire AUTEUR
113
		onglets.add(creerOngletAuteur());
114
 
687 jp_milcent 115
		// Onlget formulaire PUBLICATION
116
		onglets.add(creerOngletPublication());
117
 
638 jp_milcent 118
		// Onlget formulaire DESCRIPTION
119
		onglets.add(creerOngletDescription());
120
 
121
		// Onlget formulaire CONTENU
122
		onglets.add(creerOngletContenu());
123
 
124
		// Onlget formulaire DOCUMENT
125
		onglets.add(creerOngletDocument());
126
 
127
		// Onlget formulaire INVENTAIRE
128
		onglets.add(creerOngletInventaire());
129
 
130
		// Sélection de l'onglet par défaut
131
		//onglets.setSelection(personnelOnglet);
132
 
133
		// Ajout des onglets au formulaire général
134
		panneauFormulaire.add(onglets);
135
	}
136
 
137
	private TabItem creerOngletGeneral() {
687 jp_milcent 138
		generalOnglet = new CollectionFormGeneral(this);
638 jp_milcent 139
		return generalOnglet;
140
	}
141
 
142
	private TabItem creerOngletAuteur() {
143
		auteurOnglet = creerOnglet(i18nC.collectionAuteur(), "auteur");
144
		auteurOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
145
			public void handleEvent(ComponentEvent be) {
146
				//peuplerOngletAuteur();
147
				auteurOnglet.layout();
148
			}
149
		});
150
 
151
		return auteurOnglet;
152
	}
153
 
687 jp_milcent 154
	private TabItem creerOngletPublication() {
155
		publicationOnglet = creerOnglet(i18nC.collectionPublication(), "publication");
156
		publicationOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
157
			public void handleEvent(ComponentEvent be) {
158
				//peuplerOngletAuteur();
159
				publicationOnglet.layout();
160
			}
161
		});
162
 
163
		return publicationOnglet;
164
	}
165
 
638 jp_milcent 166
	private TabItem creerOngletDescription() {
167
		descriptionOnglet = creerOnglet(i18nC.collectionDescription(), "description");
168
		descriptionOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
169
			public void handleEvent(ComponentEvent be) {
170
				//peuplerOngletDescription();
171
				descriptionOnglet.layout();
172
			}
173
		});
174
 
175
		return descriptionOnglet;
176
	}
177
 
178
	private TabItem creerOngletContenu() {
687 jp_milcent 179
		contenuOnglet = creerOnglet(i18nC.collectionContenu(), "contenu");
638 jp_milcent 180
		contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
181
			public void handleEvent(ComponentEvent be) {
182
				//peuplerOngletContenu();
183
				contenuOnglet.layout();
184
			}
185
		});
186
 
187
		return contenuOnglet;
188
	}
189
 
190
	private TabItem creerOngletDocument() {
687 jp_milcent 191
		documentOnglet = creerOnglet(i18nC.collectionDocument(), "document");
638 jp_milcent 192
		documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
193
			public void handleEvent(ComponentEvent be) {
194
				//peuplerOngletDocument();
195
				documentOnglet.layout();
196
			}
197
		});
198
 
199
		return documentOnglet;
200
	}
201
 
202
	private TabItem creerOngletInventaire() {
687 jp_milcent 203
		inventaireOnglet = creerOnglet(i18nC.collectionInventaire(), "inventaire");
638 jp_milcent 204
		inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
205
			public void handleEvent(ComponentEvent be) {
206
				//peuplerOngletInventaire();
207
				inventaireOnglet.layout();
208
			}
209
		});
210
 
211
		return inventaireOnglet;
212
	}
213
 
214
	public void rafraichir(Object nouvellesDonnees) {
215
		try {
216
			if (nouvellesDonnees instanceof Information) {
217
				Information info = (Information) nouvellesDonnees;
218
				rafraichirInformation(info);
219
			} else if (nouvellesDonnees instanceof ValeurListe) {
220
				ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
221
				rafraichirValeurListe(listeValeurs);
222
			} else {
223
				GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
224
			}
225
		} catch (Exception e) {
226
			GWT.log("rafraichir()", e);
227
		}
228
		verifierApresRafraichissement();
229
	}
230
 
687 jp_milcent 231
	private void rafraichirInformation(Information info) {
638 jp_milcent 232
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
233
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
234
		}
235
 
236
		if (info.getType().equals("modif_structure")) {
237
			Info.display("Modification d'une collection", info.toString());
238
		} else if (info.getType().equals("selection_collection")) {
239
			Info.display("Modification d'une collection", info.toString());
240
			if (info.getDonnee(0) != null) {
241
				collection = (Collection) info.getDonnee(0);
242
			}
243
			actualiserPeuplementOnglet();
244
			actualiserTitrePanneau();
245
		}
246
	}
247
 
687 jp_milcent 248
	private void rafraichirValeurListe(ValeurListe listeValeurs) {
638 jp_milcent 249
		List<Valeur> liste = listeValeurs.toList();
250
 
251
		// Test pour savoir si la liste contient des éléments
252
		if (liste.size() > 0) {
687 jp_milcent 253
			String[] listesTraitables = {};
638 jp_milcent 254
 
687 jp_milcent 255
			Boolean implemente = false;
256
			for (int i = 0; i < listesTraitables.length;  i++) {
257
				String id = listesTraitables[i];
258
				GWT.log(id, null);
259
				if (listeValeurs.getId().equals(config.getListeId(id))) {
260
					champsLsv.get(id).removeAll();
261
					champsLsv.get(id).add(liste);
262
					champsCbv.get(id).setStore(champsLsv.get(id));
263
					implemente = true;
264
					break;
265
				}
266
			}
267
			if (implemente == false) {
268
				GWT.log("Gestion de la liste "+listeValeurs.getId()+" non implémenté!", null);
269
			}
638 jp_milcent 270
		}
271
	}
272
 
273
	private void actualiserPeuplementOnglet() {
274
		onglets.setSelection(onglets.getSelectedItem());
275
	}
276
 
277
	private void actualiserTitrePanneau() {
278
		String titre = i18nC.titreModifFormCollection();
279
		// Composition du titre
280
		titre += " - ID : "+collection.getId();
281
		panneauFormulaire.setHeading(titre);
282
	}
283
 
284
	@Override
285
	protected SelectionListener<ButtonEvent> creerEcouteurBoutonFormulaire(final String code) {
286
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
287
			@Override
288
			public void componentSelected(ButtonEvent ce) {
289
				if (code.equals(Formulaire.CODE_BOUTON_VALIDER)) {
290
					soumettreFormulaire();
291
					clicBoutonvalidation = true;
292
				} else if (code.equals(Formulaire.CODE_BOUTON_APPLIQUER)) {
293
					soumettreFormulaire();
294
				} else if (code.equals(Formulaire.CODE_BOUTON_ANNULER)) {
295
					mediateur.clicMenu(menuIdCourant);
296
				} else if (code.equals(Formulaire.CODE_BOUTON_REINITIALISER)) {
297
					if (mode.equals(StructureForm.MODE_MODIFIER)) {
298
						mediateur.afficherFormCollection(collection.getId());
299
					} else {
300
						mediateur.afficherFormCollection(null);
301
					}
302
				}
303
			}
304
		};
305
 
306
		return ecouteur;
307
	}
308
 
309
	protected void soumettreFormulaire() {
310
		// Vérification de la validité des champs du formulaire
311
		if (verifierFormulaire()) {
312
			// Collecte des données du formulaire
313
			Collection collection = collecterCollection();
314
 
315
			if (mode.equals(MODE_AJOUTER)) {
316
				mediateur.ajouterCollection(this, collection);
317
			} else if (mode.equals(MODE_MODIFIER)) {
318
				if (collection == null) {
319
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
320
				} else {
321
					mediateur.modifierCollection(this, collection);
322
				}
323
			}
324
		}
325
	}
326
 
327
	private Collection collecterCollection() {
328
		collectionCollectee = (Collection) collection.cloner(new Collection());
329
 
330
		collecterOngletGeneral();
331
 
332
		Collection collectionARetourner = null;
333
		if (!collectionCollectee.comparer(collection)) {
334
			collectionARetourner = collection = collectionCollectee;
335
		}
336
		return collectionARetourner;
337
	}
338
 
339
	private void collecterOngletGeneral() {
340
		if (generalOnglet.getData("acces").equals(true)) {
341
 
342
		}
343
	}
344
 
345
	private Boolean verifierFormulaire() {
346
		return true;
347
	}
348
 
349
	@Override
350
	protected void afficherChampSupplementaire(Radio radioBtn) {
351
		// TODO Auto-generated method stub
352
 
353
	}
354
}