Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
991 gduche 1
package org.tela_botanica.client.vues.personne;
2
 
3
import java.util.ArrayList;
1014 gduche 4
import java.util.Iterator;
5
import java.util.LinkedList;
991 gduche 6
import java.util.List;
7
 
1003 gduche 8
import org.tela_botanica.client.ComposantClass;
991 gduche 9
import org.tela_botanica.client.Mediateur;
10
import org.tela_botanica.client.images.Images;
11
import org.tela_botanica.client.interfaces.Rafraichissable;
12
import org.tela_botanica.client.modeles.Information;
1003 gduche 13
import org.tela_botanica.client.modeles.Valeur;
14
import org.tela_botanica.client.modeles.ValeurListe;
991 gduche 15
import org.tela_botanica.client.modeles.aDonnee;
16
import org.tela_botanica.client.modeles.personne.Personne;
17
import org.tela_botanica.client.modeles.publication.Publication;
18
import org.tela_botanica.client.modeles.publication.PublicationAPersonne;
19
import org.tela_botanica.client.modeles.publication.PublicationAPersonneListe;
20
import org.tela_botanica.client.modeles.publication.PublicationListe;
21
import org.tela_botanica.client.util.Debug;
1014 gduche 22
import org.tela_botanica.client.util.UtilString;
991 gduche 23
import org.tela_botanica.client.vues.FenetreForm;
24
import org.tela_botanica.client.vues.Formulaire;
25
import org.tela_botanica.client.vues.FormulaireBarreValidation;
26
import org.tela_botanica.client.vues.FormulaireOnglet;
27
import org.tela_botanica.client.vues.publication.PublicationForm;
28
 
29
import com.extjs.gxt.ui.client.core.XTemplate;
30
import com.extjs.gxt.ui.client.event.BaseEvent;
31
import com.extjs.gxt.ui.client.event.ButtonEvent;
32
import com.extjs.gxt.ui.client.event.ComponentEvent;
33
import com.extjs.gxt.ui.client.event.Events;
34
import com.extjs.gxt.ui.client.event.KeyListener;
35
import com.extjs.gxt.ui.client.event.Listener;
36
import com.extjs.gxt.ui.client.event.SelectionListener;
37
import com.extjs.gxt.ui.client.store.ListStore;
38
import com.extjs.gxt.ui.client.store.Store;
39
import com.extjs.gxt.ui.client.store.StoreEvent;
40
import com.extjs.gxt.ui.client.widget.ContentPanel;
41
import com.extjs.gxt.ui.client.widget.Info;
42
import com.extjs.gxt.ui.client.widget.Text;
43
import com.extjs.gxt.ui.client.widget.button.Button;
44
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
45
import com.extjs.gxt.ui.client.widget.form.ComboBox;
46
import com.extjs.gxt.ui.client.widget.form.FormPanel;
47
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
1003 gduche 48
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
991 gduche 49
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
50
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
51
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
52
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
53
import com.extjs.gxt.ui.client.widget.grid.Grid;
54
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
55
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
56
import com.extjs.gxt.ui.client.widget.grid.RowExpander;
57
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
58
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
59
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
60
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
61
import com.google.gwt.core.client.GWT;
62
 
