Subversion Repositories eFlore/Applications.coel

Rev

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