Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
935 jpm 1
package org.tela_botanica.client.vues.publication;
219 aurelien 2
 
227 aurelien 3
import java.util.ArrayList;
4
import java.util.Iterator;
365 jp_milcent 5
import java.util.List;
227 aurelien 6
 
981 jpm 7
import org.tela_botanica.client.ComposantClass;
219 aurelien 8
import org.tela_botanica.client.Mediateur;
1218 cyprien 9
import org.tela_botanica.client.composants.InfoLogger;
822 jpm 10
import org.tela_botanica.client.images.Images;
219 aurelien 11
import org.tela_botanica.client.interfaces.Rafraichissable;
705 aurelien 12
import org.tela_botanica.client.modeles.Information;
775 jpm 13
import org.tela_botanica.client.modeles.MenuApplicationId;
1273 gduche 14
import org.tela_botanica.client.modeles.Valeur;
15
import org.tela_botanica.client.modeles.aDonnee;
935 jpm 16
import org.tela_botanica.client.modeles.personne.Personne;
17
import org.tela_botanica.client.modeles.personne.PersonneListe;
1032 jpm 18
import org.tela_botanica.client.modeles.projet.Projet;
19
import org.tela_botanica.client.modeles.projet.ProjetListe;
935 jpm 20
import org.tela_botanica.client.modeles.publication.Publication;
21
import org.tela_botanica.client.modeles.publication.PublicationAPersonne;
22
import org.tela_botanica.client.modeles.publication.PublicationAPersonneListe;
23
import org.tela_botanica.client.modeles.structure.Structure;
24
import org.tela_botanica.client.modeles.structure.StructureListe;
1131 jpm 25
import org.tela_botanica.client.util.Debug;
792 jpm 26
import org.tela_botanica.client.util.Pattern;
782 jpm 27
import org.tela_botanica.client.util.UtilArray;
884 jpm 28
import org.tela_botanica.client.util.UtilString;
1273 gduche 29
import org.tela_botanica.client.vues.FenetreForm;
935 jpm 30
import org.tela_botanica.client.vues.Formulaire;
1273 gduche 31
import org.tela_botanica.client.vues.FormulaireBarreValidation;
32
import org.tela_botanica.client.vues.personne.PersonneForm;
219 aurelien 33
 
1273 gduche 34
import com.extjs.gxt.ui.client.Style.Scroll;
35
import com.extjs.gxt.ui.client.core.XTemplate;
36
import com.extjs.gxt.ui.client.event.BaseEvent;
505 jp_milcent 37
import com.extjs.gxt.ui.client.event.ButtonEvent;
1273 gduche 38
import com.extjs.gxt.ui.client.event.ComponentEvent;
980 jpm 39
import com.extjs.gxt.ui.client.event.Events;
1273 gduche 40
import com.extjs.gxt.ui.client.event.KeyListener;
41
import com.extjs.gxt.ui.client.event.Listener;
219 aurelien 42
import com.extjs.gxt.ui.client.event.SelectionListener;
43
import com.extjs.gxt.ui.client.store.ListStore;
1273 gduche 44
import com.extjs.gxt.ui.client.store.Store;
45
import com.extjs.gxt.ui.client.store.StoreEvent;
227 aurelien 46
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
1095 jpm 47
import com.extjs.gxt.ui.client.widget.Info;
219 aurelien 48
import com.extjs.gxt.ui.client.widget.LayoutContainer;
705 aurelien 49
import com.extjs.gxt.ui.client.widget.MessageBox;
1273 gduche 50
import com.extjs.gxt.ui.client.widget.Text;
219 aurelien 51
import com.extjs.gxt.ui.client.widget.button.Button;
1273 gduche 52
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
219 aurelien 53
import com.extjs.gxt.ui.client.widget.form.ComboBox;
1032 jpm 54
import com.extjs.gxt.ui.client.widget.form.Field;
219 aurelien 55
import com.extjs.gxt.ui.client.widget.form.FieldSet;
1273 gduche 56
import com.extjs.gxt.ui.client.widget.form.FormPanel;
219 aurelien 57
import com.extjs.gxt.ui.client.widget.form.TextField;
1032 jpm 58
import com.extjs.gxt.ui.client.widget.form.Validator;
219 aurelien 59
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
1273 gduche 60
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
61
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
62
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
63
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
64
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
65
import com.extjs.gxt.ui.client.widget.grid.Grid;
66
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
67
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
68
import com.extjs.gxt.ui.client.widget.grid.RowExpander;
69
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
70
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
219 aurelien 71
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
72
import com.extjs.gxt.ui.client.widget.layout.FormData;
73
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
1273 gduche 74
import com.extjs.gxt.ui.client.widget.layout.RowData;
75
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
76
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
77
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
705 aurelien 78
import com.google.gwt.core.client.GWT;
1273 gduche 79
import com.google.gwt.user.client.Window;
219 aurelien 80
 
877 aurelien 81
 
775 jpm 82
public class PublicationForm extends Formulaire implements Rafraichissable {
219 aurelien 83
 
786 jpm 84
	private Publication publication;
1133 jpm 85
	private PersonneListe auteursInitialListe = null;
901 jpm 86
	private static boolean publicationAPersonneListeChargementOk = false;
1273 gduche 87
	private PersonneListe auteursAjoutes = null;
88
	private PersonneListe auteursSupprimes = null;
219 aurelien 89
 
1273 gduche 90
	private LayoutContainer auteursFieldset = null;
1032 jpm 91
	private ComboBox<Projet> projetsCombo = null;
775 jpm 92
	private ArrayList<ComboBox<Personne>> auteurComboboxListe = null;
93
	private ListStore<Personne> auteursStorePartage = null;
901 jpm 94
	private static boolean auteurStorePartageChargementOk = false;
227 aurelien 95
 
775 jpm 96
	private FieldSet generalitesFieldset = null;
786 jpm 97
	private TextField<String> titreChp = null;
98
	private TextField<String> collectionChp = null;
99
	private TextField<String> uriChp = null;
219 aurelien 100
 
775 jpm 101
	private FieldSet editionFieldset = null;
792 jpm 102
	private ComboBox<Structure> editeurCombobox = null;
1178 jpm 103
	private static boolean editeursOk = false;
786 jpm 104
	private TextField<String> datePublicationChp = null;
105
	private TextField<String> tomeChp = null;
106
	private TextField<String> fasciculeChp = null;
107
	private TextField<String> pagesChp = null;
219 aurelien 108
 
1178 jpm 109
	boolean auteursAffiches = false;
901 jpm 110
	private static boolean formulaireValideOk = false;
111
	private static boolean publicationValideOk = false;
112
	private static boolean auteursValideOk = false;
1131 jpm 113
	private static boolean publicationOk = false;
901 jpm 114
	private static boolean attenteAjoutAuteursOk = true;
115
	private static boolean attenteSuppressionAuteursOk = true;
1273 gduche 116
 
117
	private LayoutContainer zoneHaut, zoneBas;
118
 
119
	private static int idGenere = 1;
120
	private ToolBar barreOutils = null;
121
	private EditorGrid<Personne> grille;
122
	private PersonneListe personnesAjoutees = null;
123
	private PersonneListe personnesSupprimees = null;
124
	private ComboBox<Personne> personnesSaisiesComboBox = null;
125
	private Button personnesBoutonSupprimer = null;
126
	private Button personnesBoutonModifier = null;
127
	private ComboBox<Valeur> typeRelationCombo = null;
128
	private List<Valeur> roles = null;
129
	private PersonneListe listePersonne = new PersonneListe();
130
 
131
	private FenetreForm fenetreFormulaire = null;
132
 
781 jpm 133
	public PublicationForm(Mediateur mediateurCourrant, String publicationId) {
782 jpm 134
		initialiserPublicationForm(mediateurCourrant, publicationId);
135
	}
136
 
137
	public PublicationForm(Mediateur mediateurCourrant, String publicationId, Rafraichissable vueARafraichirApresValidation) {
822 jpm 138
		vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
782 jpm 139
		initialiserPublicationForm(mediateurCourrant, publicationId);
140
	}
141
 
142
	private void initialiserPublicationForm(Mediateur mediateurCourrant, String publicationId) {
1273 gduche 143
 
1133 jpm 144
		auteursInitialListe = new PersonneListe();
901 jpm 145
		initialiserValidation();
146
		initialiserAffichageAuteurs();
147
 
799 jpm 148
		publication = new Publication();
822 jpm 149
		publication.setId(publicationId);
150
 
884 jpm 151
		String modeDeCreation = (UtilString.isEmpty(publication.getId()) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
775 jpm 152
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.PUBLICATION);
1273 gduche 153
		panneauFormulaire.setLayout(new RowLayout());
154
		panneauFormulaire.setStyleAttribute("padding", "0");
155
		zoneHaut = new LayoutContainer(new FitLayout());
156
		zoneBas = new LayoutContainer(new FlowLayout());
781 jpm 157
 
1273 gduche 158
		panneauFormulaire.add(zoneHaut, new RowData(1, 0.3));
159
		panneauFormulaire.add(zoneBas, new RowData(1, 0.5));
160
 
1095 jpm 161
		genererTitreFormulaire();
162
 
775 jpm 163
		creerZoneAuteurs();
1273 gduche 164
		zoneHaut.add(auteursFieldset);
219 aurelien 165
 
775 jpm 166
		creerZoneGeneralites();
1273 gduche 167
		zoneBas.add(generalitesFieldset);
239 aurelien 168
 
775 jpm 169
		creerZoneEdition();
1273 gduche 170
		zoneBas.add(editionFieldset);
822 jpm 171
 
172
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
173
			mediateurCourrant.selectionnerPublication(this, publicationId);
174
			mediateurCourrant.selectionnerPublicationAPersonne(this, publicationId, null, PublicationAPersonne.ROLE_AUTEUR);
175
		}
781 jpm 176
	}
