Subversion Repositories eFlore/Applications.coel

Rev

Rev 1098 | Rev 1245 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
997 jpm 1
package org.tela_botanica.client.vues.collection;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
import org.tela_botanica.client.Mediateur;
1031 jpm 7
import org.tela_botanica.client.composants.ChampComboBoxMultiSelect;
1239 cyprien 8
import org.tela_botanica.client.composants.InfoLogger;
997 jpm 9
import org.tela_botanica.client.images.Images;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
11
import org.tela_botanica.client.modeles.Information;
12
import org.tela_botanica.client.modeles.Valeur;
13
import org.tela_botanica.client.modeles.ValeurListe;
14
import org.tela_botanica.client.modeles.aDonnee;
15
import org.tela_botanica.client.modeles.collection.Collection;
16
import org.tela_botanica.client.modeles.collection.CollectionACommentaire;
17
import org.tela_botanica.client.modeles.collection.CollectionACommentaireListe;
18
import org.tela_botanica.client.modeles.commentaire.Commentaire;
19
import org.tela_botanica.client.modeles.commentaire.CommentaireListe;
20
import org.tela_botanica.client.util.Debug;
21
import org.tela_botanica.client.vues.FenetreForm;
22
import org.tela_botanica.client.vues.Formulaire;
23
import org.tela_botanica.client.vues.FormulaireBarreValidation;
24
import org.tela_botanica.client.vues.FormulaireOnglet;
25
import org.tela_botanica.client.vues.commentaire.CommentaireForm;
26
 
1031 jpm 27
import com.extjs.gxt.ui.client.Style.SortDir;
997 jpm 28
import com.extjs.gxt.ui.client.event.BaseEvent;
29
import com.extjs.gxt.ui.client.event.ButtonEvent;
30
import com.extjs.gxt.ui.client.event.ComponentEvent;
31
import com.extjs.gxt.ui.client.event.Events;
32
import com.extjs.gxt.ui.client.event.KeyListener;
33
import com.extjs.gxt.ui.client.event.Listener;
34
import com.extjs.gxt.ui.client.event.SelectionListener;
35
import com.extjs.gxt.ui.client.store.ListStore;
36
import com.extjs.gxt.ui.client.store.Store;
37
import com.extjs.gxt.ui.client.store.StoreEvent;
38
import com.extjs.gxt.ui.client.widget.ContentPanel;
39
import com.extjs.gxt.ui.client.widget.Info;
40
import com.extjs.gxt.ui.client.widget.Text;
41
import com.extjs.gxt.ui.client.widget.button.Button;
42
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
43
import com.extjs.gxt.ui.client.widget.form.ComboBox;
44
import com.extjs.gxt.ui.client.widget.form.FormPanel;
45
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
46
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
47
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
48
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
49
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
50
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
51
import com.extjs.gxt.ui.client.widget.grid.Grid;
52
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
53
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
54
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
55
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
56
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
57
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
58
import com.google.gwt.core.client.GWT;
59
 