63
public class PersonneFormPublication extends FormulaireOnglet implements Rafraichissable {
64
 
65
	private Personne personneSelectionnee = null;
66
	private static int idGenere = 1;
67
 
68
	private ContentPanel panneauPrincipal = null;
69
	private ToolBar barreOutils = null;
70
	private EditorGrid<PublicationAPersonne> grille;
71
 
72
	private PublicationAPersonneListe publicationsAjoutees = null;
73
	private PublicationAPersonneListe publicationsSupprimees = null;
74
	private ComboBox<Publication> publicationsSaisiesComboBox = null;
75
	private Button publicationsBoutonSupprimer = null;
76
	private Button publicationsBoutonModifier = null;
1003 gduche 77
	private ComboBox<Valeur> typeRelationCombo = null;
1014 gduche 78
	private List<Valeur> roles = null;
79
	private PublicationAPersonneListe listePublicationsLiees = new PublicationAPersonneListe();
991 gduche 80
 
81
	private FenetreForm fenetreFormulaire = null;
82
 
83
	public PersonneFormPublication(Formulaire formulaireCourrant) {
84
		initialiserOnglet(formulaireCourrant);
85
		setId("publication");
86
		setText(Mediateur.i18nC.collectionPublication());
87
		setStyleAttribute("padding", "0");
88
 
89
		panneauPrincipal = creerPanneauContenantGrille();
90
		barreOutils = creerBarreOutilsGrille();
91
		panneauPrincipal.setTopComponent(barreOutils);
92
		grille = creerGrille();
93
  		panneauPrincipal.add(grille);
94
		add(panneauPrincipal);
95
 
96
		initialiser();
97
	}
98
 
99
	private void initialiser() {
100
		// Remise à zéro des modification dans la liste des auteurs
101
		idGenere = 1;
102
		publicationsAjoutees = new PublicationAPersonneListe();
103
		publicationsSupprimees = new PublicationAPersonneListe();
104
 
105
		// Actualisation de l'état des boutons de la barre d'outils
106
		actualiserEtatBoutonsBarreOutils();
107
	}
108
 
109
	public void mettreAJourPersonne()	{
110
		personneSelectionnee = ((PersonneForm) formulaire).personneSelectionnee;
1014 gduche 111
		//Boucle sur les role pour trouver les publication à personne
1019 gduche 112
		if ((roles != null) && (personneSelectionnee!=null))	{
1014 gduche 113
			mediateur.selectionnerPublicationAPersonne(this, null, personneSelectionnee.getId(), roles);
114
		}
991 gduche 115
	}
116
 
117
	private ContentPanel creerPanneauContenantGrille() {
118
		ContentPanel panneau = new ContentPanel();
119
 
120
		panneau.setHeading(i18nC.collectionPublication()+" " + i18nC.personnePublication());
121
		panneau.setIcon(Images.ICONES.table());
122
		panneau.setLayout(new FitLayout());
123
		panneau.setFrame(true);
124
 
125
		return panneau;
126
	}
127
 
128
	private ToolBar creerBarreOutilsGrille() {
129
		ToolBar barreOutils = new ToolBar();
130
 
131
		Button ajouterBouton = creerBoutonAjouter();
132
		barreOutils.add(ajouterBouton);
133
 
134
		barreOutils.add(new Text(" ou "));
135
 
136
		publicationsSaisiesComboBox = creerComboBoxPublicationsSaisis();
137
		barreOutils.add(publicationsSaisiesComboBox);
138
 
139
		barreOutils.add(new SeparatorToolItem());
140
 
141
		publicationsBoutonModifier = creerBoutonModifier();
142
		barreOutils.add(publicationsBoutonModifier);
143
 
144
		barreOutils.add(new SeparatorToolItem());
145
 
146
		publicationsBoutonSupprimer = creerBoutonSupprimer();
147
		barreOutils.add(publicationsBoutonSupprimer);
148
 
149
		barreOutils.add(new SeparatorToolItem());
150
 
151
		Button rafraichirBouton = creerBoutonRafraichir();
152
		barreOutils.add(rafraichirBouton);
153
 
154
		return barreOutils;
155
	}
156
 
157
	private Button creerBoutonAjouter() {
158
		Button bouton = new Button(i18nC.ajouter());
159
		bouton.setIcon(Images.ICONES.vcardAjouter());
160
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
161
			@Override
162
			public void componentSelected(ButtonEvent ce) {
163
				fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_AJOUTER);
164
				fenetreFormulaire.show();
165
			}
166
		});
167
		return bouton;
168
	}
169
 