782 jpm 177
 
1273 gduche 178
	public void actualiserEtatBoutonsBarreOutils() {
179
			// Activation des boutons si la grille contient un élément
180
			if (grille.getStore().getCount() > 0) {
181
				personnesBoutonSupprimer.enable();
182
				personnesBoutonModifier.enable();
183
			}
184
			// Désactivation des boutons si la grille ne contient plus d'élément
185
			if (grille.getStore().getCount() == 0) {
186
				personnesBoutonSupprimer.disable();
187
				personnesBoutonModifier.disable();
188
			}
189
		}
190
 
191
	private ToolBar creerBarreOutilsGrille() {
192
		ToolBar barreOutils = new ToolBar();
193
 
194
		Button ajouterBouton = creerBoutonAjouter();
195
		barreOutils.add(ajouterBouton);
196
 
197
		barreOutils.add(new Text(" ou "));
198
 
199
		personnesSaisiesComboBox = creerComboBoxPersonnesSaisies();
200
		barreOutils.add(personnesSaisiesComboBox);
201
 
202
		barreOutils.add(new SeparatorToolItem());
203
 
204
		personnesBoutonModifier = creerBoutonModifier();
205
		barreOutils.add(personnesBoutonModifier);
206
 
207
		barreOutils.add(new SeparatorToolItem());
208
 
209
		personnesBoutonSupprimer = creerBoutonSupprimer();
210
		barreOutils.add(personnesBoutonSupprimer);
211
 
212
		barreOutils.add(new SeparatorToolItem());
213
 
214
		Button rafraichirBouton = creerBoutonRafraichir();
215
		barreOutils.add(rafraichirBouton);
216
 
217
		return barreOutils;
218
	}
219
 
220
	private Button creerBoutonAjouter() {
221
		Button bouton = new Button(i18nC.ajouter());
222
		bouton.setIcon(Images.ICONES.vcardAjouter());
223
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
224
			public void componentSelected(ButtonEvent ce) {
225
				fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_AJOUTER);
226
				fenetreFormulaire.show();
227
			}
228
		});
229
		return bouton;
230
	}
231
 
232
	private Button creerBoutonModifier() {
233
		Button bouton = new Button(i18nC.modifier());
234
		bouton.setIcon(Images.ICONES.vcardModifier());
235
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
236
			public void componentSelected(ButtonEvent ce) {
237
				Personne personneSaisieSelectionnee = grille.getSelectionModel().getSelectedItem();
238
 
239
				if (personneSaisieSelectionnee == null) {
240
					InfoLogger.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPublication());
241
				} else {
242
					fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_MODIFIER);
243
					fenetreFormulaire.show();
244
				}
245
			}
246
		});
247
		return bouton;
248
	}
249
 
250
	private FenetreForm creerFenetreModaleAvecFormulairePersonne(String mode) {
251
		String personneId = null;
252
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
253
			Personne personneSaisieSelectionnee = grille.getSelectionModel().getSelectedItem();
254
			personneId = personneSaisieSelectionnee.getId();
255
		}
256
 
257
		final FenetreForm fenetre = new FenetreForm("");
258
		final PersonneForm formulaire = creerFormulairePersonne(fenetre, personneId);
259
		fenetre.add(formulaire);
260
		return fenetre;
261
	}
262
 
263
	private PersonneForm creerFormulairePersonne(final FenetreForm fenetre, final String personneId) {
264
		PersonneForm formulairePersonne = new PersonneForm(mediateur, personneId, this);
265
		FormPanel panneauFormulaire = formulairePersonne.getFormulaire();
266
		fenetre.setHeading(panneauFormulaire.getHeading());
267
		panneauFormulaire.setHeaderVisible(false);
268
		panneauFormulaire.setTopComponent(null);
269
 
270
		// 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.
271
		panneauFormulaire.getBottomComponent().hide();
272
		SelectionListener<ButtonEvent> ecouteur = creerEcouteurValidationFormulairePersonne(fenetre, formulairePersonne);
273
		final ButtonBar barreValidation = new FormulaireBarreValidation(ecouteur);
274
		fenetre.setBottomComponent(barreValidation);
275
 
276
		return formulairePersonne;
277
	}
278
 
279
	private SelectionListener<ButtonEvent> creerEcouteurValidationFormulairePersonne(final FenetreForm fenetre, final PersonneForm formulaire) {
280
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
281
			public void componentSelected(ButtonEvent ce) {
282
				String code = ((Button) ce.getComponent()).getData("code");
283
				if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
284
					if (formulaire.soumettreFormulaire()) {
285
						fenetre.hide();
286
					}
287
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
288
					formulaire.soumettreFormulaire();
289
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
290
					fenetre.hide();
291
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {
292
					fenetreFormulaire.hide();
293
					fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(formulaire.mode);
294
					fenetreFormulaire.show();
295
				}
296
			}
297
		};
298
 
299
		return ecouteur;
300
	}
301
 
302
	private Button creerBoutonSupprimer() {
303
		Button bouton = new Button(i18nC.supprimer());
304
		bouton.setIcon(Images.ICONES.vcardSupprimer());
305
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
306
			public void componentSelected(ButtonEvent ce) {
307
				Personne personneSaisieSelectionnee = grille.getSelectionModel().getSelectedItem();
308
				if (personneSaisieSelectionnee == null) {
309
					InfoLogger.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPublication());
310
				} else {
311
					supprimerDansGrille(personneSaisieSelectionnee);
312
				}
313
			}
