Subversion Repositories eFlore/Applications.coel

Rev

Rev 851 | Rev 860 | 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
 
3
import org.tela_botanica.client.Mediateur;
858 jpm 4
import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;
638 jp_milcent 5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.modeles.Collection;
7
import org.tela_botanica.client.modeles.Information;
8
import org.tela_botanica.client.modeles.MenuApplicationId;
9
import org.tela_botanica.client.modeles.Valeur;
10
 
858 jpm 11
import com.extjs.gxt.ui.client.event.BaseEvent;
638 jp_milcent 12
import com.extjs.gxt.ui.client.event.ButtonEvent;
13
import com.extjs.gxt.ui.client.event.ComponentEvent;
14
import com.extjs.gxt.ui.client.event.Events;
15
import com.extjs.gxt.ui.client.event.Listener;
16
import com.extjs.gxt.ui.client.event.SelectionListener;
858 jpm 17
import com.extjs.gxt.ui.client.store.StoreEvent;
18
import com.extjs.gxt.ui.client.store.StoreListener;
638 jp_milcent 19
import com.extjs.gxt.ui.client.widget.Info;
20
import com.extjs.gxt.ui.client.widget.TabItem;
21
import com.extjs.gxt.ui.client.widget.TabPanel;
687 jp_milcent 22
import com.extjs.gxt.ui.client.widget.button.Button;
858 jpm 23
import com.extjs.gxt.ui.client.widget.form.FieldSet;
24
import com.extjs.gxt.ui.client.widget.form.TextField;
25
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
26
import com.extjs.gxt.ui.client.widget.layout.FormData;
638 jp_milcent 27
import com.google.gwt.core.client.GWT;
28
 
29
public class CollectionForm extends Formulaire implements Rafraichissable {
30
 
31
	private Collection collection = null;
32
	private Collection collectionCollectee = null;
33
 
858 jpm 34
	private ChampComboBoxListeValeurs typesCollectionCombo = null;
638 jp_milcent 35
 
775 jpm 36
	private TabPanel onglets = null;
638 jp_milcent 37
	private TabItem generalOnglet = null;
38
	private TabItem auteurOnglet = null;
687 jp_milcent 39
	private TabItem publicationOnglet = null;
638 jp_milcent 40
	private TabItem descriptionOnglet = null;
41
	private TabItem contenuOnglet = null;
42
	private TabItem inventaireOnglet = null;
858 jpm 43
	private TextField<String> nomChp = null;
687 jp_milcent 44
 
638 jp_milcent 45
	public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {
648 jp_milcent 46
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
858 jpm 47
		creerFieldsetPrincipal();
638 jp_milcent 48
	}
49
 
858 jpm 50
	private void creerFieldsetPrincipal() {
51
		FieldSet principalFieldSet = new FieldSet();
52
		principalFieldSet.setHeading("Info");
53
		principalFieldSet.setCollapsible(true);
54
		principalFieldSet.setLayout(Formulaire.creerFormLayout(150, LabelAlign.LEFT));
55
 
56
		nomChp  = new TextField<String>();
57
		nomChp.setTabIndex(tabIndex++);
58
		nomChp.setFieldLabel(i18nC.nomCollection());
59
		nomChp.setAllowBlank(false);
60
		nomChp.getMessages().setBlankText(i18nC.champObligatoire());
61
		principalFieldSet.add(nomChp, new FormData(450, 0));
62
 
63
		typesCollectionCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionNcd(), "typeCollectionNcd", tabIndex++);
64
		typesCollectionCombo.setValeurDefaut(Valeur.COLLECTION_NCD_HERBIER);
65
		typesCollectionCombo.addListener(Events.Select, new Listener<BaseEvent>() {
66
			@Override
67
			public void handleEvent(BaseEvent be) {
68
				Valeur valeur = typesCollectionCombo.getValue();
69
				panneauFormulaire.remove(onglets);
70
				mediateur.activerChargement("");
71
				if (valeur != null && valeur.getId().equals(Valeur.COLLECTION_NCD_HERBIER)) {
72
					onglets = creerOngletsHerbier();
73
					panneauFormulaire.add(onglets);
74
				} else {
75
					onglets = creerOngletsDefaut();
76
					panneauFormulaire.add(onglets);
77
				}
78
				mediateur.desactiverChargement();
79
				panneauFormulaire.layout();
80
			}
81
		});
82
		principalFieldSet.add(typesCollectionCombo, new FormData(150, 0));
83
		typesCollectionCombo.fireEvent(Events.Select);
84
 
85
		panneauFormulaire.setTopComponent(principalFieldSet);
86
	}
