Subversion Repositories eFlore/Applications.coel

Rev

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