Subversion Repositories eFlore/Applications.coel

Rev

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