60
public class CollectionFormCommentaire extends FormulaireOnglet implements Rafraichissable {
61
 
1083 jpm 62
	public static final String ID = "commentaire";
997 jpm 63
	private Collection collection = null;
64
	private static int idGenere = 1;
65
 
66
	private ContentPanel panneauPrincipal = null;
67
	private ToolBar barreOutils = null;
68
	private EditorGrid<CollectionACommentaire> grille;
1031 jpm 69
	private ChampComboBoxMultiSelect<Valeur> typeCombo = null;
997 jpm 70
 
1081 jpm 71
	private CollectionACommentaireListe commentairesAjoutes = null;
72
	private CollectionACommentaireListe commentairesModifies = null;
73
	private CollectionACommentaireListe commentairesSupprimes = null;
997 jpm 74
	private ComboBox<Commentaire> commentairesSaisisComboBox = null;
75
	private Button commentairesBoutonSupprimer = null;
76
	private Button commentairesBoutonModifier = null;
77
 
78
	private static boolean chargementTypesOk = false;
79
	private static boolean chargementCommentairesOk = false;
80
 
81
	private FenetreForm fenetreFormulaire = null;
82
 
83
	public CollectionFormCommentaire(Formulaire formulaireCourrant) {
84
		initialiserOnglet(formulaireCourrant);
1083 jpm 85
		setId(ID);
997 jpm 86
		setText(Mediateur.i18nC.collectionCommentaire());
87
		setStyleAttribute("padding", "0");
88
 
89
		panneauPrincipal = creerPanneauContenantGrille();
90
		barreOutils = creerBarreOutilsGrille();
91
		panneauPrincipal.setTopComponent(barreOutils);
92
		grille = creerGrille();
93
  		panneauPrincipal.add(grille);
94
 
95
		mediateur.obtenirListeValeurEtRafraichir(this, "typeCommentaireCollection");
96
		add(panneauPrincipal);
97
 
98
		initialiser();
99
	}
100
 
101
	private void initialiser() {
1081 jpm 102
		// Remise à zéro des modification dans la liste des commentaires
103
		initialiserGestionCommentaires();
997 jpm 104
 
105
		// Actualisation de l'état des boutons de la barre d'outils
106
		actualiserEtatBoutonsBarreOutils();
107
 
108
		collection = ((CollectionForm) formulaire).collection;
109
	}
110
 
1081 jpm 111
	private void initialiserGestionCommentaires() {
112
		idGenere = 1;
113
		commentairesAjoutes = new CollectionACommentaireListe();
114
		commentairesModifies = new CollectionACommentaireListe();
115
		commentairesSupprimes = new CollectionACommentaireListe();
116
	}
117
 
997 jpm 118
	private void initialiserChargement() {
119
		chargementCommentairesOk = false;
120
	}
121
 
122
	private ContentPanel creerPanneauContenantGrille() {
123
		ContentPanel panneau = new ContentPanel();
124
 
125
		panneau.setHeading(i18nC.collectionCommentaireTitre());
126
		panneau.setIcon(Images.ICONES.table());
127
		panneau.setLayout(new FitLayout());
128
		panneau.setFrame(true);
129
 
130
		return panneau;
131
	}
132
 
133
	private ToolBar creerBarreOutilsGrille() {
134
		ToolBar barreOutils = new ToolBar();
135
 
136
		Button ajouterPersonneBouton = creerBoutonAjouter();
137
		barreOutils.add(ajouterPersonneBouton);
138
 
139
		barreOutils.add(new Text(" ou "));
140
 
141
		commentairesSaisisComboBox = creerComboBoxCommentairesSaisies();
142
		barreOutils.add(commentairesSaisisComboBox);
143
 
144
		barreOutils.add(new SeparatorToolItem());
145
 
146
		commentairesBoutonModifier = creerBoutonModifier();
147
		barreOutils.add(commentairesBoutonModifier);
148
 
149
		barreOutils.add(new SeparatorToolItem());
150
 
151
		commentairesBoutonSupprimer = creerBoutonSupprimer();
152
		barreOutils.add(commentairesBoutonSupprimer);
153
 
154
		barreOutils.add(new SeparatorToolItem());
155
 
156
		Button rafraichirPersonneBouton = creerBoutonRafraichir();
157
		barreOutils.add(rafraichirPersonneBouton);
158
 
159
		return barreOutils;
160
	}
161
 
162
	private Button creerBoutonAjouter() {
163
		Button bouton = new Button(i18nC.ajouter());
164
		bouton.setIcon(Images.ICONES.vcardAjouter());
165
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
166
 
167
			@Override
168
			public void componentSelected(ButtonEvent ce) {
169
				fenetreFormulaire = creerFenetreModaleAvecFormulaireCommentaire(Formulaire.MODE_AJOUTER);
170
				fenetreFormulaire.show();
171
			}
172
		});
173
		return bouton;
174
	}
175
 
176
	private Button creerBoutonModifier() {
177
		Button bouton = new Button(i18nC.modifier());
178
		bouton.setIcon(Images.ICONES.vcardModifier());
179
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
180
			@Override
181
			public void componentSelected(ButtonEvent ce) {
182
				CollectionACommentaire commentaireSaisiSelectionne = grille.getSelectionModel().getSelectedItem();
183
				if (commentaireSaisiSelectionne == null) {
1239 cyprien 184
					InfoLogger.display(i18nC.informationTitreGenerique(), i18nC.selectionnerCommentaire());
997 jpm 185
				} else {
186
					fenetreFormulaire = creerFenetreModaleAvecFormulaireCommentaire(Formulaire.MODE_MODIFIER);
187
					fenetreFormulaire.show();
188
				}
189
			}
190
		});
191
		return bouton;
192
	}
193
 
