Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 1942 → Rev 1943

/branches/v1.11-okuzgozu/src/org/tela_botanica/client/vues/structure/StructureFormPersonne.java
New file
0,0 → 1,789
package org.tela_botanica.client.vues.structure;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.composants.ChampComboBoxRechercheTempsReelPaginable;
import org.tela_botanica.client.composants.InfoLogger;
import org.tela_botanica.client.composants.pagination.ProxyPersonnes;
import org.tela_botanica.client.images.Images;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Information;
import org.tela_botanica.client.modeles.Valeur;
import org.tela_botanica.client.modeles.ValeurListe;
import org.tela_botanica.client.modeles.aDonnee;
import org.tela_botanica.client.modeles.personne.Personne;
import org.tela_botanica.client.modeles.structure.Structure;
import org.tela_botanica.client.modeles.structure.StructureAPersonne;
import org.tela_botanica.client.modeles.structure.StructureAPersonneListe;
import org.tela_botanica.client.synchronisation.Sequenceur;
import org.tela_botanica.client.util.Debug;
import org.tela_botanica.client.util.UtilString;
import org.tela_botanica.client.vues.FenetreForm;
import org.tela_botanica.client.vues.Formulaire;
import org.tela_botanica.client.vues.FormulaireBarreValidation;
import org.tela_botanica.client.vues.FormulaireOnglet;
import org.tela_botanica.client.vues.personne.PersonneForm;
 
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Record;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.store.StoreEvent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.Text;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Window;
 
public class StructureFormPersonne extends FormulaireOnglet implements Rafraichissable {
private StructureAPersonneListe personnel = null;
private StructureAPersonneListe personnelAjoute = null;
private StructureAPersonneListe personnelModifie = null;
private StructureAPersonneListe personnelSupprime = null;
private NumberField nbreTotalPersonneStructureChp = null;
private EditorGrid<StructureAPersonne> grillePersonnel = null;
private ListStore<StructureAPersonne> personnelGrilleMagazin = null;
public ListStore<Valeur> fonctionsMagazin;
public ComboBox<Valeur> fonctionsCombo;
public ListStore<Valeur> magazinLiStatut;
public ComboBox<Valeur> comboLiStatut;
private ListStore<Personne> personneExistanteMagazin = null;
private ChampComboBoxRechercheTempsReelPaginable personneExistanteCombo = null;
private Button supprimerPersonnelBtn = null;
private CellEditor fonctionEditor = null;
private List<Valeur> fonctionsListe = null;
private String ID = "personnel";
private Formulaire formulaireCourant = null;
private int decompteRafraichissementPersonnel;
private FenetreForm fenetreFormulaire = null;
private Sequenceur sequenceur = null;
final class EtatPersonnelStructure {
public StructureAPersonneListe personnelModifie;
public StructureAPersonneListe personnelAjoute;
public StructureAPersonneListe personnelSupprime;
public StructureAPersonneListe personnel;
}
 
public StructureFormPersonne(Formulaire formulaireCourant, Mediateur mediateur) {
initialiserOnglet(formulaireCourant);
this.formulaireCourant = formulaireCourant;
// Création des objets contenant les manipulations de la grille
personnelModifie = new StructureAPersonneListe();
personnelAjoute = new StructureAPersonneListe();
personnelSupprime = new StructureAPersonneListe();
setId(ID);
setText(Mediateur.i18nC.personneSingulier());
FormulaireOnglet.parametrer(this);
this.setLayout(Formulaire.creerFormLayout(400, LabelAlign.LEFT));
this.setStyleAttribute("padding", "0");
this.addListener(Events.Select, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent be) {
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter...
setData("acces", true);
 
// Rafraichissement du contenu de la grille du personnel
if (StructureFormPersonne.this.formulaireCourant.mode.equals(Formulaire.MODE_AJOUTER)) {
rafraichirPersonnel();
}
}
});
ContentPanel cp = new ContentPanel();
cp.setHeadingHtml("Personnes travaillant sur les collections");
cp.setIcon(Images.ICONES.table());
cp.setScrollMode(Scroll.AUTO);
cp.setLayout(new FitLayout());
//cp.setWidth(1250);
//cp.setHeight("100%");
cp.setFrame(true);
personnelGrilleMagazin = new ListStore<StructureAPersonne>();
personnelGrilleMagazin.setMonitorChanges(true);
personnelGrilleMagazin.addListener(Store.Add, new Listener<StoreEvent<StructureAPersonne>>() {
public void handleEvent(StoreEvent<StructureAPersonne> ce) {
// Activation du bouton supprimer si la grille contient un élément
if (grillePersonnel.getStore().getCount() > 0) {
supprimerPersonnelBtn.enable();
}
}
});
RowNumberer r = new RowNumberer();
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
 