314
		});
315
		return bouton;
316
	}
317
 
318
	private Button creerBoutonRafraichir() {
319
		Button bouton = new Button(i18nC.rafraichir());
320
		bouton.setIcon(Images.ICONES.rafraichir());
321
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
322
			public void componentSelected(ButtonEvent ce) {
323
				actualiserGrille();
324
			}
325
		});
326
		return bouton;
327
	}
328
 
329
	private void actualiserGrille() {
330
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
331
			// FIXME : c'est la merde
332
			//mediateur.selectionner(this, null, personneSelectionnee.getId(), "%");
333
		} else {
334
			grille.getStore().removeAll();
335
			layout();
336
		}
337
	}
338
 
339
	private ComboBox<Personne> creerComboBoxPersonnesSaisies() {
340
		ListStore<Personne> personnesSaisiesStore = new ListStore<Personne>();
341
 
342
		ComboBox<Personne> comboBox = new ComboBox<Personne>();
343
		comboBox.setWidth(400);
344
		comboBox.setEmptyText(i18nC.chercherPersonneSaisi());
345
		comboBox.setTriggerAction(TriggerAction.ALL);
346
		comboBox.setEditable(true);
347
		comboBox.setDisplayField("fmt_nom_complet");
348
		comboBox.setStore(personnesSaisiesStore);
349
		comboBox.addKeyListener(new KeyListener() {
350
			public void componentKeyUp(ComponentEvent ce) {
351
				if (personnesSaisiesComboBox.getRawValue() != null && personnesSaisiesComboBox.getRawValue().length() > 0) {
352
					if (!ce.isNavKeyPress()) {
353
						obtenirPersonnesSaisies(personnesSaisiesComboBox.getRawValue());
354
					}
355
				}
356
			}
357
		});
358
		comboBox.addListener(Events.Select, new Listener<BaseEvent>() {
359
			public void handleEvent(BaseEvent be) {
360
				if (personnesSaisiesComboBox.getValue() instanceof Personne) {
361
					// N'ajouter l'auteur que s'il n'est pas déjà présent dans la grille et dans les valeurs initiales
362
					Personne personneSaisieSelectionne = personnesSaisiesComboBox.getValue();
363
					if (grille.getStore().findModel(personneSaisieSelectionne) != null)	{
364
						Info.display("Information", "La personne est déjà présente dans la liste d'auteurs");
365
					} else {
366
						if (!auteursInitialListe.containsValue(personneSaisieSelectionne))	{
367
							auteursAjoutes.put(personneSaisieSelectionne.getId(), personneSaisieSelectionne);
368
						}
369
						ajouterDansGrille(personneSaisieSelectionne);
370
						personnesSaisiesComboBox.setValue(null);
371
					}
372
				}
373
			}
374
		});
375
		return comboBox;
376
	}
377
 
378
	private void obtenirPersonnesSaisies(String nom) {
379
		mediateur.selectionnerPersonneParNomComplet(this, null, nom+"%");
380
	}
381
 
382
	private void ajouterDansGrille(Personne personne) {
383
		ajouterDansGrille(personne, 0);
384
	}
385
 
386
	private void ajouterDansGrille(Personne personne, int index) {
387
		if (personne != null) {
388
			if (!grille.getStore().contains(personne))	{
389
				//1) si elle ne fait pas partie des initiaux, ajouter à la liste à ajouter
390
				if (!auteursInitialListe.containsValue(personne))	{
391
					auteursAjoutes.put(personne.getId(), personne);
392
				}
393
 
394
				// L'enlever de la liste à supprimer
395
				if (auteursSupprimes.containsValue(personne))	{
396
					auteursSupprimes.remove(personne);
397
				}
398
				//2) Ajouter a la grille
399
				grille.getStore().insert(personne, index);
400
				grille.getSelectionModel().select(index, false);
401
			} else {
402
				InfoLogger.display("Information", "La personne choisie existe déjà dans la liste.");
403
			}
404
		}
405
	}
406
 
407
	/**
408
	 * Met à jour la grille avec les informations contenus dans la variable listePublicationsLiees
409
	 */
410
	private void mettreAJourGrille()	{
411
 
412
		grille.getStore().removeAll();
413
		grille.getStore().add(listePersonne.toList());
414
	}
415
 
416
	private void supprimerDansGrille(Personne personne) {
417
		if (personne != null) {
418
			//1) Ajouter a la liste des personne à supprimer uniquement si est présente dans la liste initiale
419
			if (auteursInitialListe.containsValue(personne)) {
420
				auteursSupprimes.put(personne.getId(), personne);
421
			}
422
 
423
			if (auteursAjoutes.containsValue(personne))	{
424
				auteursAjoutes.remove(personne);
425
			}
426
 
427
			//2) Supprimer la personne de la liste
428
			grille.getStore().remove(personne);
429
		} else {
430
			Info.display("Information", "Vous devez sélectionner une personne");
431
		}
432
	}
433
 
434
	private EditorGrid<Personne> creerGrille() {
435
 
436
		ListStore<Personne> storeGrille = new ListStore<Personne>();
437
		storeGrille.addListener(Store.Add, new Listener<StoreEvent<Personne>>() {
438
			public void handleEvent(StoreEvent<Personne> ce) {
439
				actualiserEtatBoutonsBarreOutils();
440
			}
441
		});
442
 
443
		storeGrille.addListener(Store.Remove, new Listener<StoreEvent<Personne>>() {
444
			public void handleEvent(StoreEvent<Personne> ce) {
445
				actualiserEtatBoutonsBarreOutils();
446
			}
447
		});
448
 
449
		storeGrille.addListener(Store.Update, new Listener<StoreEvent<Personne>>() {
450
			public void handleEvent(StoreEvent<Personne> ce) {
451
				if (ce.getRecord().isModified("_role_") && !ce.getModel().get("_etat_").equals(aDonnee.ETAT_AJOUTE)) {
452
					ce.getModel().set("_etat_", aDonnee.ETAT_MODIFIE);
453
				}
454
			}
455
		});
456
 
457
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
458
		colonnes.add(new ColumnConfig("fmt_nom_complet", i18nC.personneNomComplet(), 150));
459
		colonnes.add(new ColumnConfig("code_postal", i18nC.personneCodePostal(), 150));
460
		colonnes.add(new ColumnConfig("ville", i18nC.personneVille(), 75));
461
		colonnes.add(new ColumnConfig("truk_courriel", i18nC.personneCourriel(), 75));
462
 
463
		GridSelectionModel<Personne> modeleDeSelection = new GridSelectionModel<Personne>();
464
 
465
		ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
466
 
467
		EditorGrid<Personne> grillePublications = new EditorGrid<Personne>(storeGrille, modeleDeColonnes);
468
		grillePublications.setHeight("100%");
469
		grillePublications.setBorders(true);
470
		grillePublications.setSelectionModel(modeleDeSelection);
471
		grillePublications.getView().setForceFit(true);
472
		grillePublications.setAutoExpandColumn("fmt_nom_complet");
473
		grillePublications.setStripeRows(true);
474
		grillePublications.setTrackMouseOver(true);
475
 
476
		return grillePublications;
477
	}
478
 