194
	private FenetreForm creerFenetreModaleAvecFormulaireCommentaire(String mode) {
195
		String commentaireId = null;
196
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
197
			CollectionACommentaire commentaierSaisieSelectionnee = grille.getSelectionModel().getSelectedItem();
198
			commentaireId = commentaierSaisieSelectionnee.getIdCommentaire();
199
		}
200
 
201
		final FenetreForm fenetre = new FenetreForm("");
202
		final CommentaireForm formulaire = creerFormulaireCommentaire(fenetre, commentaireId);
203
		fenetre.add(formulaire);
204
		return fenetre;
205
	}
206
 
207
	private CommentaireForm creerFormulaireCommentaire(final FenetreForm fenetre, String commentaireId) {
208
		CommentaireForm formulaire = new CommentaireForm(mediateur, commentaireId, this);
209
		FormPanel panneauFormulaire = formulaire.getFormulaire();
210
		fenetre.setHeading(panneauFormulaire.getHeading());
211
		panneauFormulaire.setHeaderVisible(false);
212
		panneauFormulaire.setTopComponent(null);
213
 
214
		// FIXME : avec GXT-2.1.0 la redéfinition du bottom component ne marche plus. Nous le cachons et en créeons un dans la fenêtre.
215
		panneauFormulaire.getBottomComponent().hide();
216
		SelectionListener<ButtonEvent> ecouteur = creerEcouteurValidationFormulaireCommentaire(fenetre, formulaire);
217
		final ButtonBar barreValidation = new FormulaireBarreValidation(ecouteur);
218
		fenetre.setBottomComponent(barreValidation);
219
 
220
		return formulaire;
221
	}
222
 
223
	private SelectionListener<ButtonEvent> creerEcouteurValidationFormulaireCommentaire(final FenetreForm fenetre, final CommentaireForm formulaire) {
224
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
225
			@Override
226
			public void componentSelected(ButtonEvent ce) {
227
				String code = ((Button) ce.getComponent()).getData("code");
228
				if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
229
					if (formulaire.soumettreFormulaire()) {
230
						fenetre.hide();
231
					}
232
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
233
					formulaire.soumettreFormulaire();
234
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
235
					fenetre.hide();
236
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {
237
					fenetreFormulaire.hide();
238
					fenetreFormulaire = creerFenetreModaleAvecFormulaireCommentaire(formulaire.mode);
239
					fenetreFormulaire.show();
240
				}
241
			}
242
		};
243
 
244
		return ecouteur;
245
	}
246
 
247
	private Button creerBoutonSupprimer() {
248
		Button bouton = new Button(i18nC.supprimer());
249
		bouton.setIcon(Images.ICONES.vcardSupprimer());
250
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
251
			@Override
252
			public void componentSelected(ButtonEvent ce) {
253
				CollectionACommentaire commentaireSaisiSelectionnee = grille.getSelectionModel().getSelectedItem();
254
				if (commentaireSaisiSelectionnee == null) {
1239 cyprien 255
					InfoLogger.display(i18nC.informationTitreGenerique(), i18nC.selectionnerCommentaire());
997 jpm 256
				} else {
257
					supprimerDansGrille(commentaireSaisiSelectionnee);
258
				}
259
			}
260
		});
261
		return bouton;
262
	}
263
 
264
	private Button creerBoutonRafraichir() {
265
		Button bouton = new Button(i18nC.rafraichir());
266
		bouton.setIcon(Images.ICONES.rafraichir());
267
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
268
			@Override
269
			public void componentSelected(ButtonEvent ce) {
270
				actualiserGrille();
271
			}
272
		});
273
		return bouton;
274
	}
275
 