GridSelectionModel<StructureAPersonne> sm = new GridSelectionModel<StructureAPersonne>();
configs.add(r);
ColumnConfig column = new ColumnConfig("fonction", "Fonction", 150);
fonctionsMagazin = new ListStore<Valeur>();
fonctionsCombo = new ComboBox<Valeur>();
fonctionsCombo.setTriggerAction(TriggerAction.ALL);
fonctionsCombo.setEditable(true);
fonctionsCombo.setDisplayField("nom");
fonctionsCombo.setStore(fonctionsMagazin);
mediateur.obtenirListeValeurEtRafraichir(this, "fonction", sequenceur);
fonctionEditor = new CellEditor(fonctionsCombo) {
@Override
public Object preProcessValue(Object valeur) {
Valeur retour = null;
if (valeur != null) {
String chaineTransmise = (String) valeur;
if (fonctionsMagazin.getCount() == 0 && fonctionsListe != null) {
fonctionsMagazin.add(fonctionsListe);
}
if (fonctionsMagazin.findModel("id_valeur", chaineTransmise) != null) {
retour = fonctionsMagazin.findModel("id_valeur", chaineTransmise);
} else if (fonctionsMagazin.findModel("nom", chaineTransmise) != null) {
retour = fonctionsMagazin.findModel("nom", chaineTransmise);
} else {
retour = new Valeur("", chaineTransmise, "", "");
}
}
return retour;
}
@Override
public Object postProcessValue(Object valeur) {
String retour = "";
Valeur fonctionTrouvee = null;
if (valeur == null) {
String valeurBrute = this.getField().getRawValue();
if (fonctionsMagazin.getCount() == 0 && fonctionsListe != null) {
fonctionsMagazin.add(fonctionsListe);
}
if (valeurBrute.matches("^[0-9]+$") && fonctionsMagazin.findModel("id_valeur", valeurBrute) != null) {
fonctionTrouvee = fonctionsMagazin.findModel("id_valeur", valeurBrute);
} else {
retour = valeurBrute;
}
} else if (valeur instanceof Valeur) {
fonctionTrouvee = (Valeur) valeur;
}
if (fonctionTrouvee != null) {
retour = fonctionTrouvee.getNom();
}
return retour;
}
};
column.setEditor(fonctionEditor);
configs.add(column);
column = new ColumnConfig("prenom", "Prénom", 100);
configs.add(column);
column = new ColumnConfig("nom", "Nom", 100);
configs.add(column);
 
column = new ColumnConfig("tel_fix", "Téléphone", 100);
configs.add(column);
 