1095 jpm 479
	private void genererTitreFormulaire() {
989 jpm 480
		String titre = i18nC.publicationTitreFormAjout();
822 jpm 481
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
1095 jpm 482
			 titre = i18nC.publicationTitreFormModif();
483
			 if (publication != null) {
1218 cyprien 484
				 titre += " - "+i18nC.id()+": "+publication.getId()+" - "+publication.getObjetDeLaPublication();
1095 jpm 485
			 }
822 jpm 486
		}
1095 jpm 487
		panneauFormulaire.setHeading(titre);
822 jpm 488
	}
1218 cyprien 489
 
822 jpm 490
 
775 jpm 491
	private void creerZoneAuteurs() {
492
		// Fieldset Auteur
1273 gduche 493
		auteursFieldset = new LayoutContainer(new FitLayout());
775 jpm 494
		auteurComboboxListe = new ArrayList<ComboBox<Personne>>(0);
792 jpm 495
		mediateur.clicObtenirListeAuteurs(this);
775 jpm 496
 
822 jpm 497
		creerChampsAuteur();
775 jpm 498
	}
499
 
822 jpm 500
	private void creerChampsAuteur() {
775 jpm 501
		auteursFieldset.removeAll();
1273 gduche 502
		barreOutils = creerBarreOutilsGrille();
503
		panneauFormulaire.setTopComponent(barreOutils);
504
		grille = creerGrille();
505
		auteursFieldset.add(grille);
1131 jpm 506
		auteursFieldset.layout();
775 jpm 507
	}
508
 
822 jpm 509
	public void creerChampAuteurEtBoutonSupprimer(Personne auteur) {
1273 gduche 510
		/*final HorizontalPanel panneauHorizontal = new HorizontalPanel();
1134 jpm 511
 
512
		LayoutContainer panneauChampTxt = new LayoutContainer();
513
		panneauChampTxt.setLayout(new FormLayout());
514
 
775 jpm 515
		final ComboBox<Personne> auteursSaisisComboBox = creerComboBoxAuteursSaisis();
516
		if (auteur != null) {
1131 jpm 517
			auteursSaisisComboBox.setValue(auteur);
901 jpm 518
			auteursSaisisComboBox.validate();
775 jpm 519
		}
520
		auteurComboboxListe.add(auteursSaisisComboBox);
989 jpm 521
		auteursSaisisComboBox.setFieldLabel(i18nC.publicationAuteurSingulier()+" "+auteurComboboxListe.size());
1134 jpm 522
		panneauChampTxt.add(auteursSaisisComboBox, new FormData(300, 0));
523
		panneauHorizontal.add(panneauChampTxt);
758 aurelien 524
 
822 jpm 525
		Button supprimerAuteurBouton = new Button();
526
		supprimerAuteurBouton.setIcon(Images.ICONES.supprimer());
527
		supprimerAuteurBouton.setToolTip(i18nC.supprimer());
528
		supprimerAuteurBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
775 jpm 529
			@Override
530
			public void componentSelected(ButtonEvent be) {
531
				auteurComboboxListe.remove(auteursSaisisComboBox);
532
				conteneurChamps.remove(panneauHorizontal);
822 jpm 533
 
534
				int numeroAuteurs = 1;
535
				for (Iterator<ComboBox<Personne>> it = auteurComboboxListe.iterator(); it.hasNext();) {
989 jpm 536
					it.next().setFieldLabel(i18nC.publicationAuteurSingulier()+" "+numeroAuteurs);
822 jpm 537
					numeroAuteurs++;
538
				}
539
 
1131 jpm 540
				auteursFieldset.layout();
775 jpm 541
			}
542
		});
822 jpm 543
		panneauHorizontal.add(supprimerAuteurBouton);
1134 jpm 544
 
775 jpm 545
		conteneurChamps.add(panneauHorizontal);
1273 gduche 546
		auteursFieldset.layout();*/
775 jpm 547
	}
548
 
549
	private ComboBox<Personne> creerComboBoxAuteursSaisis() {
1134 jpm 550
		ListStore<Personne> auteursStore = new ListStore<Personne>();
551
		auteursStore.add(auteursStorePartage.getModels());
552
 
775 jpm 553
		ComboBox<Personne> comboBox = new ComboBox<Personne>();
860 jpm 554
		comboBox.setEmptyText(i18nC.chercherPersonneSaisi());
775 jpm 555
		comboBox.setEditable(true);
1131 jpm 556
		comboBox.setAllowBlank(false);
775 jpm 557
		comboBox.setForceSelection(true);
558
		comboBox.setDisplayField("fmt_nom_complet");
559
		comboBox.setTriggerAction(TriggerAction.ALL);
1134 jpm 560
		comboBox.setStore(auteursStore);
1174 jpm 561
		comboBox.setMessageTarget("tooltip");
981 jpm 562
		comboBox.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 563
		comboBox.addListener(Events.Valid, creerEcouteurChampObligatoire());
775 jpm 564
 
565
		return comboBox;
566
	}
567
 
568
	private void creerZoneGeneralites() {
569
		FormLayout layout = new FormLayout();
570
		layout.setLabelWidth(200);
219 aurelien 571
 
572
		// Fieldset Infos Générales
775 jpm 573
		generalitesFieldset = new FieldSet();
574
		generalitesFieldset.setHeading("Informations générales");
575
		generalitesFieldset.setCollapsible(true);
576
		generalitesFieldset.setLayout(layout);
219 aurelien 577
 
1032 jpm 578
		projetsCombo = new ComboBox<Projet>();
579
		projetsCombo.setTabIndex(tabIndex++);
580
		projetsCombo.setFieldLabel(i18nC.projetChamp());
581
		projetsCombo.setDisplayField("nom");
582
		projetsCombo.setForceSelection(true);
583
		projetsCombo.setValidator(new Validator() {
584
			public String validate(Field<?> field, String value) {
585
				String retour = null;
586
				if (field.getRawValue().equals("")) {
587
					field.setValue(null);
588
				} else if (projetsCombo.getStore().findModel("nom", field.getRawValue()) == null) {
589
					String contenuBrut = field.getRawValue();
590
					field.setValue(null);
591
					field.setRawValue(contenuBrut);
592
					retour = "Veuillez sélectionner une valeur ou laisser le champ vide";
593
				}
594
				return retour;
595
			}
596
		});
597
		projetsCombo.setTriggerAction(TriggerAction.ALL);
598
		projetsCombo.setStore(new ListStore<Projet>());
599
		projetsCombo.addStyleName(ComposantClass.OBLIGATOIRE);
600
		projetsCombo.addListener(Events.Valid, Formulaire.creerEcouteurChampObligatoire());
601
		generalitesFieldset.add(projetsCombo, new FormData(450, 0));
602
		mediateur.selectionnerProjet(this, null);
603
 
786 jpm 604
		titreChp = new TextField<String>();
605
		titreChp.setName("cpu");
606
		titreChp.setFieldLabel("Titre de l'article ou de l'ouvrage");
981 jpm 607
		titreChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 608
		titreChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
792 jpm 609
		generalitesFieldset.add(titreChp, new FormData(450, 0));
219 aurelien 610
 
786 jpm 611
		collectionChp = new TextField<String>();
792 jpm 612
		collectionChp.setFieldLabel("Intitulé de la revue ou de la collection");
613
		generalitesFieldset.add(collectionChp, new FormData(450, 0));
219 aurelien 614
 
786 jpm 615
		uriChp = new TextField<String>();
792 jpm 616
		uriChp.setFieldLabel("URL de la publication");
617
		generalitesFieldset.add(uriChp, new FormData(450, 0));
775 jpm 618
	}