170
	private Button creerBoutonModifier() {
171
		Button bouton = new Button(i18nC.modifier());
172
		bouton.setIcon(Images.ICONES.vcardModifier());
173
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
174
			@Override
175
			public void componentSelected(ButtonEvent ce) {
176
				PublicationAPersonne publicationSaisieSelectionnee = grille.getSelectionModel().getSelectedItem();
177
 
178
				if (publicationSaisieSelectionnee == null) {
179
					Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPublication());
180
				} else {
181
					fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_MODIFIER);
182
					fenetreFormulaire.show();
183
				}
184
			}
185
		});
186
		return bouton;
187
	}
188
 
189
	private FenetreForm creerFenetreModaleAvecFormulairePersonne(String mode) {
190
		String publicationId = null;
191
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
192
			PublicationAPersonne publicationSaisiSelectionne = grille.getSelectionModel().getSelectedItem();
193
			publicationId = publicationSaisiSelectionne.getIdPublication();
194
		}
195
 
196
		final FenetreForm fenetre = new FenetreForm("");
197
		final PublicationForm formulaire = creerFormulairePublication(fenetre, publicationId);
198
		fenetre.add(formulaire);
199
		return fenetre;
200
	}
201
 
202
	private PublicationForm creerFormulairePublication(final FenetreForm fenetre, final String publicationId) {
203
		PublicationForm formulairePublication = new PublicationForm(mediateur, publicationId, this);
204
		FormPanel panneauFormulaire = formulairePublication.getFormulaire();
205
		fenetre.setHeading(panneauFormulaire.getHeading());
206
		panneauFormulaire.setHeaderVisible(false);
207
		panneauFormulaire.setTopComponent(null);
208
 
209
		// 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.
210
		panneauFormulaire.getBottomComponent().hide();
211
		SelectionListener<ButtonEvent> ecouteur = creerEcouteurValidationFormulairePublication(fenetre, formulairePublication);
212
		final ButtonBar barreValidation = new FormulaireBarreValidation(ecouteur);
213
		fenetre.setBottomComponent(barreValidation);
214
 
215
		return formulairePublication;
216
	}
217
 
218
	private SelectionListener<ButtonEvent> creerEcouteurValidationFormulairePublication(final FenetreForm fenetre, final PublicationForm formulaire) {
219
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
220
			@Override
221
			public void componentSelected(ButtonEvent ce) {
222
				String code = ((Button) ce.getComponent()).getData("code");
223
				if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
224
					if (formulaire.soumettreFormulaire()) {
225
						fenetre.hide();
226
					}
227
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
228
					formulaire.soumettreFormulaire();
229
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
230
					fenetre.hide();
231
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {
232
					fenetreFormulaire.hide();
233
					fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(formulaire.mode);
234
					fenetreFormulaire.show();
235
				}
236
			}
237
		};
238
 
239
		return ecouteur;
240
	}
241
 
242
	private Button creerBoutonSupprimer() {
243
		Button bouton = new Button(i18nC.supprimer());
244
		bouton.setIcon(Images.ICONES.vcardSupprimer());
245
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
246
			@Override
247
			public void componentSelected(ButtonEvent ce) {
248
				PublicationAPersonne publicationSaisieSelectionnee = grille.getSelectionModel().getSelectedItem();
249
				if (publicationSaisieSelectionnee == null) {
250
					Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPublication());
251
				} else {
252
					supprimerDansGrille(publicationSaisieSelectionnee);
253
				}
254
			}
255
		});
256
		return bouton;
257
	}
258
 
259
	private Button creerBoutonRafraichir() {
260
		Button bouton = new Button(i18nC.rafraichir());
261
		bouton.setIcon(Images.ICONES.rafraichir());
262
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
263
			@Override
264
			public void componentSelected(ButtonEvent ce) {
265
				actualiserGrille();
266
			}
267
		});
268
		return bouton;
269
	}
270
 
271
	private void actualiserGrille() {
272
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
1003 gduche 273
			mediateur.selectionnerPublicationAPersonne(this, null, personneSelectionnee.getId(), "%");
991 gduche 274
		} else {
275
			grille.getStore().removeAll();
276
			layout();
277
		}
