Subversion Repositories eFlore/Applications.coel

Rev

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