Subversion Repositories eFlore/Applications.coel

Rev

Rev 858 | Rev 862 | 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
858 jpm 122
		ongletsCollectionHerbier.setSelection(contenuOnglet);
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() {
687 jp_milcent 153
		inventaireOnglet = creerOnglet(i18nC.collectionInventaire(), "inventaire");
638 jp_milcent 154
		inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
155
			public void handleEvent(ComponentEvent be) {
156
				//peuplerOngletInventaire();
157
				inventaireOnglet.layout();
158
			}
159
		});
160
 
161
		return inventaireOnglet;
162
	}
163
 
164
	public void rafraichir(Object nouvellesDonnees) {
858 jpm 165
		if (nouvellesDonnees instanceof Information) {
166
			Information info = (Information) nouvellesDonnees;
167
			rafraichirInformation(info);
168
		} else {
169
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
638 jp_milcent 170
		}
858 jpm 171
 
782 jpm 172
		controlerFermetureApresRafraichissement();
638 jp_milcent 173
	}
174
 
687 jp_milcent 175
	private void rafraichirInformation(Information info) {
638 jp_milcent 176
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
177
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
178
		}
179
 
180
		if (info.getType().equals("modif_structure")) {
181
			Info.display("Modification d'une collection", info.toString());
182
		} else if (info.getType().equals("selection_collection")) {
183
			Info.display("Modification d'une collection", info.toString());
184
			if (info.getDonnee(0) != null) {
185
				collection = (Collection) info.getDonnee(0);
186
			}
187
			actualiserPeuplementOnglet();
188
			actualiserTitrePanneau();
189
		}
190
	}
191
 
192
	private void actualiserPeuplementOnglet() {
858 jpm 193
		// TODO : déclencher le peuplement de l'onglet courant
638 jp_milcent 194
	}
195
 
196
	private void actualiserTitrePanneau() {
197
		String titre = i18nC.titreModifFormCollection();
198
		// Composition du titre
199
		titre += " - ID : "+collection.getId();
200
		panneauFormulaire.setHeading(titre);
201
	}
202
 
203
	@Override
775 jpm 204
	protected SelectionListener<ButtonEvent> creerEcouteurValidation() {
638 jp_milcent 205
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
206
			@Override
207
			public void componentSelected(ButtonEvent ce) {
775 jpm 208
				String code = ((Button) ce.getComponent()).getData("code");
209
				if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
782 jpm 210
					soumettreFormulaire();
638 jp_milcent 211
					clicBoutonvalidation = true;
775 jpm 212
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
782 jpm 213
					soumettreFormulaire();
775 jpm 214
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
638 jp_milcent 215
					mediateur.clicMenu(menuIdCourant);
775 jpm 216
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {
217
					reinitialiserFormulaire();
638 jp_milcent 218
				}
219
			}
220
		};
221
 
222
		return ecouteur;
223
	}
224
 
786 jpm 225
	protected boolean soumettreFormulaire() {
638 jp_milcent 226
		// Vérification de la validité des champs du formulaire
786 jpm 227
		boolean fomulaireValide = verifierFormulaire();
228
		if (fomulaireValide) {
638 jp_milcent 229
			// Collecte des données du formulaire
230
			Collection collection = collecterCollection();
231
 
232
			if (mode.equals(MODE_AJOUTER)) {
782 jpm 233
				mediateur.ajouterCollection(this, collection);
638 jp_milcent 234
			} else if (mode.equals(MODE_MODIFIER)) {
235
				if (collection == null) {
236
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
237
				} else {
782 jpm 238
					mediateur.modifierCollection(this, collection);
638 jp_milcent 239
				}
240
			}
241
		}
786 jpm 242
		return fomulaireValide;
638 jp_milcent 243
	}
244
 
775 jpm 245
	protected void reinitialiserFormulaire() {
246
		if (mode.equals(StructureForm.MODE_MODIFIER)) {
247
			mediateur.afficherFormCollection(collection.getId());
248
		} else {
249
			mediateur.afficherFormCollection(null);
250
		}
251
	}
252
 
638 jp_milcent 253
	private Collection collecterCollection() {
254
		collectionCollectee = (Collection) collection.cloner(new Collection());
255
 
256
		collecterOngletGeneral();
257
 
258
		Collection collectionARetourner = null;
259
		if (!collectionCollectee.comparer(collection)) {
260
			collectionARetourner = collection = collectionCollectee;
261
		}
262
		return collectionARetourner;
263
	}
264
 
265
	private void collecterOngletGeneral() {
266
		if (generalOnglet.getData("acces").equals(true)) {
267
 
268
		}
269
	}
270
 
787 jpm 271
	protected boolean verifierFormulaire() {
638 jp_milcent 272
		return true;
273
	}
274
}