87
 
88
	protected TabPanel creerOngletsDefaut() {
89
		TabPanel ongletsCollectionDefaut = new TabPanel();
90
 
91
		// Onlget formulaire GENERAL
92
		ongletsCollectionDefaut.add(creerOngletGeneral());
93
 
94
		// Onlget formulaire AUTEUR
95
		ongletsCollectionDefaut.add(creerOngletAuteur());
96
 
97
		return ongletsCollectionDefaut;
98
	}
99
 
100
	protected TabPanel creerOngletsHerbier() {
101
		TabPanel ongletsCollectionHerbier = new TabPanel();
638 jp_milcent 102
		// NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner)
858 jpm 103
		ongletsCollectionHerbier.setHeight("100%");
638 jp_milcent 104
 
105
		// Onlget formulaire GENERAL
858 jpm 106
		ongletsCollectionHerbier.add(creerOngletGeneral());
638 jp_milcent 107
 
108
		// Onlget formulaire AUTEUR
858 jpm 109
		ongletsCollectionHerbier.add(creerOngletAuteur());
638 jp_milcent 110
 
687 jp_milcent 111
		// Onlget formulaire PUBLICATION
858 jpm 112
		ongletsCollectionHerbier.add(creerOngletPublication());
687 jp_milcent 113
 
638 jp_milcent 114
		// Onlget formulaire DESCRIPTION
858 jpm 115
		ongletsCollectionHerbier.add(creerOngletDescription());
638 jp_milcent 116
 
117
		// Onlget formulaire CONTENU
858 jpm 118
		ongletsCollectionHerbier.add(creerOngletContenu());
638 jp_milcent 119
 
120
		// Onlget formulaire INVENTAIRE
858 jpm 121
		ongletsCollectionHerbier.add(creerOngletInventaire());
638 jp_milcent 122
 
123
		// Sélection de l'onglet par défaut
858 jpm 124
		ongletsCollectionHerbier.setSelection(contenuOnglet);
638 jp_milcent 125
 
858 jpm 126
		return ongletsCollectionHerbier;
638 jp_milcent 127
	}
128
 
129
	private TabItem creerOngletGeneral() {
687 jp_milcent 130
		generalOnglet = new CollectionFormGeneral(this);
638 jp_milcent 131
		return generalOnglet;
132
	}
133
 
134
	private TabItem creerOngletAuteur() {
703 jp_milcent 135
		auteurOnglet = new CollectionFormAuteur(this);
638 jp_milcent 136
		return auteurOnglet;
137
	}
138
 
687 jp_milcent 139
	private TabItem creerOngletPublication() {
720 jp_milcent 140
		publicationOnglet = new CollectionFormPublication(this);
687 jp_milcent 141
		return publicationOnglet;
142
	}
143
 
638 jp_milcent 144
	private TabItem creerOngletDescription() {
807 jpm 145
		descriptionOnglet = new CollectionFormDescription(this);
638 jp_milcent 146
		return descriptionOnglet;
147
	}
148
 
149
	private TabItem creerOngletContenu() {
858 jpm 150
		contenuOnglet = new CollectionFormContenu(this);
638 jp_milcent 151
		return contenuOnglet;
152
	}
153
 
154
	private TabItem creerOngletInventaire() {
687 jp_milcent 155
		inventaireOnglet = creerOnglet(i18nC.collectionInventaire(), "inventaire");
638 jp_milcent 156
		inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
157
			public void handleEvent(ComponentEvent be) {
158
				//peuplerOngletInventaire();
159
				inventaireOnglet.layout();
160
			}
161
		});
162
 
163
		return inventaireOnglet;
164
	}
165
 