column = new ColumnConfig("tel_fax", "Fax", 100);
configs.add(column);
column = new ColumnConfig("courriel", "Courriel principal", 200);
configs.add(column);
magazinLiStatut = new ListStore<Valeur>();
magazinLiStatut.add(new ArrayList<Valeur>());
comboLiStatut = new ComboBox<Valeur>();
comboLiStatut.setTriggerAction(TriggerAction.ALL);
comboLiStatut.setEditable(false);
comboLiStatut.disableTextSelection(true);
comboLiStatut.setDisplayField("nom");
comboLiStatut.setStore(magazinLiStatut);
mediateur.obtenirListeValeurEtRafraichir(this, "statut", sequenceur);
CellEditor statutEditor = new CellEditor(comboLiStatut) {
@Override
public Object preProcessValue(Object value) {
if (value == null) {
return value;
}
return comboLiStatut.getStore().findModel("nom", (String) value);
}
@Override
public Object postProcessValue(Object value) {
if (value == null) {
return value;
}
return ((Valeur) value).get("nom");
}
};
column = new ColumnConfig("statut", "Statut", 100);
column.setEditor(statutEditor);
configs.add(column);
column = new ColumnConfig("travail", "Travail hebdo (%)", 100);
column.setNumberFormat(NumberFormat.getFormat("##"));
NumberField tpsWChp = new NumberField();
tpsWChp.setFormat(NumberFormat.getFormat("##"));
tpsWChp.setToolTip("Ce champ doit contenir un nombre");
column.setEditor(new CellEditor(tpsWChp));
configs.add(column);
column = new ColumnConfig("specialite", "Spécialité botanique principale", 150);
configs.add(column);
CheckColumnConfig checkColumn = new CheckColumnConfig("contact", "Contact ?", 60);
configs.add(checkColumn);
ToolBar toolBar = new ToolBar();
personneExistanteMagazin = new ListStore<Personne>();
personneExistanteMagazin.add(new ArrayList<Personne>());
ModelType modelTypePersonnes = new ModelType();
modelTypePersonnes.setRoot("personnes");
modelTypePersonnes.setTotalName("nbElements");
modelTypePersonnes.addField("cp_fmt_nom_complet");
modelTypePersonnes.addField("cp_nom");
modelTypePersonnes.addField("cp_prenom");
modelTypePersonnes.addField("cp_truk_courriel");
modelTypePersonnes.addField("cp_truk_telephone");
modelTypePersonnes.addField("cp_ce_truk_specialite");
modelTypePersonnes.addField("cp_id_personne");
String displayNamePersonnes = "cp_fmt_nom_complet";
ProxyPersonnes<ModelData> proxyPersonnes = new ProxyPersonnes<ModelData>(null);
personneExistanteCombo = new ChampComboBoxRechercheTempsReelPaginable(proxyPersonnes, modelTypePersonnes, displayNamePersonnes);
personneExistanteCombo.getCombo().setEmptyText("Rechercher et sélectionner une personne existante dans la base");
// TODO : dans GXT 2.0 plus besoin de l'adaptateur, on peut ajouter la combobox directement sur la toolbar
//> CHECK
toolBar.add(personneExistanteCombo);
personneExistanteCombo.getCombo().addListener(Events.Select, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
if (personneExistanteCombo.getValeur() instanceof ModelData) {
Personne personneExistante = new Personne(personneExistanteCombo.getValeur());
StructureAPersonne membreDuPersonnel = new StructureAPersonne(personneExistante, "", StructureAPersonne.ROLE_EQUIPE, StructureAPersonne.ETAT_AJOUTE);
ajouterMembreAGrillePersonnel(membreDuPersonnel);
personneExistanteCombo.getCombo().setValue(null);
}
}
});
 
toolBar.add(new Text(" ou "));
Button ajouterPersonnelBtn = creerBoutonAjouter();
toolBar.add(ajouterPersonnelBtn);
toolBar.add(new SeparatorToolItem());
Button modifierPersonnelBtn = creerBoutonModifier();
toolBar.add(modifierPersonnelBtn);
toolBar.add(new SeparatorToolItem());
supprimerPersonnelBtn = new Button("Supprimer");
supprimerPersonnelBtn.setIcon(Images.ICONES.vcardSupprimer());
supprimerPersonnelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
StructureAPersonne personne = grillePersonnel.getSelectionModel().getSelectedItem();
if (personne != null) {
// Ajout de la personne supprimée à la liste
if (personne.getIdPersonne() != null && !personne.getIdPersonne().equals("")) {
personnelSupprime.put(personne.getId(), personne);
}
// Suppression de l'enregistrement de la grille
grillePersonnel.getStore().remove(personne);
// Désactivation du bouton supprimer si la grille contient plus d'élément
if (grillePersonnel.getStore().getCount() == 0) {
//TODO : check : Item -> component
ce.getComponent().disable();
}
}
}
});
toolBar.add(supprimerPersonnelBtn);
toolBar.add(new SeparatorToolItem());
Button rafraichirPersonnelBtn = new Button("Rafraichir");
rafraichirPersonnelBtn.setIcon(Images.ICONES.rafraichir());
rafraichirPersonnelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
rafraichirPersonnel();
}
});
toolBar.add(rafraichirPersonnelBtn);
toolBar.add(new SeparatorToolItem());
cp.setTopComponent(toolBar);
 