276
	private ComboBox<Commentaire> creerComboBoxCommentairesSaisies() {
277
		ListStore<Commentaire> commentairesSaisiesStore = new ListStore<Commentaire>();
278
		commentairesSaisiesStore.add(new ArrayList<Commentaire>());
279
 
280
		ComboBox<Commentaire> comboBox = new ComboBox<Commentaire>();
281
		comboBox.setWidth(200);
282
		comboBox.setEmptyText(i18nC.chercherCommentaireSaisi());
283
		comboBox.setTriggerAction(TriggerAction.ALL);
284
		comboBox.setEditable(true);
285
		comboBox.setDisplayField("titre");
286
		comboBox.setStore(commentairesSaisiesStore);
287
		comboBox.addKeyListener(new KeyListener() {
288
			public void componentKeyUp(ComponentEvent ce) {
289
				if (commentairesSaisisComboBox.getRawValue() != null && commentairesSaisisComboBox.getRawValue().length() > 0) {
290
					if (!ce.isNavKeyPress()) {
291
						obtenirCommentairesSaisis(commentairesSaisisComboBox.getRawValue());
292
					}
293
				}
294
			}
295
		});
296
		comboBox.addListener(Events.Select, new Listener<BaseEvent>() {
297
			@Override
298
			public void handleEvent(BaseEvent be) {
299
				if (commentairesSaisisComboBox.getValue() instanceof Commentaire) {
300
					Commentaire commentaireSaisiSelectionnee = commentairesSaisisComboBox.getValue();
301
					ajouterDansGrille(commentaireSaisiSelectionnee);
302
					commentairesSaisisComboBox.setValue(null);
303
				}
304
			}
305
		});
306
		return comboBox;
307
	}
308
 
309
	private void ajouterDansGrille(Commentaire commentaire) {
310
		ajouterDansGrille(commentaire, null, 0);
311
	}
312
 
313
	private void ajouterDansGrille(Commentaire commentaire, String type, int index) {
314
		if (commentaire != null) {
315
			CollectionACommentaire relationCollectionACommentaire = new CollectionACommentaire();
316
			relationCollectionACommentaire.setCommentaire(commentaire);
317
			relationCollectionACommentaire.setIdCommentaire(commentaire.getId());
318
			if (type != null) {
319
				relationCollectionACommentaire.set("_type_", type);
320
			}
321
			// Gestion de l'id de la collection
322
			if (mode.equals(Formulaire.MODE_MODIFIER)) {
323
				relationCollectionACommentaire.setIdCollection(collection.getId());
324
			}
325
			relationCollectionACommentaire.set("_etat_", aDonnee.ETAT_AJOUTE);
326
			corrigerChampsGrille(relationCollectionACommentaire);
327
 
328
			// Ajout à la grille
329
			grille.stopEditing();
330
			grille.getStore().insert(relationCollectionACommentaire, index);
331
			grille.startEditing(index, 0);
332
			grille.getSelectionModel().select(index, false);
333
		}
334
	}
335
 
336
	private void supprimerDansGrille(CollectionACommentaire relationCollectionACommentaire) {
337
		if (relationCollectionACommentaire != null) {
338
			// Ajout de la personne supprimée à la liste
339
			if ((relationCollectionACommentaire.get("_etat_").equals("") || !relationCollectionACommentaire.get("_etat_").equals(aDonnee.ETAT_AJOUTE))
340
					&& relationCollectionACommentaire.getId() != null
341
					&& !relationCollectionACommentaire.getId().equals("")) {
1081 jpm 342
				Debug.log("Nbre commentaires supprimées avant:"+commentairesSupprimes.size());
343
				commentairesSupprimes.put("id"+idGenere++, relationCollectionACommentaire);
997 jpm 344
				Debug.log("Commentaires supprimées : "+relationCollectionACommentaire.getCommentaire().getId());
1081 jpm 345
				Debug.log("Nbre commentaires supprimées :"+commentairesSupprimes.size());
997 jpm 346
			}
347
 
348
			// Suppression de l'enregistrement de la grille
349
			grille.getStore().remove(relationCollectionACommentaire);
350
		}
351
	}
352
 
