Subversion Repositories eFlore/Applications.coel

Rev

Rev 687 | 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,ComboBox<Valeur>> champsCbv = new HashMap<String,ComboBox<Valeur>>();
75
	private HashMap<String,ListStore<Valeur>> champsLsv = new HashMap<String,ListStore<Valeur>>();
638 jp_milcent 76
 
77
	private TabItem generalOnglet = null;
78
	private TabItem auteurOnglet = null;
687 jp_milcent 79
	private TabItem publicationOnglet = null;
638 jp_milcent 80
	private TabItem descriptionOnglet = null;
81
	private TabItem contenuOnglet = null;
82
	private TabItem documentOnglet = null;
83
	private TabItem inventaireOnglet = null;
687 jp_milcent 84
 
638 jp_milcent 85
	public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {
648 jp_milcent 86
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
638 jp_milcent 87
	}
88
 
89
	protected void creerOnglets() {
90
		onglets = new TabPanel();
91
		// NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner)
92
		onglets.setHeight("100%");
93
 
94
		// Onlget formulaire GENERAL
95
		onglets.add(creerOngletGeneral());
96
 
97
		// Onlget formulaire AUTEUR
98
		onglets.add(creerOngletAuteur());
99
 
687 jp_milcent 100
		// Onlget formulaire PUBLICATION
101
		onglets.add(creerOngletPublication());
102
 
638 jp_milcent 103
		// Onlget formulaire DESCRIPTION
104
		onglets.add(creerOngletDescription());
105
 
106
		// Onlget formulaire CONTENU
107
		onglets.add(creerOngletContenu());
108
 
109
		// Onlget formulaire DOCUMENT
110
		onglets.add(creerOngletDocument());
111
 
112
		// Onlget formulaire INVENTAIRE
113
		onglets.add(creerOngletInventaire());
114
 
115
		// Sélection de l'onglet par défaut
703 jp_milcent 116
		onglets.setSelection(auteurOnglet);
638 jp_milcent 117
 
118
		// Ajout des onglets au formulaire général
119
		panneauFormulaire.add(onglets);
120
	}
121
 
122
	private TabItem creerOngletGeneral() {
687 jp_milcent 123
		generalOnglet = new CollectionFormGeneral(this);
638 jp_milcent 124
		return generalOnglet;
125
	}
126
 
127
	private TabItem creerOngletAuteur() {
703 jp_milcent 128
		auteurOnglet = new CollectionFormAuteur(this);
638 jp_milcent 129
		return auteurOnglet;
130
	}
131
 
687 jp_milcent 132
	private TabItem creerOngletPublication() {
133
		publicationOnglet = creerOnglet(i18nC.collectionPublication(), "publication");
134
		publicationOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
135
			public void handleEvent(ComponentEvent be) {
136
				//peuplerOngletAuteur();
137
				publicationOnglet.layout();
138
			}
139
		});
140
 
141
		return publicationOnglet;
142
	}
143
 
638 jp_milcent 144
	private TabItem creerOngletDescription() {
145
		descriptionOnglet = creerOnglet(i18nC.collectionDescription(), "description");
146
		descriptionOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
147
			public void handleEvent(ComponentEvent be) {
148
				//peuplerOngletDescription();
149
				descriptionOnglet.layout();
150
			}
151
		});
152
 
153
		return descriptionOnglet;
154
	}
155
 
156
	private TabItem creerOngletContenu() {
687 jp_milcent 157
		contenuOnglet = creerOnglet(i18nC.collectionContenu(), "contenu");
638 jp_milcent 158
		contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
159
			public void handleEvent(ComponentEvent be) {
160
				//peuplerOngletContenu();
161
				contenuOnglet.layout();
162
			}
163
		});
164
 
165
		return contenuOnglet;
166
	}
167
 
168
	private TabItem creerOngletDocument() {
687 jp_milcent 169
		documentOnglet = creerOnglet(i18nC.collectionDocument(), "document");
638 jp_milcent 170
		documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
171
			public void handleEvent(ComponentEvent be) {
172
				//peuplerOngletDocument();
173
				documentOnglet.layout();
174
			}
175
		});
176
 
177
		return documentOnglet;
178
	}
179
 
