Subversion Repositories eFlore/Applications.coel

Rev

Rev 703 | Rev 775 | 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() {
720 jp_milcent 133
		publicationOnglet = new CollectionFormPublication(this);
687 jp_milcent 134
		return publicationOnglet;
135
	}
136
 
638 jp_milcent 137
	private TabItem creerOngletDescription() {
138
		descriptionOnglet = creerOnglet(i18nC.collectionDescription(), "description");
139
		descriptionOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
140
			public void handleEvent(ComponentEvent be) {
141
				//peuplerOngletDescription();
142
				descriptionOnglet.layout();
143
			}
144
		});
145
 
146
		return descriptionOnglet;
147
	}
148
 
149
	private TabItem creerOngletContenu() {
687 jp_milcent 150
		contenuOnglet = creerOnglet(i18nC.collectionContenu(), "contenu");
638 jp_milcent 151
		contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
152
			public void handleEvent(ComponentEvent be) {
153
				//peuplerOngletContenu();
154
				contenuOnglet.layout();
155
			}
156
		});
157
 
158
		return contenuOnglet;
159
	}
160
 
161
	private TabItem creerOngletDocument() {
687 jp_milcent 162
		documentOnglet = creerOnglet(i18nC.collectionDocument(), "document");
638 jp_milcent 163
		documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
164
			public void handleEvent(ComponentEvent be) {
165
				//peuplerOngletDocument();
166
				documentOnglet.layout();
167
			}
168
		});
169
 
170
		return documentOnglet;
171
	}
172
 
173
	private TabItem creerOngletInventaire() {
687 jp_milcent 174
		inventaireOnglet = creerOnglet(i18nC.collectionInventaire(), "inventaire");
638 jp_milcent 175
		inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
176
			public void handleEvent(ComponentEvent be) {
177
				//peuplerOngletInventaire();
178
				inventaireOnglet.layout();
179
			}
180
		});
181
 
182
		return inventaireOnglet;
183
	}
184
 
185
	public void rafraichir(Object nouvellesDonnees) {
186
		try {
187
			if (nouvellesDonnees instanceof Information) {
188
				Information info = (Information) nouvellesDonnees;
189
				rafraichirInformation(info);
190
			} else {
191
				GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
192
			}
193
		} catch (Exception e) {
194
			GWT.log("rafraichir()", e);
195
		}
196
		verifierApresRafraichissement();
197
	}
198
 
687 jp_milcent 199
	private void rafraichirInformation(Information info) {
638 jp_milcent 200
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
201
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
202
		}
203
 
204
		if (info.getType().equals("modif_structure")) {
205
			Info.display("Modification d'une collection", info.toString());
206
		} else if (info.getType().equals("selection_collection")) {
207
			Info.display("Modification d'une collection", info.toString());
208
			if (info.getDonnee(0) != null) {
209
				collection = (Collection) info.getDonnee(0);
210
			}
211
			actualiserPeuplementOnglet();
212
			actualiserTitrePanneau();
213
		}
214
	}
215
 
216
	private void actualiserPeuplementOnglet() {
217
		onglets.setSelection(onglets.getSelectedItem());
218
	}
219
 
220
	private void actualiserTitrePanneau() {
221
		String titre = i18nC.titreModifFormCollection();
222
		// Composition du titre
223
		titre += " - ID : "+collection.getId();
224
		panneauFormulaire.setHeading(titre);
225
	}
226
 
227
	@Override
228
	protected SelectionListener<ButtonEvent> creerEcouteurBoutonFormulaire(final String code) {
229
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
230
			@Override
231
			public void componentSelected(ButtonEvent ce) {
232
				if (code.equals(Formulaire.CODE_BOUTON_VALIDER)) {
233
					soumettreFormulaire();
234
					clicBoutonvalidation = true;
235
				} else if (code.equals(Formulaire.CODE_BOUTON_APPLIQUER)) {
236
					soumettreFormulaire();
237
				} else if (code.equals(Formulaire.CODE_BOUTON_ANNULER)) {
238
					mediateur.clicMenu(menuIdCourant);
239
				} else if (code.equals(Formulaire.CODE_BOUTON_REINITIALISER)) {
240
					if (mode.equals(StructureForm.MODE_MODIFIER)) {
241
						mediateur.afficherFormCollection(collection.getId());
242
					} else {
243
						mediateur.afficherFormCollection(null);
244
					}
245
				}
246
			}
247
		};
248
 
249
		return ecouteur;
250
	}
251
 
252
	protected void soumettreFormulaire() {
253
		// Vérification de la validité des champs du formulaire
254
		if (verifierFormulaire()) {
255
			// Collecte des données du formulaire
256
			Collection collection = collecterCollection();
257
 
258
			if (mode.equals(MODE_AJOUTER)) {
259
				mediateur.ajouterCollection(this, collection);
260
			} else if (mode.equals(MODE_MODIFIER)) {
261
				if (collection == null) {
262
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
263
				} else {
264
					mediateur.modifierCollection(this, collection);
265
				}
266
			}
267
		}
268
	}
269
 
270
	private Collection collecterCollection() {
271
		collectionCollectee = (Collection) collection.cloner(new Collection());
272
 
273
		collecterOngletGeneral();
274
 
275
		Collection collectionARetourner = null;
276
		if (!collectionCollectee.comparer(collection)) {
277
			collectionARetourner = collection = collectionCollectee;
278
		}
279
		return collectionARetourner;
280
	}
281
 
282
	private void collecterOngletGeneral() {
283
		if (generalOnglet.getData("acces").equals(true)) {
284
 
285
		}
286
	}
287
 
288
	private Boolean verifierFormulaire() {
289
		return true;
290
	}
291
 
292
	@Override
293
	protected void afficherChampSupplementaire(Radio radioBtn) {
294
		// TODO Auto-generated method stub
295
 
296
	}
297
}