Subversion Repositories eFlore/Applications.coel

Rev

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