619
 
620
	private void creerZoneEdition() {
621
		FormLayout layout = new FormLayout();
622
		layout.setLabelWidth(200);
623
 
219 aurelien 624
		// Fieldset Edition
775 jpm 625
		editionFieldset = new FieldSet();
792 jpm 626
		editionFieldset.setHeading("Édition");
775 jpm 627
		editionFieldset.setCollapsible(true);
628
		editionFieldset.setLayout(layout);
219 aurelien 629
 
792 jpm 630
		ListStore<Structure> editeurStore = new ListStore<Structure>();
631
		editeurCombobox = new ComboBox<Structure>();
632
		editeurCombobox.setEmptyText("Sélectionner un éditeur...");
633
		editeurCombobox.setFieldLabel("Éditeur de la publication");
634
		editeurCombobox.setDisplayField("nom");
635
		editeurCombobox.setStore(editeurStore);
636
		editeurCombobox.setEditable(true);
637
		editeurCombobox.setTriggerAction(TriggerAction.ALL);
638
		editionFieldset.add(editeurCombobox, new FormData(450, 0));
639
		mediateur.clicObtenirListeEditeurs(this);
219 aurelien 640
 
786 jpm 641
		datePublicationChp = new TextField<String>();
642
		datePublicationChp.setMaxLength(4);
643
		datePublicationChp.setMinLength(4);
644
		datePublicationChp.setFieldLabel("Année de publication");
981 jpm 645
		datePublicationChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 646
		datePublicationChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
792 jpm 647
		editionFieldset.add(datePublicationChp, new FormData(40, 0));
219 aurelien 648
 
786 jpm 649
		tomeChp = new TextField<String>();
792 jpm 650
		tomeChp.setFieldLabel("Série de la revue ou tome");
651
		editionFieldset.add(tomeChp, new FormData(75, 0));
219 aurelien 652
 
786 jpm 653
		fasciculeChp = new TextField<String>();
792 jpm 654
		fasciculeChp.setFieldLabel("Fascicule de la revue");
655
		editionFieldset.add(fasciculeChp, new FormData(75, 0));
219 aurelien 656
 
786 jpm 657
		pagesChp = new TextField<String>();
658
		pagesChp.setFieldLabel("Pages");
887 aurelien 659
		pagesChp.setToolTip("Fomat : NBRE ou NBRE-NBRE. ('NBRE' correspond à une suite de chiffres arabes ou romains ou à un point d'interrogation '?' dans le cas d'une donnée inconnue)");
792 jpm 660
		editionFieldset.add(pagesChp, new FormData(100, 0));
219 aurelien 661
	}
775 jpm 662
 
705 aurelien 663
	public void rafraichir(Object nouvellesDonnees) {
664
		if (nouvellesDonnees instanceof Publication) {
782 jpm 665
			// Si on a reçu les details d'une publication
666
			rafraichirPublication((Publication) nouvellesDonnees);
667
		} else if (nouvellesDonnees instanceof StructureListe) {
668
			// Si on a reçu une liste des editeurs
669
			rafraichirListeEditeurs((StructureListe) nouvellesDonnees);
670
		} else if (nouvellesDonnees instanceof PublicationAPersonneListe) {
671
			rafraichirListeAuteurs((PublicationAPersonneListe) nouvellesDonnees);
672
		} else if (nouvellesDonnees instanceof Information) {
673
			rafraichirInformation((Information) nouvellesDonnees);
1032 jpm 674
		} else if (nouvellesDonnees instanceof ProjetListe) {
675
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
676
			Formulaire.rafraichirComboBox(projets, projetsCombo);
677
			setValeurComboProjets();
782 jpm 678
		} else {
679
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
227 aurelien 680
		}
681
 
1178 jpm 682
		synchronisation();
683
	}
684
 
685
	private void synchronisation() {
686
		// Respecter l'ordre et faire attention à la réinitialisation des jetons
687
		// 1. gestion des auteurs (Modif ou Ajout)
688
		// 2. peupler le formulaire (Modif)
689
		// 3. initialisation de la gestion des auteurs ajoutés/supprimés (Modif)
690
		// 4. valider le formulaire (Modif ou Ajout)
691
 
822 jpm 692
		if (etrePretAAfficherAuteurs()) {
1131 jpm 693
			afficherAuteurs();
901 jpm 694
			initialiserAffichageAuteurs();
822 jpm 695
		}
1178 jpm 696
 
697
		if (etrePretAPeupler()) {
698
			peuplerFormulaire();
699
			genererTitreFormulaire();
700
			initialiserPeupler();
1174 jpm 701
		}
822 jpm 702
 
1178 jpm 703
		if (avoirAuteursMiseAJourCorrectement()) {
704
			miseAJourAuteursInitialListe();
705
			initialiserAuteurs();
706
			auteursValideOk = true;
707
		}
708
 
782 jpm 709
		if (etreValide()) {
822 jpm 710
			initialiserValidation();
782 jpm 711
			repandreRafraichissement();
1218 cyprien 712
			controlerFermeture();
219 aurelien 713
		}
782 jpm 714
	}
901 jpm 715
 
1133 jpm 716
	private void miseAJourAuteursInitialListe() {
901 jpm 717
		Iterator<String> clesAjoutees = auteursAjoutes.keySet().iterator();
718
		while (clesAjoutees.hasNext()) {
1273 gduche 719
			Personne auteurAjoute = auteursAjoutes.get(clesAjoutees.next());
1133 jpm 720
			auteursInitialListe.put(auteurAjoute.getId(), auteurAjoute);
901 jpm 721
		}
722
 
723
		Iterator<String> clesSupprimees = auteursSupprimes.keySet().iterator();
724
		while (clesSupprimees.hasNext()) {
1273 gduche 725
			Personne auteurSupprime = auteursSupprimes.get(clesSupprimees.next());
1133 jpm 726
			auteursInitialListe.remove(auteurSupprime.getId());
901 jpm 727
		}
728
	}
729
 
786 jpm 730
	private void rafraichirPublication(Publication publi) {
1131 jpm 731
		publicationOk = true;
786 jpm 732
		publication = publi;
782 jpm 733
	}
734
 
735
	private void rafraichirListeEditeurs(StructureListe editeurs) {
1178 jpm 736
		editeursOk = true;
792 jpm 737
		editeurCombobox.getStore().removeAll();
738
		editeurCombobox.getStore().add((List<Structure>) editeurs.toList());
782 jpm 739
	}
740
 
741
	private void rafraichirListeAuteurs(PublicationAPersonneListe auteurs) {
1133 jpm 742
		Iterator<String> it = auteurs.keySet().iterator();
743
		while (it.hasNext()) {
744
			Personne auteur = auteurs.get(it.next()).getPersonne();
745
			auteursInitialListe.put(auteur.getId(), auteur);
746
		}
1273 gduche 747
 
748
		grille.getStore().removeAll();
749
		grille.getStore().add(auteursInitialListe.toList());
750
 
822 jpm 751
		publicationAPersonneListeChargementOk = true;
782 jpm 752
	}
753
 
1255 cyprien 754
	private void rafraichirInformation(Information info) {
1095 jpm 755
		String type = info.getType();
756
		if (type.equals("ajout_publication") || type.equals("modif_publication")) {
1273 gduche 757
			// On vient de soumettre le formulaire, on doit passer à l'étape suivante:
758
			// Validation des auteurs ou fermeture du formulaire
1095 jpm 759
			publicationValideOk = true;
760
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
1182 jpm 761
				if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
762
					String publicationId = (String) info.getDonnee(0);
763
					if (publicationId.matches("[0-9]+")) {
764
						publication.setId(publicationId);
765
					}
766
				}
1255 cyprien 767
				attenteAjoutAuteursOk = true;
1095 jpm 768
			}