278
	}
279
 
280
	private ComboBox<Publication> creerComboBoxPublicationsSaisis() {
281
		ListStore<Publication> publicationsSaisiesStore = new ListStore<Publication>();
282
 
283
		ComboBox<Publication> comboBox = new ComboBox<Publication>();
284
		comboBox.setWidth(400);
285
		comboBox.setEmptyText(i18nC.chercherPublicationSaisi());
286
		comboBox.setTriggerAction(TriggerAction.ALL);
287
		comboBox.setEditable(true);
288
		comboBox.setDisplayField("fmt_nom_complet");
289
		comboBox.setStore(publicationsSaisiesStore);
290
		comboBox.addKeyListener(new KeyListener() {
291
			public void componentKeyUp(ComponentEvent ce) {
292
				if (publicationsSaisiesComboBox.getRawValue() != null && publicationsSaisiesComboBox.getRawValue().length() > 0) {
293
					if (!ce.isNavKeyPress()) {
294
						obtenirPublicationsSaisies(publicationsSaisiesComboBox.getRawValue());
295
					}
296
				}
297
			}
298
		});
299
		comboBox.addListener(Events.Select, new Listener<BaseEvent>() {
300
			@Override
301
			public void handleEvent(BaseEvent be) {
302
				if (publicationsSaisiesComboBox.getValue() instanceof Publication) {
303
					Publication publicationSaisieSelectionne = publicationsSaisiesComboBox.getValue();
304
					ajouterDansGrille(publicationSaisieSelectionne);
305
					publicationsSaisiesComboBox.setValue(null);
306
				}
307
			}
308
		});
309
		return comboBox;
310
	}
311
 
312
	private void ajouterDansGrille(Publication publication) {
313
		ajouterDansGrille(publication, 0);
314
	}
315
 
316
	private void ajouterDansGrille(Publication publication, int index) {
317
		if (publication != null) {
1014 gduche 318
 
319
			if (!listePublicationsLiees.containsKey(publication.getId()))	{
320
				PublicationAPersonne publicationLiee = new PublicationAPersonne();
321
				publicationLiee.setPersonne(personneSelectionnee);
322
				publicationLiee.setPublicationLiee(publication);
323
				publicationLiee.setIdPublication(publication.getId());
324
				publicationLiee.set("_etat_", aDonnee.ETAT_AJOUTE);
325
				listePublicationsLiees.put(publication.getId(), publicationLiee);
326
 
327
				// Ajout à la grille
328
				grille.stopEditing();
329
				grille.getStore().insert(publicationLiee, 0);
330
				grille.startEditing(index, 0);
331
				grille.getSelectionModel().select(index, false);
332
			} else {
333
				Info.display("Information", "La publication choisie existe déjà dans la liste.");
991 gduche 334
			}
335
		}
336
	}
337
 
1014 gduche 338
	/**
339
	 * Met à jour la grille avec les informations contenus dans la variable listePublicationsLiees
340
	 */
341
	private void mettreAJourGrille()	{
342
		grille.getStore().removeAll();
343
		grille.getStore().add(listePublicationsLiees.toList());
344
	}
345
 
991 gduche 346
	private void supprimerDansGrille(PublicationAPersonne publicationLiee) {
347
		if (publicationLiee != null) {
348
			// Ajout de la personne supprimée à la liste
349
			if ((publicationLiee.get("_etat_").equals("") || !publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE))
350
					&& publicationLiee.getId() != null
351
					&& !publicationLiee.getId().equals("")) {
352
				Debug.log("Nbre publications supprimées avant:"+publicationsSupprimees.size());
353
				publicationsSupprimees.put("id"+idGenere++, publicationLiee);
354
				//GWT.log("Publications supprimée : "+publicationLiee.getIdPublication()+" "+publicationLiee.get.getNomComplet(), null);
355
				Debug.log("Nbre publications supprimées :"+publicationsSupprimees.size());
356
			}
357
 
358
			// Suppression de l'enregistrement de la grille
359
			grille.getStore().remove(publicationLiee);
360
		}