ColumnModel cm = new ColumnModel(configs);
grillePersonnel = new EditorGrid<StructureAPersonne>(personnelGrilleMagazin, cm);
//grillePersonnel.setHeight("100%");
grillePersonnel.setAutoHeight(true);
grillePersonnel.setBorders(true);
grillePersonnel.setSelectionModel(sm);
grillePersonnel.addPlugin(checkColumn);
grillePersonnel.addPlugin(r);
grillePersonnel.getView().setForceFit(true);
grillePersonnel.setAutoExpandColumn("specialite");
grillePersonnel.setStripeRows(true);
grillePersonnel.setTrackMouseOver(true);
personnelGrilleMagazin.addListener(Store.Update, new Listener<StoreEvent<StructureAPersonne>>() {
public void handleEvent(StoreEvent<StructureAPersonne> ce) {
StructureAPersonne structureAPersonne = ce.getModel();
String etat = structureAPersonne.get("etat");
if ((etat==null || !etat.equals(aDonnee.ETAT_AJOUTE)) && structureAPersonne!=null && !UtilString.isEmpty(structureAPersonne.getId())) {
ce.getModel().set("etat", aDonnee.ETAT_MODIFIE);
}
}
});
cp.add(grillePersonnel);
this.add(cp);
this.setAutoHeight(true);
}
private Button creerBoutonAjouter() {
Button bouton = new Button(i18nC.ajouter());
bouton.setIcon(Images.ICONES.vcardAjouter());
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_AJOUTER);
fenetreFormulaire.show();
}
});
return bouton;
}
private Button creerBoutonModifier() {
Button bouton = new Button(i18nC.modifier());
bouton.setIcon(Images.ICONES.vcardModifier());
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
String IdpersonneSaisieSelectionnee = (grillePersonnel.getSelectionModel().getSelectedItem()).getIdPersonne();
if (IdpersonneSaisieSelectionnee == null) {
InfoLogger.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPersonne());
} else {
fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_MODIFIER);
fenetreFormulaire.show();
}
}
});
return bouton;
}
private FenetreForm creerFenetreModaleAvecFormulairePersonne(String mode) {
String personneId = null;
if (mode.equals(Formulaire.MODE_MODIFIER)) {
personneId = (grillePersonnel.getSelectionModel().getSelectedItem()).getIdPersonne();
}
final FenetreForm fenetre = new FenetreForm("");
final PersonneForm formulaire = creerFormulairePersonne(fenetre, personneId);
fenetre.add(formulaire);
return fenetre;
}
private PersonneForm creerFormulairePersonne(final FenetreForm fenetre, final String personneId) {
PersonneForm formulairePersonne = new PersonneForm(mediateur, personneId, this);
FormPanel panneauFormulaire = formulairePersonne.getFormulaire();
fenetre.setHeadingHtml(panneauFormulaire.getHeadingHtml());
panneauFormulaire.setHeaderVisible(false);
panneauFormulaire.setTopComponent(null);
// 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.
panneauFormulaire.getBottomComponent().hide();
SelectionListener<ButtonEvent> ecouteur = creerEcouteurValidationFormulairePersonne(fenetre, formulairePersonne);
final ButtonBar barreValidation = new FormulaireBarreValidation(ecouteur);
fenetre.setBottomComponent(barreValidation);
return formulairePersonne;
}
private SelectionListener<ButtonEvent> creerEcouteurValidationFormulairePersonne(final FenetreForm fenetre, final PersonneForm formulaire) {
SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
String code = ((Button) ce.getComponent()).getData("code");
if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
if (formulaire.soumettreFormulaire()) {
fenetre.hide();
}
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
formulaire.soumettreFormulaire();
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
fenetre.hide();
}
}
};
return ecouteur;
}
public Collection<? extends String> verifier() {
ArrayList<String> messages = new ArrayList<String>();
// Vérification du Personnel
if (getData("acces").equals(true)) {
String personnelNumero = "";
int nbrePersonne = personnelGrilleMagazin.getCount();
for (int i = 0; i < nbrePersonne; i++) {
StructureAPersonne personne = personnelGrilleMagazin.getAt(i);
if (personne.getNom().equals("") || personne.getPrenom().equals("")) {
personnelNumero += (i != 0 ? ", " : "")+(i+1);
}
}
if (!personnelNumero.equals("")) {
messages.add("Veuillez indiquez un prénom et un nom au personnel numéro : "+personnelNumero);
}
}
return messages;
}
 
