Subversion Repositories eFlore/Applications.coel

Rev

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

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