353
	private EditorGrid<CollectionACommentaire> creerGrille() {
354
		ListStore<CollectionACommentaire> storeGrille = new ListStore<CollectionACommentaire>();
355
		storeGrille.addListener(Store.Add, new Listener<StoreEvent<CollectionACommentaire>>() {
356
			public void handleEvent(StoreEvent<CollectionACommentaire> ce) {
357
				actualiserEtatBoutonsBarreOutils();
358
			}
359
		});
360
		storeGrille.addListener(Store.Remove, new Listener<StoreEvent<CollectionACommentaire>>() {
361
			public void handleEvent(StoreEvent<CollectionACommentaire> ce) {
362
				actualiserEtatBoutonsBarreOutils();
363
			}
364
		});
365
		storeGrille.addListener(Store.Update, new Listener<StoreEvent<CollectionACommentaire>>() {
366
			public void handleEvent(StoreEvent<CollectionACommentaire> ce) {
367
				if (ce.getRecord().isModified("_type_") && !ce.getModel().get("_etat_").equals(aDonnee.ETAT_AJOUTE)) {
368
					Debug.log("id type modifié : "+ce.getModel().get("_type_"));
369
					ce.getModel().set("_etat_", aDonnee.ETAT_MODIFIE);
370
				}
371
			}
372
		});
373
 
374
		RowNumberer pluginLigneNumero = new RowNumberer();
375
 
376
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
377
		colonnes.add(pluginLigneNumero);
378
 
379
		colonnes.add(creerColonneType());
380
		colonnes.add(new ColumnConfig("_titre_", i18nC.commentaireTitre(), 150));
381
		colonnes.add(new ColumnConfig("_texte_", i18nC.commentaireTexte(), 75));
382
		colonnes.add(new ColumnConfig("_ponderation_", i18nC.commentairePonderation(), 35));
383
		colonnes.add(creerColonneAcces());
384
 
385
		GridSelectionModel<CollectionACommentaire> modeleDeSelection = new GridSelectionModel<CollectionACommentaire>();
386
		ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
387
 
388
		EditorGrid<CollectionACommentaire> grille = new EditorGrid<CollectionACommentaire>(storeGrille, modeleDeColonnes);
389
		grille.setHeight("100%");
390
		grille.setBorders(true);
391
		grille.setSelectionModel(modeleDeSelection);
392
		grille.addPlugin(pluginLigneNumero);
393
		grille.getView().setForceFit(true);
394
		grille.setAutoExpandColumn("_titre_");
395
		grille.setStripeRows(true);
396
		grille.setTrackMouseOver(true);
397
 
398
		return grille;
399
	}
400
 
401
	private ColumnConfig creerColonneType() {
1031 jpm 402
		typeCombo = new ChampComboBoxMultiSelect<Valeur>();
997 jpm 403
		typeCombo.setDisplayField("nom");
1031 jpm 404
		typeCombo.setValueField("id_valeur");
997 jpm 405
		typeCombo.setStore(new ListStore<Valeur>());
406
		typeCombo.setEditable(false);
1031 jpm 407
		typeCombo.setForceSelection(true);
997 jpm 408
 
409
		CellEditor typeEditeur = new CellEditor(typeCombo) {
1031 jpm 410
			@SuppressWarnings("unchecked")
997 jpm 411
			@Override
412
			public Object preProcessValue(Object valeur) {
1031 jpm 413
				Valeur retour = new Valeur();
997 jpm 414
				if (valeur != null ) {
1031 jpm 415
					if (valeur instanceof String) {
416
						((ChampComboBoxMultiSelect<Valeur>) getField()).peuplerAvecTexte(valeur.toString());
997 jpm 417
					}
418
				}
419
				return retour;
420
			}
421
 
422
			@Override
423
			public Object postProcessValue(Object valeur) {
424
				String retour = null;
1031 jpm 425
				if (getField().getRawValue() != null ) {
426
					retour = getField().getRawValue();
997 jpm 427
				}
1031 jpm 428
				Debug.log("Post : "+retour);
997 jpm 429
				return retour;
430
			}
431
		};
1031 jpm 432
 
997 jpm 433
		GridCellRenderer<CollectionACommentaire> typeRendu = new GridCellRenderer<CollectionACommentaire>() {
434
			@Override
435
			public String render(CollectionACommentaire model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<CollectionACommentaire> store, Grid<CollectionACommentaire> grid) {
1031 jpm 436
				String type = model.get("_type_");
437
				Debug.log("Initialisation type origine :"+type);
438
				if (typeCombo.getStore() != null && type != null && (type.matches("[0-9]+") || type.contains(aDonnee.SEPARATEUR_VALEURS))) {
439
					type = typeCombo.formaterIdentifiantsEnTexte(type);
440
					model.set("_type_", type);
441
					Debug.log("Initialisation :"+type);
997 jpm 442
				}
443
				return type;
444
			}
445
		};
446
		ColumnConfig typeColonne = new ColumnConfig("_type_", i18nC.commentaireType(), 100);
447
		typeColonne.setEditor(typeEditeur);
448
		typeColonne.setRenderer(typeRendu);
449
		return typeColonne;
450
	}
451
 