@Override
public void rafraichir(Object nouvellesDonnees) {
if (nouvellesDonnees instanceof ValeurListe) {
ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
rafraichirValeurListe(listeValeurs);
} else if (nouvellesDonnees instanceof Information) {
Information info = (Information) nouvellesDonnees;
rafraichirInformation(info);
} else {
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
}
}
public void rafraichirInformation(Information info) {
if (info.getType().equals("ajout_structure")) {
if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
String structureId = (String) info.getDonnee(0);
// Suite à la récupération de l'id de l'institution nouvellement ajoutée nous ajoutons le personnel
mediateur.ajouterStructureAPersonne(this, structureId, getPersonnelAjoute());
}
} else if (info.getType().equals("modif_structure_a_personne")) {
InfoLogger.display("Modification du Personnel", info.toString());
testerLancementRafraichirPersonnel();
} else if (info.getType().equals("suppression_structure_a_personne")) {
InfoLogger.display("Suppression du Personnel", info.toString());
testerLancementRafraichirPersonnel();
} else if (info.getType().equals("ajout_structure_a_personne")) {
InfoLogger.display("Ajout du Personnel", info.toString());
testerLancementRafraichirPersonnel();
} else if (info.getType().equals("liste_structure_a_personne")) {
if (info.getDonnee(0) != null) {
StructureAPersonneListe personnel = (StructureAPersonneListe) info.getDonnee(0);
peupler(personnel);
layout();
InfoLogger.display("Chargement du Personnel", "ok");
}
} else if (info.getType().equals("personne_modifiee")) {
if (info.getDonnee(0) != null) {
Personne personne = (Personne) info.getDonnee(0);
StructureAPersonne personneDansGrille = grillePersonnel.getStore().findModel("id_personne", personne.getId());
StructureAPersonne personneDansGrilleModif = new StructureAPersonne(personne, personneDansGrille.getFonction(), personneDansGrille.getIdRole(), personneDansGrille.getIdEtat());
int index = grillePersonnel.getStore().indexOf(personneDansGrille);
grillePersonnel.getStore().remove(personneDansGrille);
grillePersonnel.getStore().insert(personneDansGrilleModif, index);
personnelModifie.put(personne.getId()+"", personneDansGrilleModif);
}
} else if (info.getType().equals("personne_ajoutee")) {
if (info.getDonnee(0) != null) {
Personne personne = (Personne) info.getDonnee(0);
StructureAPersonne structAPersonne = new StructureAPersonne(personne,"",StructureAPersonne.ROLE_EQUIPE, "");
Structure structure = ((StructureForm) formulaire).identification;
structAPersonne.setIdStructure(structure.getId());
personnelAjoute.put(personne.getId(), structAPersonne);
ajouterMembreAGrillePersonnel(structAPersonne);
}
}
}
public void rafraichirValeurListe(ValeurListe listeValeurs) {
List<Valeur> liste = listeValeurs.toList();
if (listeValeurs.getId().equals(config.getListeId("statut"))) {
magazinLiStatut.removeAll();
magazinLiStatut.add(liste);
comboLiStatut.setStore(magazinLiStatut);
}
if (listeValeurs.getId().equals(config.getListeId("fonction"))) {
// FIXME : le store ne contient pas tout le temps les données, chose étrange.
// On stocke donc les données dans une variables de la classe pour recharger le store si besoin.
fonctionsListe = liste;
fonctionsMagazin.removeAll();
fonctionsMagazin.add(liste);
fonctionsCombo.setStore(fonctionsMagazin);
}
}
 