361
	}
362
 
363
	private EditorGrid<PublicationAPersonne> creerGrille() {
364
		ListStore<PublicationAPersonne> storeGrille = new ListStore<PublicationAPersonne>();
365
		storeGrille.addListener(Store.Add, new Listener<StoreEvent<PublicationAPersonne>>() {
366
			public void handleEvent(StoreEvent<PublicationAPersonne> ce) {
367
				actualiserEtatBoutonsBarreOutils();
368
			}
369
		});
370
		storeGrille.addListener(Store.Remove, new Listener<StoreEvent<PublicationAPersonne>>() {
371
			public void handleEvent(StoreEvent<PublicationAPersonne> ce) {
372
				actualiserEtatBoutonsBarreOutils();
373
			}
374
		});
375
 
376
		RowNumberer numeroPlugin = new RowNumberer();
377
		numeroPlugin.setHeader("#");
378
 
379
		XTemplate infoTpl = XTemplate.create("<p>"+
380
			"<span style='font-weight:bold;'>"+i18nC.publicationAuteurs()+" :</span> {fmt_auteur}<br />"+
381
			"<span style='font-weight:bold;'>"+i18nC.publicationTitre()+" :</span> {titre}<br />"+
382
			"<span style='font-weight:bold;'>"+i18nC.publicationRevueCollection()+" :</span> {collection}<br />"+
383
			"<span style='font-weight:bold;'>"+i18nC.publicationEditeur()+" :</span> {_editeur_}"+
384
			"</p>");
385
		RowExpander expansionPlugin = new RowExpander();
386
		expansionPlugin.setTemplate(infoTpl);
387
 
388
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
389
		colonnes.add(expansionPlugin);
390
		colonnes.add(numeroPlugin);
1003 gduche 391
 
392
 
393
		typeRelationCombo = new ComboBox<Valeur>();
394
		typeRelationCombo.setForceSelection(true);
395
		typeRelationCombo.setTriggerAction(TriggerAction.ALL);
396
		typeRelationCombo.setDisplayField("nom");
397
		typeRelationCombo.setStore(new ListStore<Valeur>());
398
		typeRelationCombo.setEditable(false);
399
		typeRelationCombo.addStyleName(ComposantClass.OBLIGATOIRE);
400
		typeRelationCombo.addListener(Events.Select, Formulaire.creerEcouteurChampObligatoire());
401
 
402
		CellEditor editeurRelation = new CellEditor(typeRelationCombo) {
403
			@Override
404
			public Object preProcessValue(Object valeur) {
405
				Valeur retour = null;
406
				if (valeur != null ) {
407
					Debug.log(valeur.toString());
408
					if (typeRelationCombo.getStore().findModel("nom", valeur.toString()) != null) {
409
						retour = typeRelationCombo.getStore().findModel("nom", valeur.toString());
410
					} else if (typeRelationCombo.getStore().findModel("abr", valeur.toString()) != null) {
411
						retour = typeRelationCombo.getStore().findModel("abr", valeur.toString());
412
					} else if (typeRelationCombo.getStore().findModel("id_valeur", valeur.toString()) != null) {
413
						retour = typeRelationCombo.getStore().findModel("id_valeur", valeur.toString());
414
					}
415
				}
416
				return retour;
417
			}
418
 
419
			@Override
420
			public Object postProcessValue(Object valeur) {
421
				String retour = null;
422
				if (valeur != null ) {
423
					if (valeur instanceof Valeur) {
424
						Valeur valeurOntologie = (Valeur) valeur;
425
						retour = valeurOntologie.getId();
426
					}
427
				}
428
				return retour;
429
			}
430
		};
431
 
432
		GridCellRenderer<PublicationAPersonne> relationRendu = new GridCellRenderer<PublicationAPersonne>() {
433
			@Override
434
			public String render(PublicationAPersonne modele, String property, ColumnData config, int rowIndex, int colIndex, ListStore<PublicationAPersonne> store, Grid<PublicationAPersonne> grille) {
435
				// Gestion du texte afficher dans la cellule
436
				String role = modele.get("_role_");
1014 gduche 437
				String roleNom = "";
438
				if (typeRelationCombo.getStore() != null && role!=null && role.matches("[0-9]+")) {
439
					roleNom = typeRelationCombo.getStore().findModel("id_valeur", role).getNom();
1003 gduche 440
					role = typeRelationCombo.getStore().findModel("id_valeur", role).getId();
441
				}
442
				modele.set("_role_", role);
1014 gduche 443
				modele.set("_etat_", aDonnee.ETAT_MODIFIE);
444
				return roleNom;
1003 gduche 445
			}
446
		};
447
 
448
 
449
		ColumnConfig typeRelationColonne = new ColumnConfig("_role_", i18nC.typeRelationPersonneCollection(), 75);
450
		typeRelationColonne.setEditor(editeurRelation);
451
		typeRelationColonne.setRenderer(relationRendu);
1014 gduche 452
 
1003 gduche 453
		colonnes.add(typeRelationColonne);
454
 
991 gduche 455
		colonnes.add(new ColumnConfig("fmt_auteur", i18nC.publicationAuteurs(), 150));
456
		colonnes.add(new ColumnConfig("titre", i18nC.publicationTitre(), 150));
457
		colonnes.add(new ColumnConfig("collection", i18nC.publicationRevueCollection(), 75));
458
		colonnes.add(creerColonneEditeur());
459
		colonnes.add(creerColonneAnneePublication());
460
		colonnes.add(new ColumnConfig("indication_nvt", i18nC.publicationNvt(), 75));
461
		colonnes.add(new ColumnConfig("fascicule", i18nC.publicationFascicule(), 75));
462
		colonnes.add(new ColumnConfig("truk_pages", i18nC.publicationPage(), 50));
463
 
464
		GridSelectionModel<PublicationAPersonne> modeleDeSelection = new GridSelectionModel<PublicationAPersonne>();
465
 
466
		ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
467
		modeleDeColonnes.getColumn(0).setWidget(Images.ICONES.information().createImage(), "Info");
468
 
469
		EditorGrid<PublicationAPersonne> grillePublications = new EditorGrid<PublicationAPersonne>(storeGrille, modeleDeColonnes);
470
		grillePublications.setHeight("100%");
471
		grillePublications.setBorders(true);
472
		grillePublications.setSelectionModel(modeleDeSelection);
473
		grillePublications.addPlugin(expansionPlugin);
474
		grillePublications.addPlugin(numeroPlugin);
475
		grillePublications.getView().setForceFit(true);
476
		grillePublications.setAutoExpandColumn("titre");
477
		grillePublications.setStripeRows(true);
478
		grillePublications.setTrackMouseOver(true);
479
 
480
		return grillePublications;
481
	}