452
	private ColumnConfig creerColonneAcces() {
453
		GridCellRenderer<CollectionACommentaire> accesRendu = new GridCellRenderer<CollectionACommentaire>() {
454
			@Override
455
			public String render(CollectionACommentaire model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<CollectionACommentaire> store, Grid<CollectionACommentaire> grid) {
456
				String acces = (model.getCommentaire().etrePublic() ? i18nC.donneePublic() : i18nC.donneePrivee());
457
				model.set("_public_", acces);
458
				return acces;
459
			}
460
		};
461
		ColumnConfig accesColonne = new ColumnConfig("_public_", i18nC.commentairePublic(), 30);
462
		accesColonne.setRenderer(accesRendu);
463
		return accesColonne;
464
	}
465
 
466
	public void actualiserEtatBoutonsBarreOutils() {
467
		// Activation des boutons si la grille contient un élément
468
		if (grille.getStore().getCount() > 0) {
469
			commentairesBoutonSupprimer.enable();
470
			commentairesBoutonModifier.enable();
471
		}
472
		// Désactivation des boutons si la grille ne contient plus d'élément
473
		if (grille.getStore().getCount() == 0) {
474
			commentairesBoutonSupprimer.disable();
475
			commentairesBoutonModifier.disable();
476
		}
477
	}
478
 
479
	public void rafraichir(Object nouvellesDonnees) {
480
		if (nouvellesDonnees instanceof ValeurListe) {
481
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
482
			rafraichirValeurListe(listeValeurs);
483
		} else if (nouvellesDonnees instanceof Information) {
484
			Information info = (Information) nouvellesDonnees;
485
			rafraichirInformation(info);
486
		} else if (nouvellesDonnees instanceof CommentaireListe) {
487
			CommentaireListe listeCommentaires = (CommentaireListe) nouvellesDonnees;
488
			rafraichirCommentairesListe(listeCommentaires);
489
		} else {
490
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
491
		}
492
 
493
		if (chargementTypesOk && chargementCommentairesOk) {
494
			peupler();
495
			initialiserChargement();
496
		}
497
	}
498
 
499
	private void rafraichirValeurListe(ValeurListe listeValeurs) {
500
		if (listeValeurs.getId().equals(config.getListeId("typeCommentaireCollection"))) {
1031 jpm 501
			List<Valeur> liste = listeValeurs.toList();
502
			if (liste.size() > 0) {
503
				ListStore<Valeur> store = typeCombo.getStore();
504
				store.removeAll();
505
				store.add(liste);
506
				store.sort("nom", SortDir.ASC);
507
				typeCombo.setStore(store);
508
			}
997 jpm 509
			chargementTypesOk = true;
510
		} else {
511
			GWT.log("Gestion de la liste "+listeValeurs.getId()+" non implémenté!", null);
512
		}
513
	}
514
 
515
	public void rafraichirInformation(Information info) {
516
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
517
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
518
		}
519
		String type = info.getType();
1098 jpm 520
		if (info.getType().equals("liste_collection_a_commentaire")) {
521
			if (info.getDonnee(0) != null) {
522
				initialiser();
523
				collection.setCommentairesLiees((CollectionACommentaireListe) info.getDonnee(0));
524
				chargementCommentairesOk = true;
525
			}
526
		} else if (info.getType().equals("ajout_collection")) {
997 jpm 527
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
528
				String collectionId = (String) info.getDonnee(0);
529
 
530
				// Suite à la récupération de l'id de la collection nouvellement ajoutée nous ajoutons les personnes liées
531
				// En mode AJOUT, il ne peut que y avoir des personnes liées ajoutées
1081 jpm 532
				mediateur.ajouterCollectionACommentaire(this, collectionId, commentairesAjoutes);
997 jpm 533
			}
534
		} else if (type.equals("commentaire_modifiee")) {
535
			if (info.getDonnee(0) != null) {
536
				Commentaire commentaire = (Commentaire) info.getDonnee(0);
537
				CollectionACommentaire commentaireDansGrille = grille.getStore().findModel("id_commentaire", commentaire.getId());
538
				int index = grille.getStore().indexOf(commentaireDansGrille);
539
				grille.getStore().remove(commentaireDansGrille);
540
				String typeCommentaire = (String) commentaireDansGrille.get("_type_");
541
				ajouterDansGrille(commentaire, typeCommentaire, index);
542
			}
543
		} else if (type.equals("commentaire_ajoutee")) {
544
			if (info.getDonnee(0) != null) {
545
				Commentaire commentaire = (Commentaire) info.getDonnee(0);
546
				ajouterDansGrille(commentaire);
547
			}
548
		} else if (info.getType().equals("modif_collection_a_commentaire")) {
1239 cyprien 549
			InfoLogger.display("Modification des notes liées à la collection", info.toString());
1081 jpm 550
			initialiserGestionCommentaires();
997 jpm 551
		} else if (info.getType().equals("suppression_collection_a_commentaire")) {
1239 cyprien 552
			InfoLogger.display("Suppression des notes liées à la collection", info.toString());
1081 jpm 553
			initialiserGestionCommentaires();
997 jpm 554
		} else if (info.getType().equals("ajout_collection_a_commentaire")) {
1239 cyprien 555
			InfoLogger.display("Ajout des notes liées à la collection", info.toString());
1081 jpm 556
			initialiserGestionCommentaires();
997 jpm 557
		}