public EtatPersonnelStructure collecter() {
StructureForm formulaire = (StructureForm)formulaireCourant;
if (getData("acces").equals(true)) {
personnelGrilleMagazin.commitChanges();
int nbrePersonne = personnelGrilleMagazin.getCount();
for (int i = 0; i < nbrePersonne; i++) {
StructureAPersonne personne = personnelGrilleMagazin.getAt(i);
// Seules les lignes ajoutées ou modifiées sont prises en compte.
Record record = personnelGrilleMagazin.getRecord(personne);
if (personnelGrilleMagazin.getModifiedRecords().contains(record) == true
|| (personne.get("etat") != null && (personne.get("etat").equals(StructureAPersonne.ETAT_AJOUTE) || personne.get("etat").equals(StructureAPersonne.ETAT_MODIFIE)) )) {
// Gestion de l'id de la structure
if (mode.equals("MODIF")) {
personne.setIdStructure(getIdIdentification());
}
// Gestion de la fonction
String fonction = personne.get("fonction");
if (fonction != null && !fonction.equals("")) {
Valeur valeurRecherche = fonctionsCombo.getStore().findModel("nom", fonction);
if (valeurRecherche != null) {
personne.setFonction(valeurRecherche.getId());
} else {
personne.setFonction("AUTRE", fonction);
}
} else {
personne.setFonction("");
}
 
// Gestion du nom complet
String nomComplet = personne.getPrenom()+" "+personne.getNom();
personne.setNomComplet(nomComplet);
// Gestion de la notion de "contact"
personne.setContact(false);
if (personne.get("contact").equals(true)) {
personne.setContact(true);
}
// Gestion du statut
String statut = personne.get("statut");
if (statut != null && !statut.equals("")) {
Valeur valeurRecherche = comboLiStatut.getStore().findModel("nom", statut);
if (valeurRecherche != null) {
personne.setStatut(valeurRecherche.getId());
} else {
personne.setStatut("AUTRE", statut);
}
} else {
personne.setStatut("");
}
// Gestion du temps de travail
String personneTravail = "";
if(personne.get("travail") != null) {
personneTravail = personne.get("travail").toString();
}
personne.setBotaTravailHebdoTps(personneTravail);
// Gestion du téléphone
String telephoneFixe = personne.get("tel_fix");
personne.setTelephoneFixe(telephoneFixe);
// Gestion du fax
String fax = personne.get("tel_fax");
personne.setFax(fax);
// Gestion du courriel
String courriel = personne.get("courriel");
personne.setCourriel(courriel);
// Gestion de la spécialité
String specialite = personne.get("specialite");
personne.setSpecialite(specialite);
// On met à faux le décès
personne.setDeces(Personne.ETRE_VIVANT);
// Ajout de la personne dans la liste correspondant à son état (ajouté ou modifié)
if (personne.get("etat") != null && personne.get("etat").equals(StructureAPersonne.ETAT_AJOUTE)) { // Une personne ajoutée
personnelAjoute.put(""+i, personne);
} else {// Une personne modifiée
personnelModifie.put(personne.getId(), personne);
}
} else {
GWT.log("Personne non modifiées : "+personne.getPrenom()+" "+personne.getNom(), null);
}
}
}
EtatPersonnelStructure etatPersonnel = new EtatPersonnelStructure();
etatPersonnel.personnelAjoute = personnelAjoute;
etatPersonnel.personnelModifie = personnelModifie;
etatPersonnel.personnelSupprime = personnelSupprime;
// Remise à zéro des modification dans la liste du personnel
personnelModifie = new StructureAPersonneListe();
personnelAjoute = new StructureAPersonneListe();
personnelSupprime = new StructureAPersonneListe();
return etatPersonnel;
}
 
