Subversion Repositories eFlore/Applications.coel

Rev

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

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