Subversion Repositories eFlore/Applications.coel

Rev

Rev 862 | Rev 875 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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