public void peupler(StructureAPersonneListe personnel) {
//this.personnel = personnel;
if (formulaireCourant.mode.equals(Formulaire.MODE_MODIFIER) && personnel != null) {
ArrayList<StructureAPersonne> personnes = new ArrayList<StructureAPersonne>();
for (Iterator<String> it = personnel.keySet().iterator(); it.hasNext();) {
String index = it.next();
// Gestion de la fonction
if (fonctionsMagazin != null && !((String) personnel.get(index).getFonction()).startsWith("AUTRE##")) {
if (fonctionsMagazin.findModel("id_valeur", personnel.get(index).getFonction()) != null) {
personnel.get(index).set("fonction", fonctionsMagazin.findModel("id_valeur", personnel.get(index).getFonction()).getNom());
}
} else {
personnel.get(index).set("fonction", personnel.get(index).getFonction().replaceFirst("AUTRE##", ""));
}
// Gestion de la notion de "contact"
personnel.get(index).set("contact", (personnel.get(index).getContact().equals("1") ? true : false));
// Gestion du statut
if (magazinLiStatut != null && ((String) personnel.get(index).getStatut()).matches("^[0-9]+$")) {
personnel.get(index).set("statut", magazinLiStatut.findModel("id_valeur", personnel.get(index).getStatut()).getNom());
} else {
personnel.get(index).set("statut", personnel.get(index).getStatut().replaceFirst("AUTRE##", ""));
}
// Gestion de la specialite
if (((String) personnel.get(index).getSpecialite()).matches("^[0-9]+$")) {
// Author : Cyprien
// TODO
// Ici faire un combobox ?
// ...
} else {
personnel.get(index).set("specialite", personnel.get(index).getSpecialite().replaceFirst("AUTRE##", ""));
}
// Gestion du temps de travail
String tps = personnel.get(index).getBotaTravailHebdoTps();
personnel.get(index).set("travail", (tps.matches("^[0-9]+$") ? Integer.parseInt(tps) : 0));
personnes.add(personnel.get(index));
}
personnelGrilleMagazin.removeAll();
personnelGrilleMagazin.add(personnes);
// Remise à zéro des modification dans la liste du personnel
personnelModifie = new StructureAPersonneListe();
personnelAjoute = new StructureAPersonneListe();
personnelSupprime = new StructureAPersonneListe();
// Nous vidons la variable personnel une fois qu'elle a remplie la grille
personnel = null;
}
}
public StructureAPersonneListe getPersonnelAjoute() {
return personnelAjoute;
}
private void ajouterMembreAGrillePersonnel(StructureAPersonne personnel) {
grillePersonnel.stopEditing();
personnelGrilleMagazin.insert(personnel, 0);
grillePersonnel.startEditing(0, 0);
}
public void testerLancementRafraichirPersonnel() {
decompteRafraichissementPersonnel--;
if (decompteRafraichissementPersonnel <= 0) {
// Nous rechargeons la liste du Personnel
rafraichirPersonnel();
}
}
private void rafraichirPersonnel() {
decompteRafraichissementPersonnel = 0;
if (formulaireCourant.mode.equals(Formulaire.MODE_MODIFIER)) {
initialiserGrillePersonnelEnModification();
} else if (formulaireCourant.mode.equals(Formulaire.MODE_AJOUTER)) {
initialiserGrillePersonnelEnAjout();
}
}
private void rafraichirPersonneExistante(String nom) {
mediateur.selectionnerPersonneParNomComplet(this, nom+"%", null);
}
public void incrementerDecompteRafraichissementPersonnel() {
decompteRafraichissementPersonnel++;
}
private void initialiserGrillePersonnelEnAjout() {
personnelGrilleMagazin.removeAll();
layout();
}
private String getIdIdentification() {
return ((StructureForm)formulaireCourant).getIdIdentification();
}
private void initialiserGrillePersonnelEnModification() {
mediateur.selectionnerStructureAPersonne(this, getIdIdentification(), StructureAPersonne.ROLE_EQUIPE, null);
}
}