Subversion Repositories eFlore/Applications.coel

Rev

Rev 648 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
638 jp_milcent 1
package org.tela_botanica.client.vues;
2
 
3
import java.util.HashMap;
4
import java.util.List;
5
 
6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.Collection;
9
import org.tela_botanica.client.modeles.Information;
10
import org.tela_botanica.client.modeles.MenuApplicationId;
11
import org.tela_botanica.client.modeles.Structure;
12
import org.tela_botanica.client.modeles.StructureConservation;
13
import org.tela_botanica.client.modeles.StructureValorisation;
14
import org.tela_botanica.client.modeles.Valeur;
15
import org.tela_botanica.client.modeles.ValeurListe;
16
 
17
import com.extjs.gxt.ui.client.event.ButtonEvent;
18
import com.extjs.gxt.ui.client.event.ComponentEvent;
19
import com.extjs.gxt.ui.client.event.Events;
20
import com.extjs.gxt.ui.client.event.Listener;
21
import com.extjs.gxt.ui.client.event.SelectionListener;
22
import com.extjs.gxt.ui.client.widget.Info;
23
import com.extjs.gxt.ui.client.widget.TabItem;
24
import com.extjs.gxt.ui.client.widget.TabPanel;
25
import com.extjs.gxt.ui.client.widget.form.FieldSet;
26
import com.extjs.gxt.ui.client.widget.form.HiddenField;
27
import com.extjs.gxt.ui.client.widget.form.Radio;
28
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
29
import com.google.gwt.core.client.GWT;
30
import com.google.gwt.user.client.ui.Widget;
31
 
32
public class CollectionForm extends Formulaire implements Rafraichissable {
33
 
34
	private Collection collection = null;
35
	private Collection collectionCollectee = null;
36
 
37
	private HashMap<String, Widget>champs = new HashMap<String, Widget>();
38
 
39
	private TabItem generalOnglet = null;
40
	private TabItem auteurOnglet = null;
41
	private TabItem descriptionOnglet = null;
42
	private TabItem contenuOnglet = null;
43
	private TabItem documentOnglet = null;
44
	private TabItem inventaireOnglet = null;
45
 
46
	public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {
47
		super(mediateurCourrant, modeDeCreation);
48
		menuIdCourant = MenuApplicationId.COLLECTION;
49
		creerOnglets();
50
		add(panneauFormulaire);
51
	}
52
 
53
	protected void creerOnglets() {
54
		onglets = new TabPanel();
55
		// NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner)
56
		onglets.setHeight("100%");
57
 
58
		// Onlget formulaire GENERAL
59
		onglets.add(creerOngletGeneral());
60
 
61
		// Onlget formulaire AUTEUR
62
		onglets.add(creerOngletAuteur());
63
 
64
		// Onlget formulaire DESCRIPTION
65
		onglets.add(creerOngletDescription());
66
 
67
		// Onlget formulaire CONTENU
68
		onglets.add(creerOngletContenu());
69
 
70
		// Onlget formulaire DOCUMENT
71
		onglets.add(creerOngletDocument());
72
 
73
		// Onlget formulaire INVENTAIRE
74
		onglets.add(creerOngletInventaire());
75
 
76
		// Sélection de l'onglet par défaut
77
		//onglets.setSelection(personnelOnglet);
78
 
79
		// Ajout des onglets au formulaire général
80
		panneauFormulaire.add(onglets);
81
	}
82
 
83
	private TabItem creerOngletGeneral() {
84
		generalOnglet = creerOnglet(i18nC.collectionGeneral(), "general");
85
		generalOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
86
			public void handleEvent(ComponentEvent be) {
87
				//peuplerOngletGeneral();
88
				generalOnglet.layout();
89
			}
90
		});
91
 
92
		//+-----------------------------------------------------------------------------------------------------------+
93
		// Champs cachés
94
		HiddenField<String> idCollectionChp = new HiddenField<String>();
95
		champs.put("idCollectionChp", idCollectionChp);
96
 
97
		//+-----------------------------------------------------------------------------------------------------------+
98
		// Fieldset ADMINISTRATIF
99
		FieldSet fieldSetIdentite = new FieldSet();
100
		fieldSetIdentite.setHeading(i18nC.collectionGeneralTitre());
101
		fieldSetIdentite.setCollapsible(true);
102
		fieldSetIdentite.setLayout(creerFormLayout(120, LabelAlign.LEFT));
103
 
104
 
105
		return generalOnglet;
106
	}
107
 
108
	private TabItem creerOngletAuteur() {
109
		auteurOnglet = creerOnglet(i18nC.collectionAuteur(), "auteur");
110
		auteurOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
111
			public void handleEvent(ComponentEvent be) {
112
				//peuplerOngletAuteur();
113
				auteurOnglet.layout();
114
			}
115
		});
116
 
117
		return auteurOnglet;
118
	}
119
 
120
	private TabItem creerOngletDescription() {
121
		descriptionOnglet = creerOnglet(i18nC.collectionDescription(), "description");
122
		descriptionOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
123
			public void handleEvent(ComponentEvent be) {
124
				//peuplerOngletDescription();
125
				descriptionOnglet.layout();
126
			}
127
		});
128
 
129
		return descriptionOnglet;
130
	}
131
 
