Subversion Repositories eFlore/Applications.coel

Rev

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

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