1273 gduche 769
			soumettreAuteurs();
1095 jpm 770
		}
771
 
1273 gduche 772
 
782 jpm 773
		if (info.getType().equals("liste_personne")) {
822 jpm 774
			PersonneListe listePersonneAuteur = (PersonneListe) info.getDonnee(0);
775
 
1273 gduche 776
			/*List<Personne> liste = listePersonneAuteur.toList();
782 jpm 777
			auteursStorePartage.removeAll();
778
			auteursStorePartage.add(liste);
1273 gduche 779
			auteurStorePartageChargementOk = true;*/
780
 
781
			ListStore store = personnesSaisiesComboBox.getStore();
782
			store.removeAll();
783
			store.add(listePersonneAuteur.toList());
784
 
901 jpm 785
		} else if (info.getType().equals("ajout_publication_a_personne")) {
786
			attenteAjoutAuteursOk = false;
787
		} else if (info.getType().equals("suppression_publication_a_personne")) {
788
			attenteSuppressionAuteursOk = false;
1095 jpm 789
		} else if (info.getType().equals("modif_publication")) {
1218 cyprien 790
			InfoLogger.display("Modification d'une publication", info.toString());
1095 jpm 791
		} else if (info.getType().equals("ajout_publication")) {
1182 jpm 792
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String && ((String) info.getDonnee(0)).matches("[0-9]+")) {
1095 jpm 793
				String publicationId = (String) info.getDonnee(0);
1218 cyprien 794
				InfoLogger.display("Ajout d'une publication", "La publication '"+publicationId+"' a bien été ajoutée");
1095 jpm 795
			} else {
1218 cyprien 796
				InfoLogger.display("Ajout d'une publication", info.toString());
1095 jpm 797
			}
1255 cyprien 798
		}
782 jpm 799
	}
800
 
901 jpm 801
	private boolean avoirAuteursMiseAJourCorrectement() {
1273 gduche 802
 
901 jpm 803
		boolean ok = false;
804
		if (attenteAjoutAuteursOk == false && attenteSuppressionAuteursOk == false) {
805
			ok = true;
806
		}
807
		return ok;
808
	}
809
 
822 jpm 810
	private void afficherAuteurs() {
1178 jpm 811
		if (mode.equals(Formulaire.MODE_AJOUTER)) {
812
			creerChampAuteurEtBoutonSupprimer(null);
813
		} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
814
			Iterator<String> itap = auteursInitialListe.keySet().iterator();
815
			while (itap.hasNext()) {
816
				creerChampAuteurEtBoutonSupprimer(auteursInitialListe.get(itap.next()));
817
			}
822 jpm 818
		}
1178 jpm 819
		auteursAffiches = true;
822 jpm 820
	}
821
 
822
	private void initialiserAffichageAuteurs() {
823
		auteurStorePartageChargementOk = false;
824
		publicationAPersonneListeChargementOk = false;
825
	}
1174 jpm 826
 
1178 jpm 827
	private void initialiserPeupler() {
828
		publicationOk = false;
829
		editeursOk = false;
830
		auteursAffiches = false;
1174 jpm 831
	}
822 jpm 832
 
833
	private boolean etrePretAAfficherAuteurs() {
834
		boolean ok = false;
1178 jpm 835
		if (auteurStorePartageChargementOk
836
				&& ((mode.equals(Formulaire.MODE_MODIFIER) && publicationOk && publicationAPersonneListeChargementOk)
837
						|| (mode.equals(Formulaire.MODE_AJOUTER)))) {
822 jpm 838
			ok = true;
839
		}
840
		return ok;
841
	}
1174 jpm 842
 
1178 jpm 843
	private boolean etrePretAPeupler() {
1174 jpm 844
		boolean ok = false;
1273 gduche 845
		if (mode.equals(Formulaire.MODE_MODIFIER) && publicationOk && editeursOk) {
1174 jpm 846
			ok = true;
847
		}
848
		return ok;
849
	}
1178 jpm 850
 
782 jpm 851
	private Boolean etreValide() {
852
		Boolean valide = false;
1273 gduche 853
		if (formulaireValideOk && auteursValideOk) {
782 jpm 854
			valide = true;
855
		}
856
		return valide;
857
	}
858
 
822 jpm 859
	private void initialiserValidation() {
860
		formulaireValideOk = false;
861
		publicationValideOk = false;
901 jpm 862
		initialiserAuteurs();
822 jpm 863
		auteursValideOk = false;
782 jpm 864
	}
865
 
901 jpm 866
	private void initialiserAuteurs() {
867
		attenteAjoutAuteursOk = true;
1273 gduche 868
		auteursAjoutes = new PersonneListe();
901 jpm 869
		attenteSuppressionAuteursOk = true;
1273 gduche 870
		auteursSupprimes = new PersonneListe();
901 jpm 871
	}
872
 
782 jpm 873
	private void repandreRafraichissement() {
874
		if (vueExterneARafraichirApresValidation != null) {
786 jpm 875
			String type = "publication_modifiee";
876
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
877
				type = "publication_ajoutee";
878
			}
879
			Information info = new Information(type);
880
			info.setDonnee(0, publication);
782 jpm 881
			vueExterneARafraichirApresValidation.rafraichir(info);
882
		}
883
	}
884
 
786 jpm 885
	public boolean soumettreFormulaire() {
822 jpm 886
		formulaireValideOk = verifierFormulaire();
887
		if (formulaireValideOk) {
901 jpm 888
			soumettrePublication();
1273 gduche 889
			//Les auteurs seront mis à jour lors du rafraichissement
901 jpm 890
		}
891
		return formulaireValideOk;
892
	}
893
 
894
	private void soumettrePublication() {
895
		Publication publicationCollectee = collecterPublication();
896
		if (publicationCollectee != null) {
897
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
898
				mediateur.ajouterPublication(this, publicationCollectee);
899
			} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
900
				mediateur.modifierPublication(this, publicationCollectee);
901
			}
902
		}
903
	}
904
 