132
	private TabItem creerOngletContenu() {
133
		contenuOnglet = creerOnglet(i18nC.collectionDescription(), "contenu");
134
		contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
135
			public void handleEvent(ComponentEvent be) {
136
				//peuplerOngletContenu();
137
				contenuOnglet.layout();
138
			}
139
		});
140
 
141
		return contenuOnglet;
142
	}
143
 
144
	private TabItem creerOngletDocument() {
145
		documentOnglet = creerOnglet(i18nC.collectionDescription(), "document");
146
		documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
147
			public void handleEvent(ComponentEvent be) {
148
				//peuplerOngletDocument();
149
				documentOnglet.layout();
150
			}
151
		});
152
 
153
		return documentOnglet;
154
	}
155
 
156
	private TabItem creerOngletInventaire() {
157
		inventaireOnglet = creerOnglet(i18nC.collectionDescription(), "inventaire");
158
		inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
159
			public void handleEvent(ComponentEvent be) {
160
				//peuplerOngletInventaire();
161
				inventaireOnglet.layout();
162
			}
163
		});
164
 
165
		return inventaireOnglet;
166
	}
167
 
168
	public void rafraichir(Object nouvellesDonnees) {
169
		try {
170
			if (nouvellesDonnees instanceof Information) {
171
				Information info = (Information) nouvellesDonnees;
172
				rafraichirInformation(info);
173
			} else if (nouvellesDonnees instanceof ValeurListe) {
174
				ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
175
				rafraichirValeurListe(listeValeurs);
176
			} else {
177
				GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
178
			}
179
		} catch (Exception e) {
180
			GWT.log("rafraichir()", e);
181
		}
182
		verifierApresRafraichissement();
183
	}
184
 
185
	public void rafraichirInformation(Information info) {
186
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
187
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
188
		}
189
 
190
		if (info.getType().equals("modif_structure")) {
191
			Info.display("Modification d'une collection", info.toString());
192
		} else if (info.getType().equals("selection_collection")) {
193
			Info.display("Modification d'une collection", info.toString());
194
			if (info.getDonnee(0) != null) {
195
				collection = (Collection) info.getDonnee(0);
196
			}
197
			actualiserPeuplementOnglet();
198
			actualiserTitrePanneau();
199
		}
200
	}
201
 
202
	public void rafraichirValeurListe(ValeurListe listeValeurs) {
203
		List<Valeur> liste = listeValeurs.toList();
204
 
205
		// Test pour savoir si la liste contient des éléments
206
		if (liste.size() > 0) {
207
 
208
		}
209
	}
210
 
211
	private void actualiserPeuplementOnglet() {
212
		onglets.setSelection(onglets.getSelectedItem());
213
	}
214
 
215
	private void actualiserTitrePanneau() {
216
		String titre = i18nC.titreModifFormCollection();
217
		// Composition du titre
218
		titre += " - ID : "+collection.getId();
219
		panneauFormulaire.setHeading(titre);
220
	}
221
 
222
	@Override
223
	protected SelectionListener<ButtonEvent> creerEcouteurBoutonFormulaire(final String code) {
224
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
225
			@Override
226
			public void componentSelected(ButtonEvent ce) {
227
				if (code.equals(Formulaire.CODE_BOUTON_VALIDER)) {
228
					soumettreFormulaire();
229
					clicBoutonvalidation = true;
230
				} else if (code.equals(Formulaire.CODE_BOUTON_APPLIQUER)) {
231
					soumettreFormulaire();
232
				} else if (code.equals(Formulaire.CODE_BOUTON_ANNULER)) {
233
					mediateur.clicMenu(menuIdCourant);
234
				} else if (code.equals(Formulaire.CODE_BOUTON_REINITIALISER)) {
235
					if (mode.equals(StructureForm.MODE_MODIFIER)) {
236
						mediateur.afficherFormCollection(collection.getId());
237
					} else {
238
						mediateur.afficherFormCollection(null);
239
					}
240
				}
241
			}
242
		};
243
 
244
		return ecouteur;
245
	}
246
 
247
	protected void soumettreFormulaire() {
248
		// Vérification de la validité des champs du formulaire
249
		if (verifierFormulaire()) {
250
			// Collecte des données du formulaire
251
			Collection collection = collecterCollection();
252
 
253
			if (mode.equals(MODE_AJOUTER)) {
254
				mediateur.ajouterCollection(this, collection);
255
			} else if (mode.equals(MODE_MODIFIER)) {
256
				if (collection == null) {
257
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
258
				} else {
259
					mediateur.modifierCollection(this, collection);
260
				}
261
			}
262
		}
263
	}
264
 
265
	private Collection collecterCollection() {
266
		collectionCollectee = (Collection) collection.cloner(new Collection());
267
 
268
		collecterOngletGeneral();
269
 
270
		Collection collectionARetourner = null;
271
		if (!collectionCollectee.comparer(collection)) {
272
			collectionARetourner = collection = collectionCollectee;
273
		}
274
		return collectionARetourner;
275
	}
276
 
277
	private void collecterOngletGeneral() {
278
		if (generalOnglet.getData("acces").equals(true)) {
279
 
280
		}
281
	}
282
 
283
	private Boolean verifierFormulaire() {
284
		return true;
285
	}
286
 
287
	@Override
288
	protected void afficherChampSupplementaire(Radio radioBtn) {
289
		// TODO Auto-generated method stub
290
 
291
	}
292
}