180
	private TabItem creerOngletInventaire() {
687 jp_milcent 181
		inventaireOnglet = creerOnglet(i18nC.collectionInventaire(), "inventaire");
638 jp_milcent 182
		inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
183
			public void handleEvent(ComponentEvent be) {
184
				//peuplerOngletInventaire();
185
				inventaireOnglet.layout();
186
			}
187
		});
188
 
189
		return inventaireOnglet;
190
	}
191
 
192
	public void rafraichir(Object nouvellesDonnees) {
193
		try {
194
			if (nouvellesDonnees instanceof Information) {
195
				Information info = (Information) nouvellesDonnees;
196
				rafraichirInformation(info);
197
			} else {
198
				GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
199
			}
200
		} catch (Exception e) {
201
			GWT.log("rafraichir()", e);
202
		}
203
		verifierApresRafraichissement();
204
	}
205
 
687 jp_milcent 206
	private void rafraichirInformation(Information info) {
638 jp_milcent 207
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
208
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
209
		}
210
 
211
		if (info.getType().equals("modif_structure")) {
212
			Info.display("Modification d'une collection", info.toString());
213
		} else if (info.getType().equals("selection_collection")) {
214
			Info.display("Modification d'une collection", info.toString());
215
			if (info.getDonnee(0) != null) {
216
				collection = (Collection) info.getDonnee(0);
217
			}
218
			actualiserPeuplementOnglet();
219
			actualiserTitrePanneau();
220
		}
221
	}
222
 
223
	private void actualiserPeuplementOnglet() {
224
		onglets.setSelection(onglets.getSelectedItem());
225
	}
226
 
227
	private void actualiserTitrePanneau() {
228
		String titre = i18nC.titreModifFormCollection();
229
		// Composition du titre
230
		titre += " - ID : "+collection.getId();
231
		panneauFormulaire.setHeading(titre);
232
	}
233
 
234
	@Override
235
	protected SelectionListener<ButtonEvent> creerEcouteurBoutonFormulaire(final String code) {
236
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
237
			@Override
238
			public void componentSelected(ButtonEvent ce) {
239
				if (code.equals(Formulaire.CODE_BOUTON_VALIDER)) {
240
					soumettreFormulaire();
241
					clicBoutonvalidation = true;
242
				} else if (code.equals(Formulaire.CODE_BOUTON_APPLIQUER)) {
243
					soumettreFormulaire();
244
				} else if (code.equals(Formulaire.CODE_BOUTON_ANNULER)) {
245
					mediateur.clicMenu(menuIdCourant);
246
				} else if (code.equals(Formulaire.CODE_BOUTON_REINITIALISER)) {
247
					if (mode.equals(StructureForm.MODE_MODIFIER)) {
248
						mediateur.afficherFormCollection(collection.getId());
249
					} else {
250
						mediateur.afficherFormCollection(null);
251
					}
252
				}
253
			}
254
		};
255
 
256
		return ecouteur;
257
	}
258
 
259
	protected void soumettreFormulaire() {
260
		// Vérification de la validité des champs du formulaire
261
		if (verifierFormulaire()) {
262
			// Collecte des données du formulaire
263
			Collection collection = collecterCollection();
264
 
265
			if (mode.equals(MODE_AJOUTER)) {
266
				mediateur.ajouterCollection(this, collection);
267
			} else if (mode.equals(MODE_MODIFIER)) {
268
				if (collection == null) {
269
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
270
				} else {
271
					mediateur.modifierCollection(this, collection);
272
				}
273
			}
274
		}
275
	}
276
 
277
	private Collection collecterCollection() {
278
		collectionCollectee = (Collection) collection.cloner(new Collection());
279
 
280
		collecterOngletGeneral();
281
 
282
		Collection collectionARetourner = null;
283
		if (!collectionCollectee.comparer(collection)) {
284
			collectionARetourner = collection = collectionCollectee;
285
		}
286
		return collectionARetourner;
287
	}
288
 
289
	private void collecterOngletGeneral() {
290
		if (generalOnglet.getData("acces").equals(true)) {
291
 
292
		}
293
	}
294
 
295
	private Boolean verifierFormulaire() {
296
		return true;
297
	}
298
 
299
	@Override
300
	protected void afficherChampSupplementaire(Radio radioBtn) {
301
		// TODO Auto-generated method stub
302
 
303
	}
304
}