Subversion Repositories eFlore/Applications.coel

Rev

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