905
	private void soumettreAuteurs() {
906
		attenteAjoutAuteursOk = false;
907
		attenteSuppressionAuteursOk = false;
908
 
1273 gduche 909
		//1) Auteurs ajoutés :
910
		// - Créer une PublicationAAuteurListe
911
		PublicationAPersonneListe listeDesAuteurs = new PublicationAPersonneListe();
912
		Iterator<String> itAuteur = auteursAjoutes.keySet().iterator();
913
		while (itAuteur.hasNext())	{
914
			PublicationAPersonne publiAPersonne = new PublicationAPersonne();
915
			String cle = itAuteur.next();
916
			publiAPersonne.setIdPersonne(cle);
917
			publiAPersonne.setIdPublication(publication.getId());
918
			listeDesAuteurs.put(cle, publiAPersonne);
919
		}
920
 
921
		// - envoyer au mediateur SSI personnes à ajouter
922
		if (listeDesAuteurs.size() > 0)	{
923
			mediateur.ajouterPublicationAPersonne(this, publication.getId(), listeDesAuteurs, PublicationAPersonne.ROLE_AUTEUR);
924
			attenteAjoutAuteursOk = true;
925
		}
926
 
927
		//2) Auteurs supprimés :
928
		// - Créer une PublicationAPersonneListe
929
		listeDesAuteurs = new PublicationAPersonneListe();
930
		itAuteur = auteursSupprimes.keySet().iterator();
931
		while (itAuteur.hasNext())	{
932
			PublicationAPersonne publiAPersonne = new PublicationAPersonne();
933
			String cle = itAuteur.next();
934
			publiAPersonne.setIdPersonne(cle);
935
			publiAPersonne.setIdPublication(publication.getId());
936
			listeDesAuteurs.put(cle, publiAPersonne);
937
		}
938
 
939
		// - Envoyer au médiateur SSI personnes à supprimer
940
		if (listeDesAuteurs.size() > 0) {
941
			mediateur.supprimerPublicationAPersonne(this, listeDesAuteurs);
942
			attenteSuppressionAuteursOk = true;
943
		}
944
 
945
		/*
946
		attenteAjoutAuteursOk = false;
947
		attenteSuppressionAuteursOk = false;
948
 
1133 jpm 949
		PersonneListe personnesInitiales = auteursInitialListe;
901 jpm 950
 
951
		PersonneListe personnesActuelles = new PersonneListe();
1131 jpm 952
		if (auteurComboboxListe != null) {
953
			Iterator<ComboBox<Personne>> itcp = auteurComboboxListe.iterator();
954
			while (itcp.hasNext()) {
1133 jpm 955
				ComboBox<Personne> combobox = itcp.next();
956
				Personne personne = combobox.getValue();
1131 jpm 957
				if (personne != null) {
958
					personnesActuelles.put(personne.getId(), personne);
959
				} else {
1134 jpm 960
					Debug.log("Etre valide :"+combobox.isValid()+" - "+combobox.getRawValue());
1131 jpm 961
				}
901 jpm 962
			}
963
		}
964
 
965
		// Auteurs ajoutés
966
		Iterator<String> clesActuelles = personnesActuelles.keySet().iterator();
967
		while (clesActuelles.hasNext()) {
968
			String idActuel = clesActuelles.next();
969
			if (personnesInitiales.size() == 0 || personnesInitiales.get(idActuel) == null) {
970
				Personne personne = personnesActuelles.get(idActuel);
971
				PublicationAPersonne publicationAAuteur = new PublicationAPersonne();
972
				if (mode.equals(Formulaire.MODE_MODIFIER)) {
973
					publicationAAuteur.setIdPublication(publication.getId());
741 aurelien 974
				}
901 jpm 975
				publicationAAuteur.setPersonne(personne);
976
				publicationAAuteur.setIdRole(PublicationAPersonne.ROLE_AUTEUR);
1273 gduche 977
				//FIXME : auteursAjoutes.put(publicationAAuteur.getId(), publicationAAuteur);
901 jpm 978
				attenteAjoutAuteursOk = true;
239 aurelien 979
			}
980
		}
901 jpm 981
 
982
		// Auteurs supprimés
983
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
984
			Iterator<String> clesInitiales = personnesInitiales.keySet().iterator();
985
			while (clesInitiales.hasNext()) {
986
				String idInitial = clesInitiales.next();
987
				if (personnesActuelles.size() == 0 || personnesActuelles.get(idInitial) == null) {
988
					Personne personne = personnesInitiales.get(idInitial);
989
					PublicationAPersonne publicationAAuteur = new PublicationAPersonne();
990
					publicationAAuteur.setIdPublication(publication.getId());
991
					publicationAAuteur.setPersonne(personne);
992
					publicationAAuteur.setIdRole(PublicationAPersonne.ROLE_AUTEUR);
1273 gduche 993
					//FIXME : auteursSupprimes.put(publicationAAuteur.getId(), publicationAAuteur);
901 jpm 994
					attenteSuppressionAuteursOk = true;
995
				}
996
			}
997
		}
998
 
999
		// Execution de les mise à jour pour le mode MODIFICATION
1000
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
1001
			if (auteursAjoutes != null && auteursAjoutes.size() != 0) {
1273 gduche 1002
				//FIXME : mediateur.ajouterPublicationAPersonne(this, publication.getId(), auteursAjoutes, PublicationAPersonne.ROLE_AUTEUR);
901 jpm 1003
			}
1004
 
1005
			if (auteursSupprimes != null && auteursSupprimes.size() != 0) {
1273 gduche 1006
				//FIXME : mediateur.supprimerPublicationAPersonne(this, auteursSupprimes);
901 jpm 1007
			}
1273 gduche 1008
		}*/
219 aurelien 1009
	}
1010
 
934 jpm 1011
	public boolean verifierFormulaire() {
782 jpm 1012
		boolean valide = true;
1013
		ArrayList<String> messages = new ArrayList<String>();
1014
 
1273 gduche 1015
		// Tester si au moins un auteur est présent
1016
		if (grille.getStore().getModels().size() == 0) {
1017
			messages.add("Veuillez saisir au moins un auteur.");
227 aurelien 1018
		}
705 aurelien 1019
 
786 jpm 1020
		String titre = titreChp.getValue();
782 jpm 1021
		if (titre == null || titre.equals("")) {
1022
			messages.add("Veuillez saisir le titre de la publication !");
705 aurelien 1023
		}
1024
 
792 jpm 1025
		String uri = uriChp.getValue();
1026
		if (uri != null && ! uri.isEmpty() && ! uri.matches(Pattern.url)) {
1027
			messages.add("L'URL saisie n'est pas valide !");
1028
		}
1029
 
799 jpm 1030
		String datePublication = datePublicationChp.getRawValue();
1031
		if (datePublication == null || datePublication.equals("")) {
1032
			messages.add("Veuillez saisir une année de parution !");
725 aurelien 1033
		} else {
799 jpm 1034
			if (!etreDateValide(datePublication)) {
792 jpm 1035
				messages.add("Le format de l'année saisie est incorrect !");
725 aurelien 1036
			}
705 aurelien 1037
		}
717 aurelien 1038
 
792 jpm 1039
		String pages = pagesChp.getValue();
1040
		String valeurPage = "(?:[0-9]+|[IVXLCDM]+|\\?)";
799 jpm 1041
		if (pages != null && ! pages.matches("^(?:"+valeurPage+"|"+valeurPage+"-"+valeurPage+")$")) {
792 jpm 1042
			messages.add("Le format des pages est incorrect !");
1043
		}
1044
 
782 jpm 1045
		if (messages.size() != 0) {
1046
			String[] tableauDeMessages = {};
1047
			tableauDeMessages = messages.toArray(tableauDeMessages);
799 jpm 1048
			MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDeMessages, "<br />"), null);
782 jpm 1049
			valide = false;
705 aurelien 1050
		}
782 jpm 1051
		return valide;
775 jpm 1052
	}
1053
 
822 jpm 1054
	private void peuplerFormulaire() {
1032 jpm 1055
		setValeurComboProjets();
822 jpm 1056
		titreChp.setValue(publication.getTitre());
1057
		collectionChp.setValue(publication.getCollection());
1058
		uriChp.setValue(publication.getURI());
1032 jpm 1059
		datePublicationChp.setValue(reduireDateParAnnee(publication.getDateParution()));
822 jpm 1060
		tomeChp.setValue(publication.getIndicationNvt());
1061
		fasciculeChp.setValue(publication.getFascicule());
1062
		pagesChp.setValue(publication.getPages());
1063
 
1064
		if (publication.getEditeur().matches("^[0-9]+$")) {
1065
			editeurCombobox.setValue(editeurCombobox.getStore().findModel("id_structure", publication.getEditeur()));
1066
		} else {
1067
			editeurCombobox.setRawValue(publication.getEditeur());
1068
		}
1069
	}