482
 
483
	private ColumnConfig creerColonneEditeur() {
484
		GridCellRenderer<PublicationAPersonne> editeurRendu = new GridCellRenderer<PublicationAPersonne>() {
485
			@Override
486
			public String render(PublicationAPersonne model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<PublicationAPersonne> store, Grid<PublicationAPersonne> grid) {
487
				String editeur = model.getPublicationLiee().getNomEditeur();
488
				model.set("_editeur_", editeur);
489
				return editeur;
490
			}
491
		};
492
		ColumnConfig editeurColonne = new ColumnConfig("_editeur_", Mediateur.i18nC.publicationEditeur(), 135);
493
		editeurColonne.setRenderer(editeurRendu);
494
		return editeurColonne;
495
	}
496
 
497
	private ColumnConfig creerColonneAnneePublication() {
498
		GridCellRenderer<PublicationAPersonne> datePublicationRendu = new GridCellRenderer<PublicationAPersonne>() {
499
			@Override
500
			public String render(PublicationAPersonne model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<PublicationAPersonne> store, Grid<PublicationAPersonne> grid) {
501
				String annee = model.getPublicationLiee().getAnneeParution();
502
				model.set("_annee_", annee);
503
				return annee;
504
			}
505
		};
506
		ColumnConfig datePublicationColonne = new ColumnConfig("_annee_", Mediateur.i18nC.publicationDateParution(), 75);
507
		datePublicationColonne.setRenderer(datePublicationRendu);
508
		return datePublicationColonne;
509
	}