558
	}
559
 
560
	private void rafraichirCommentairesListe(CommentaireListe listeCommentaires) {
561
		commentairesSaisisComboBox.getStore().removeAll();
562
		commentairesSaisisComboBox.getStore().add(listeCommentaires.toList());
563
		commentairesSaisisComboBox.expand();
564
	}
565
 
566
	public void peupler() {
567
		grille.getStore().removeAll();
568
		grille.getStore().add(collection.getCommentairesLiees().toList());
1031 jpm 569
		grille.recalculate();
997 jpm 570
		layout();
1239 cyprien 571
		InfoLogger.display(i18nC.chargementCommentaire(), i18nC.ok());
997 jpm 572
	}
573
 
574
	public void collecter() {
575
		if (etreAccede()) {
576
			int nbreCommentaire = grille.getStore().getCount();
577
			for (int i = 0; i < nbreCommentaire; i++) {
578
				CollectionACommentaire relationCollectionACommentaire = grille.getStore().getAt(i);
579
				if (relationCollectionACommentaire.get("_etat_") != null) {
580
					if (relationCollectionACommentaire.get("_etat_").equals(aDonnee.ETAT_MODIFIE)) {
1081 jpm 581
						corrigerChampsGrille(relationCollectionACommentaire);// Nous modifions l'id_type
582
						commentairesModifies.put("id"+idGenere++, relationCollectionACommentaire);
583
						Debug.log("Commentaires modifiés : "+relationCollectionACommentaire.getCommentaire().getTitre());
997 jpm 584
					}
585
					if (relationCollectionACommentaire.get("_etat_").equals(aDonnee.ETAT_AJOUTE)) {
586
						corrigerChampsGrille(relationCollectionACommentaire);// Nous modifions l'id_type
1081 jpm 587
						commentairesAjoutes.put("id"+idGenere++, relationCollectionACommentaire);
997 jpm 588
						Debug.log("Commentaires ajoutés : "+relationCollectionACommentaire.getCommentaire().getTitre());
589
					}
590
					// Initialisation de la grille
591
					relationCollectionACommentaire.set("_etat_", "");
592
				}
593
			}
594
			grille.getStore().commitChanges();
595
		}
596
	}
597
 
598
	private void corrigerChampsGrille(CollectionACommentaire relationCollectionACommentaire) {
599
		String type = relationCollectionACommentaire.get("_type_");
1077 jpm 600
		relationCollectionACommentaire.setType(typeCombo.formaterTexteEnIdentifiants(type));
997 jpm 601
	}
602
 
603
	public void soumettre() {
604
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
1081 jpm 605
			if (commentairesAjoutes.size() == 0 && commentairesModifies.size() == 0 && commentairesSupprimes.size() == 0) {
1239 cyprien 606
				InfoLogger.display("Modification des notes liées", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
997 jpm 607
			} else {
1081 jpm 608
				mediateur.ajouterCollectionACommentaire(this, collection.getId(), commentairesAjoutes);
609
				mediateur.modifierCollectionACommentaire(this, commentairesModifies);
610
				mediateur.supprimerCollectionACommentaire(this, commentairesSupprimes);
997 jpm 611
			}
612
		}
613
	}
614
 
615
	private void obtenirCommentairesSaisis(String titre) {
616
		mediateur.selectionnerCommentaireParTitre(this, titre+"%");
617
	}
618
 
619
	private void actualiserGrille() {
620
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
621
			mediateur.selectionnerCollectionACommentaire(this, collection.getId());
622
		} else {
623
			grille.getStore().removeAll();
624
			layout();
625
		}
626
	}
627
}