1070
 
786 jpm 1071
	private Publication collecterPublication() {
1273 gduche 1072
 
786 jpm 1073
		Publication publicationCollectee = (Publication) publication.cloner(new Publication());
1032 jpm 1074
		publicationCollectee.setIdProjet(getValeurComboProjets());
1124 jpm 1075
		publicationCollectee.setAuteur(construireIntituleAuteur());
786 jpm 1076
 
1077
		String titre = titreChp.getValue();
1078
		publicationCollectee.setTitre(titre);
1079
 
1080
		String collection = collectionChp.getValue();
1081
		publicationCollectee.setCollection(collection);
1082
 
1124 jpm 1083
		publicationCollectee.setNomComplet(construireNomComplet());
786 jpm 1084
 
1085
		String uri = uriChp.getValue();
1086
		publicationCollectee.setUri(uri);
1087
 
1088
		String editeur = "";
792 jpm 1089
		if (editeurCombobox.getValue() != null) {
1090
			editeur = editeurCombobox.getValue().getId();
799 jpm 1091
			publicationCollectee.setStructureEditeur(editeurCombobox.getValue());
792 jpm 1092
		} else if (editeurCombobox.getRawValue() != "") {
1093
			editeur = editeurCombobox.getRawValue();
786 jpm 1094
		}
1095
		publicationCollectee.setEditeur(editeur);
1096
 
792 jpm 1097
		String anneePublication = datePublicationChp.getRawValue();
1098
		String datePublication = anneePublication+"-00-00";
1099
		publicationCollectee.setDateParution(datePublication);
786 jpm 1100
 
1101
		String tome = tomeChp.getValue();
1102
		publicationCollectee.setIndicationNvt(tome);
1103
 
1104
		String fascicule = fasciculeChp.getValue();
1105
		publicationCollectee.setFascicule(fascicule);
1106
 
1107
		String pages = pagesChp.getValue();
1108
		publicationCollectee.setPages(pages);
1109
 
927 jpm 1110
		Publication publicationARetourner = null;
786 jpm 1111
		if (!publicationCollectee.comparer(publication)) {
1112
			publicationARetourner = publication = publicationCollectee;
1113
		}
1114
		return publicationARetourner;
1115
	}
1116
 
1124 jpm 1117
	private String construireIntituleEditeur() {
1118
		String editeur = "";
1119
		if (editeurCombobox.getValue() != null) {
1120
			editeur = editeurCombobox.getValue().getNom();
1121
		} else if (editeurCombobox.getRawValue() != "") {
1122
			editeur = editeurCombobox.getRawValue();
1123
		}
1124
		return editeur;
1125
	}
1126
 
1127
	private String construireIntituleAuteur() {
1273 gduche 1128
		String intituleAuteur = "";
1129
		List<Personne> auteurs = grille.getStore().getModels();
1130
		Iterator<Personne> itAuteurs = auteurs.iterator();
1131
		while (itAuteurs.hasNext())	{
1132
			Personne personneCourante = itAuteurs.next();
1133
			intituleAuteur += personneCourante.getNom().toUpperCase() + " " + personneCourante.getPrenom();
1134
			if (itAuteurs.hasNext())	{
1135
				intituleAuteur+=", ";
1136
			}
1137
		}
1138
		/*
1139
		 * TO DELETE:int auteursNombre = auteurComboboxListe.size();
1140
		 *
1124 jpm 1141
		for (int i = 0; i < auteursNombre; i++) {
1142
			if (auteurComboboxListe.get(i).getValue() != null) {
1143
				Personne auteur = auteurComboboxListe.get(i).getValue();
1144
				inituleAuteur += auteur.getNom().toUpperCase()+ " "+auteur.getPrenom();
1145
				if (i != (auteursNombre - 1)) {
1146
					inituleAuteur += ", ";
1147
				}
1148
			}
1273 gduche 1149
		}*/
1150
		return intituleAuteur;
1124 jpm 1151
	}
1152
 
1153
	private String construireNomComplet() {
1154
		// Intitulé de la publication complet : fmt_auteur, date_parution(année). titre. Editeur (nom), collection, fascicule, indication_nvt. pages.
1155
		String nomComplet = "";
1156
		String auteurs = construireIntituleAuteur();
1157
		String annee = datePublicationChp.getRawValue();
1158
		String titre = titreChp.getValue();
1159
		String editeur = construireIntituleEditeur();
1160
 
1161
		nomComplet += auteurs+", "+annee+". "+titre+".";
1162
 
1163
		if (!UtilString.isEmpty(editeur)) {
1164
			nomComplet += " Éditeur "+editeur+".";
1165
		}
1166
 
1167
		if (collectionChp.getValue() != null) {
1168
			String revue = collectionChp.getValue();
1169
			nomComplet += ", "+revue;
1170
		}
1171
 
1172
		if (fasciculeChp.getValue() != null) {
1173
			String fascicule = fasciculeChp.getValue();
1174
			nomComplet += ", "+fascicule;
1175
		}
1176
 
1177
		if (tomeChp.getValue() != null) {
1178
			String tomaison = tomeChp.getValue();
1179
			nomComplet += ", "+tomaison;
1180
		}
1181
 
1182
		if (collectionChp.getValue() != null || fasciculeChp.getValue() != null || tomeChp.getValue() != null) {
1183
			nomComplet += ".";
1184
		}
1185
 
1186
		if (pagesChp.getValue() != null) {
1187
			String pages = pagesChp.getValue();
1188
			nomComplet += pages+".";
1189
		}
1190
 
1191
		return nomComplet;
1192
	}
1193
 
934 jpm 1194
	public void reinitialiserFormulaire() {
781 jpm 1195
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
786 jpm 1196
			mediateur.afficherFormPublication(publication.getId());
775 jpm 1197
		} else {
1198
			mediateur.afficherFormPublication(null);
219 aurelien 1199
		}
1200
	}
227 aurelien 1201
 
792 jpm 1202
	private boolean etreDateValide(String anneePublication) {
782 jpm 1203
		boolean valide = true;
792 jpm 1204
		if (!anneePublication.matches("^[0-2][0-9]{3}$")) {
782 jpm 1205
			valide = false;
725 aurelien 1206
		}
782 jpm 1207
		return valide;
725 aurelien 1208
	}
758 aurelien 1209
 
1210
	private String reduireDateParAnnee(String datePar) {
775 jpm 1211
		if (datePar.matches("^[0-2][0-9]{3}(-[0-9]{2}){2}$")) {
758 aurelien 1212
			return datePar.split("-")[0];
505 jp_milcent 1213
		} else {
758 aurelien 1214
			return "";
227 aurelien 1215
		}
758 aurelien 1216
	}
1032 jpm 1217
 
1218
	private String getValeurComboProjets() {
1219
		String valeur = "";
1220
		if (projetsCombo.getValue() != null) {
1221
			valeur = projetsCombo.getValue().getId();
1222
		}
1223
		return valeur;
1224
	}
1225
	private void setValeurComboProjets() {
1226
		if (projetsCombo.getStore() != null ) {
1227
			if (mode.equals(Formulaire.MODE_MODIFIER) && publication != null) {
1228
				projetsCombo.setValue(projetsCombo.getStore().findModel("id_projet", publication.getIdProjet()));
1229
			} else if (mode.equals(Formulaire.MODE_AJOUTER)) {
1230
				projetsCombo.setValue(projetsCombo.getStore().findModel("id_projet", mediateur.getProjetId()));
1231
			}
1232
		}
1233
	}
505 jp_milcent 1234
}