166
	public void rafraichir(Object nouvellesDonnees) {
858 jpm 167
		if (nouvellesDonnees instanceof Information) {
168
			Information info = (Information) nouvellesDonnees;
169
			rafraichirInformation(info);
170
		} else {
171
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
638 jp_milcent 172
		}
858 jpm 173
 
782 jpm 174
		controlerFermetureApresRafraichissement();
638 jp_milcent 175
	}
176
 
687 jp_milcent 177
	private void rafraichirInformation(Information info) {
638 jp_milcent 178
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
179
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
180
		}
181
 
182
		if (info.getType().equals("modif_structure")) {
183
			Info.display("Modification d'une collection", info.toString());
184
		} else if (info.getType().equals("selection_collection")) {
185
			Info.display("Modification d'une collection", info.toString());
186
			if (info.getDonnee(0) != null) {
187
				collection = (Collection) info.getDonnee(0);
188
			}
189
			actualiserPeuplementOnglet();
190
			actualiserTitrePanneau();
191
		}
192
	}
193
 
194
	private void actualiserPeuplementOnglet() {
858 jpm 195
		// TODO : déclencher le peuplement de l'onglet courant
638 jp_milcent 196
	}
197
 
198
	private void actualiserTitrePanneau() {
199
		String titre = i18nC.titreModifFormCollection();
200
		// Composition du titre
201
		titre += " - ID : "+collection.getId();
202
		panneauFormulaire.setHeading(titre);
203
	}
204
 
205
	@Override
775 jpm 206
	protected SelectionListener<ButtonEvent> creerEcouteurValidation() {
638 jp_milcent 207
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
208
			@Override
209
			public void componentSelected(ButtonEvent ce) {
775 jpm 210
				String code = ((Button) ce.getComponent()).getData("code");
211
				if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
782 jpm 212
					soumettreFormulaire();
638 jp_milcent 213
					clicBoutonvalidation = true;
775 jpm 214
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
782 jpm 215
					soumettreFormulaire();
775 jpm 216
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
638 jp_milcent 217
					mediateur.clicMenu(menuIdCourant);
775 jpm 218
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {
219
					reinitialiserFormulaire();
638 jp_milcent 220
				}
221
			}
222
		};
223
 
224
		return ecouteur;
225
	}
226
 
786 jpm 227
	protected boolean soumettreFormulaire() {
638 jp_milcent 228
		// Vérification de la validité des champs du formulaire
786 jpm 229
		boolean fomulaireValide = verifierFormulaire();
230
		if (fomulaireValide) {
638 jp_milcent 231
			// Collecte des données du formulaire
232
			Collection collection = collecterCollection();
233
 
234
			if (mode.equals(MODE_AJOUTER)) {
782 jpm 235
				mediateur.ajouterCollection(this, collection);
638 jp_milcent 236
			} else if (mode.equals(MODE_MODIFIER)) {
237
				if (collection == null) {
238
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
239
				} else {
782 jpm 240
					mediateur.modifierCollection(this, collection);
638 jp_milcent 241
				}
242
			}
243
		}
786 jpm 244
		return fomulaireValide;
638 jp_milcent 245
	}
246
 
775 jpm 247
	protected void reinitialiserFormulaire() {
248
		if (mode.equals(StructureForm.MODE_MODIFIER)) {
249
			mediateur.afficherFormCollection(collection.getId());
250
		} else {
251
			mediateur.afficherFormCollection(null);
252
		}
253
	}
254
 
638 jp_milcent 255
	private Collection collecterCollection() {
256
		collectionCollectee = (Collection) collection.cloner(new Collection());
257
 
258
		collecterOngletGeneral();
259
 
260
		Collection collectionARetourner = null;
261
		if (!collectionCollectee.comparer(collection)) {
262
			collectionARetourner = collection = collectionCollectee;
263
		}
264
		return collectionARetourner;
265
	}
266
 
267
	private void collecterOngletGeneral() {
268
		if (generalOnglet.getData("acces").equals(true)) {
269
 
270
		}
271
	}
272
 
787 jpm 273
	protected boolean verifierFormulaire() {
638 jp_milcent 274
		return true;
275
	}
276
}