510
 
511
	public void actualiserEtatBoutonsBarreOutils() {
512
		// Activation des boutons si la grille contient un élément
513
		if (grille.getStore().getCount() > 0) {
514
			publicationsBoutonSupprimer.enable();
515
			publicationsBoutonModifier.enable();
516
		}
517
		// Désactivation des boutons si la grille ne contient plus d'élément
518
		if (grille.getStore().getCount() == 0) {
519
			publicationsBoutonSupprimer.disable();
520
			publicationsBoutonModifier.disable();
521
		}
522
	}
523
 
524
	public void rafraichir(Object nouvellesDonnees) {
525
		if (nouvellesDonnees instanceof Information) {
526
			Information info = (Information) nouvellesDonnees;
527
			rafraichirInformation(info);
1003 gduche 528
		} else if (nouvellesDonnees instanceof ValeurListe)	{
1014 gduche 529
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
1003 gduche 530
			if (listeValeurs.getId().equals(config.getListeId("relationPersonnePublication")))	{
531
				Formulaire.rafraichirComboBox(listeValeurs, typeRelationCombo);
1014 gduche 532
				roles = listeValeurs.toList();
533
				mettreAJourPersonne();
1003 gduche 534
			}
991 gduche 535
		} else if (nouvellesDonnees instanceof PublicationListe) {
536
			PublicationListe listePublications = (PublicationListe) nouvellesDonnees;
537
			rafraichirPublicationListe(listePublications);
1014 gduche 538
		} else if (nouvellesDonnees instanceof PublicationAPersonneListe) {
539
			PublicationAPersonneListe papl = (PublicationAPersonneListe) nouvellesDonnees;
540
			List<PublicationAPersonne> paplListe = papl.toList();
541
			if (paplListe.size()>0){
542
				Iterator<PublicationAPersonne> it = paplListe.iterator();
543
				while (it.hasNext())	{
544
					PublicationAPersonne pap = it.next();
545
					listePublicationsLiees.put(pap.getPublicationLiee().getId(), pap);
546
				}
547
				mettreAJourGrille();
548
 
549
			}
991 gduche 550
		} else {
551
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
552
		}
553
	}
554
 
555
	private void rafraichirPublicationListe(PublicationListe listePublications) {
556
		publicationsSaisiesComboBox.getStore().removeAll();
557
		publicationsSaisiesComboBox.getStore().add(listePublications.toList());
558
		publicationsSaisiesComboBox.expand();
559
	}
560
 
561
	public void rafraichirInformation(Information info) {
562
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
563
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
564
		}
565
		String type = info.getType();
566
		if (type.equals("publication_liees")) {
567
			if (info.getDonnee(0) != null) {
568
				initialiser();
569
				personneSelectionnee.setPublicationsLiees((PublicationAPersonneListe) info.getDonnee(0));
570
				peupler();
571
			}
572
		} else if (type.equals("publication_modifiee")) {
573
			if (info.getDonnee(0) != null) {
574
				Publication publication = (Publication) info.getDonnee(0);
575
				PublicationAPersonne publicationDansGrille = grille.getStore().findModel("id_publication", publication.getId());
576
				int index = grille.getStore().indexOf(publicationDansGrille);
577
				grille.getStore().remove(publicationDansGrille);
578
				ajouterDansGrille(publication, index);
579
			}
580
		} else if (type.equals("publication_ajoutee")) {
581
			if (info.getDonnee(0) != null) {
582
				Publication publication = (Publication) info.getDonnee(0);
583
				ajouterDansGrille(publication);
584
			}
585
		} else if (type.equals("suppression_collection_a_publication")) {
586
			Info.display("Suppression des publications liées à la collection", info.toString());
587
		} else if (type.equals("ajout_collection_a_publication")) {
588
			Info.display("Ajout des publications liées à la collection", info.toString());
589
		} else {
590
			GWT.log(Mediateur.i18nM.erreurRafraichir(info.getClass(), this.getClass()), null);
591
		}
592
	}
593
 
594
	public void peupler() {
595
		grille.getStore().removeAll();
596
		grille.getStore().add(personneSelectionnee.getPublicationsLiees().toList());
597
		layout();
598
		Info.display(i18nC.chargementPublication(), i18nC.ok());
599
 
600
	}
601
 
602
	public void collecter() {
603
		if (etreAccede()) {
604
			int nbrePublication = grille.getStore().getCount();
605
			for (int i = 0; i < nbrePublication; i++) {
606
				PublicationAPersonne publicationLiee = grille.getStore().getAt(i);
607
				if (publicationLiee.get("_etat_") != null) {
608
					if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_MODIFIE)) {
609
						// Comme il est impossible de modifier les relations nous supprimons l'ancien enregistrement et ajoutons un nouveau avec le nouveau id_role
610
						publicationsSupprimees.put("id"+idGenere++, publicationLiee);
611
						PublicationAPersonne relationAAjouter = (PublicationAPersonne) publicationLiee.cloner(new PublicationAPersonne());
612
						publicationsAjoutees.put("id"+idGenere++, relationAAjouter);
613
						Debug.log(publicationLiee.toString());
614
					}
1014 gduche 615
 
991 gduche 616
					if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE)) {
617
						publicationsAjoutees.put("id"+idGenere++, publicationLiee);
618
						Debug.log(publicationLiee.toString());
619
					}
620
					// Initialisation de la grille
621
					publicationLiee.set("_etat_", "");
1014 gduche 622
 
991 gduche 623
				}
624
			}
625
			grille.getStore().commitChanges();
626
		}
627
	}
628
 
1014 gduche 629
	public List verifier()	{
630
 
631
		List lstMessageErreur = new LinkedList<String>();
632
		//Vérifier les roles
633
		List<PublicationAPersonne> listePublis = grille.getStore().getModels();
634
		Iterator<PublicationAPersonne> itPublis = listePublis.iterator();
635
		while (itPublis.hasNext())	{
636
				PublicationAPersonne publi = itPublis.next();
637
					if (UtilString.isEmpty((String) publi.get("_role_")))	{
1064 gduche 638
						lstMessageErreur.add("Vous devez choisir le rôle de la relation " + (grille.getStore().indexOf(publi) + 1));
1014 gduche 639
					}
640
				}
641
		return lstMessageErreur;
642
	}
643
 
991 gduche 644
	public void soumettre() {
645
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
646
			if (publicationsAjoutees.size() == 0 && publicationsSupprimees.size() == 0) {
647
				Info.display("Modification des publications liées", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
648
			} else {
649
				// Ajout des relations CollectionAPublication
650
				if (publicationsAjoutees.size() != 0) {
651
					//TODO : utiliser le role d'une liste déroulante
1003 gduche 652
					mediateur.ajouterPublicationAPersonne(this, publicationsAjoutees, personneSelectionnee.getId(), null);
991 gduche 653
				}
654
				// Suppression des relations CollectionAPublication
655
				if (publicationsSupprimees.size() != 0) {
656
					mediateur.supprimerPublicationAPersonne(this, publicationsSupprimees);
657
				}
658
			}
659
		}
660
	}
661
 
662
	private void obtenirPublicationsSaisies(String nom) {
1124 jpm 663
		mediateur.selectionnerPublicationParNomComplet(this, null, "%"+nom+"%");
991 gduche 664
	}
665
}