/branches/v1.0-syrah/src/org/tela_botanica/client/vues/personne/PersonneFormPublication.java |
---|
New file |
0,0 → 1,665 |
package org.tela_botanica.client.vues.personne; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.LinkedList; |
import java.util.List; |
import org.tela_botanica.client.ComposantClass; |
import org.tela_botanica.client.Mediateur; |
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.publication.Publication; |
import org.tela_botanica.client.modeles.publication.PublicationAPersonne; |
import org.tela_botanica.client.modeles.publication.PublicationAPersonneListe; |
import org.tela_botanica.client.modeles.publication.PublicationListe; |
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.publication.PublicationForm; |
import com.extjs.gxt.ui.client.core.XTemplate; |
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.KeyListener; |
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.Store; |
import com.extjs.gxt.ui.client.store.StoreEvent; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Info; |
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.FormPanel; |
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; |
import com.extjs.gxt.ui.client.widget.grid.CellEditor; |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; |
import com.extjs.gxt.ui.client.widget.grid.ColumnData; |
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.Grid; |
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel; |
import com.extjs.gxt.ui.client.widget.grid.RowExpander; |
import com.extjs.gxt.ui.client.widget.grid.RowNumberer; |
import com.extjs.gxt.ui.client.widget.layout.FitLayout; |
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; |
public class PersonneFormPublication extends FormulaireOnglet implements Rafraichissable { |
private Personne personneSelectionnee = null; |
private static int idGenere = 1; |
private ContentPanel panneauPrincipal = null; |
private ToolBar barreOutils = null; |
private EditorGrid<PublicationAPersonne> grille; |
private PublicationAPersonneListe publicationsAjoutees = null; |
private PublicationAPersonneListe publicationsSupprimees = null; |
private ComboBox<Publication> publicationsSaisiesComboBox = null; |
private Button publicationsBoutonSupprimer = null; |
private Button publicationsBoutonModifier = null; |
private ComboBox<Valeur> typeRelationCombo = null; |
private List<Valeur> roles = null; |
private PublicationAPersonneListe listePublicationsLiees = new PublicationAPersonneListe(); |
private FenetreForm fenetreFormulaire = null; |
public PersonneFormPublication(Formulaire formulaireCourrant) { |
initialiserOnglet(formulaireCourrant); |
setId("publication"); |
setText(Mediateur.i18nC.collectionPublication()); |
setStyleAttribute("padding", "0"); |
panneauPrincipal = creerPanneauContenantGrille(); |
barreOutils = creerBarreOutilsGrille(); |
panneauPrincipal.setTopComponent(barreOutils); |
grille = creerGrille(); |
panneauPrincipal.add(grille); |
add(panneauPrincipal); |
initialiser(); |
} |
private void initialiser() { |
// Remise à zéro des modification dans la liste des auteurs |
idGenere = 1; |
publicationsAjoutees = new PublicationAPersonneListe(); |
publicationsSupprimees = new PublicationAPersonneListe(); |
// Actualisation de l'état des boutons de la barre d'outils |
actualiserEtatBoutonsBarreOutils(); |
} |
public void mettreAJourPersonne() { |
personneSelectionnee = ((PersonneForm) formulaire).personneSelectionnee; |
//Boucle sur les role pour trouver les publication à personne |
if ((roles != null) && (personneSelectionnee!=null)) { |
mediateur.selectionnerPublicationAPersonne(this, null, personneSelectionnee.getId(), roles); |
} |
} |
private ContentPanel creerPanneauContenantGrille() { |
ContentPanel panneau = new ContentPanel(); |
panneau.setHeading(i18nC.collectionPublication()+" " + i18nC.personnePublication()); |
panneau.setIcon(Images.ICONES.table()); |
panneau.setLayout(new FitLayout()); |
panneau.setFrame(true); |
return panneau; |
} |
private ToolBar creerBarreOutilsGrille() { |
ToolBar barreOutils = new ToolBar(); |
Button ajouterBouton = creerBoutonAjouter(); |
barreOutils.add(ajouterBouton); |
barreOutils.add(new Text(" ou ")); |
publicationsSaisiesComboBox = creerComboBoxPublicationsSaisis(); |
barreOutils.add(publicationsSaisiesComboBox); |
barreOutils.add(new SeparatorToolItem()); |
publicationsBoutonModifier = creerBoutonModifier(); |
barreOutils.add(publicationsBoutonModifier); |
barreOutils.add(new SeparatorToolItem()); |
publicationsBoutonSupprimer = creerBoutonSupprimer(); |
barreOutils.add(publicationsBoutonSupprimer); |
barreOutils.add(new SeparatorToolItem()); |
Button rafraichirBouton = creerBoutonRafraichir(); |
barreOutils.add(rafraichirBouton); |
return barreOutils; |
} |
private Button creerBoutonAjouter() { |
Button bouton = new Button(i18nC.ajouter()); |
bouton.setIcon(Images.ICONES.vcardAjouter()); |
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() { |
@Override |
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>() { |
@Override |
public void componentSelected(ButtonEvent ce) { |
PublicationAPersonne publicationSaisieSelectionnee = grille.getSelectionModel().getSelectedItem(); |
if (publicationSaisieSelectionnee == null) { |
Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPublication()); |
} else { |
fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_MODIFIER); |
fenetreFormulaire.show(); |
} |
} |
}); |
return bouton; |
} |
private FenetreForm creerFenetreModaleAvecFormulairePersonne(String mode) { |
String publicationId = null; |
if (mode.equals(Formulaire.MODE_MODIFIER)) { |
PublicationAPersonne publicationSaisiSelectionne = grille.getSelectionModel().getSelectedItem(); |
publicationId = publicationSaisiSelectionne.getIdPublication(); |
} |
final FenetreForm fenetre = new FenetreForm(""); |
final PublicationForm formulaire = creerFormulairePublication(fenetre, publicationId); |
fenetre.add(formulaire); |
return fenetre; |
} |
private PublicationForm creerFormulairePublication(final FenetreForm fenetre, final String publicationId) { |
PublicationForm formulairePublication = new PublicationForm(mediateur, publicationId, this); |
FormPanel panneauFormulaire = formulairePublication.getFormulaire(); |
fenetre.setHeading(panneauFormulaire.getHeading()); |
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 = creerEcouteurValidationFormulairePublication(fenetre, formulairePublication); |
final ButtonBar barreValidation = new FormulaireBarreValidation(ecouteur); |
fenetre.setBottomComponent(barreValidation); |
return formulairePublication; |
} |
private SelectionListener<ButtonEvent> creerEcouteurValidationFormulairePublication(final FenetreForm fenetre, final PublicationForm formulaire) { |
SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() { |
@Override |
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(); |
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) { |
fenetreFormulaire.hide(); |
fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(formulaire.mode); |
fenetreFormulaire.show(); |
} |
} |
}; |
return ecouteur; |
} |
private Button creerBoutonSupprimer() { |
Button bouton = new Button(i18nC.supprimer()); |
bouton.setIcon(Images.ICONES.vcardSupprimer()); |
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() { |
@Override |
public void componentSelected(ButtonEvent ce) { |
PublicationAPersonne publicationSaisieSelectionnee = grille.getSelectionModel().getSelectedItem(); |
if (publicationSaisieSelectionnee == null) { |
Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPublication()); |
} else { |
supprimerDansGrille(publicationSaisieSelectionnee); |
} |
} |
}); |
return bouton; |
} |
private Button creerBoutonRafraichir() { |
Button bouton = new Button(i18nC.rafraichir()); |
bouton.setIcon(Images.ICONES.rafraichir()); |
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() { |
@Override |
public void componentSelected(ButtonEvent ce) { |
actualiserGrille(); |
} |
}); |
return bouton; |
} |
private void actualiserGrille() { |
if (mode.equals(Formulaire.MODE_MODIFIER)) { |
mediateur.selectionnerPublicationAPersonne(this, null, personneSelectionnee.getId(), "%"); |
} else { |
grille.getStore().removeAll(); |
layout(); |
} |
} |
private ComboBox<Publication> creerComboBoxPublicationsSaisis() { |
ListStore<Publication> publicationsSaisiesStore = new ListStore<Publication>(); |
ComboBox<Publication> comboBox = new ComboBox<Publication>(); |
comboBox.setWidth(400); |
comboBox.setEmptyText(i18nC.chercherPublicationSaisi()); |
comboBox.setTriggerAction(TriggerAction.ALL); |
comboBox.setEditable(true); |
comboBox.setDisplayField("fmt_nom_complet"); |
comboBox.setStore(publicationsSaisiesStore); |
comboBox.addKeyListener(new KeyListener() { |
public void componentKeyUp(ComponentEvent ce) { |
if (publicationsSaisiesComboBox.getRawValue() != null && publicationsSaisiesComboBox.getRawValue().length() > 0) { |
if (!ce.isNavKeyPress()) { |
obtenirPublicationsSaisies(publicationsSaisiesComboBox.getRawValue()); |
} |
} |
} |
}); |
comboBox.addListener(Events.Select, new Listener<BaseEvent>() { |
@Override |
public void handleEvent(BaseEvent be) { |
if (publicationsSaisiesComboBox.getValue() instanceof Publication) { |
Publication publicationSaisieSelectionne = publicationsSaisiesComboBox.getValue(); |
ajouterDansGrille(publicationSaisieSelectionne); |
publicationsSaisiesComboBox.setValue(null); |
} |
} |
}); |
return comboBox; |
} |
private void ajouterDansGrille(Publication publication) { |
ajouterDansGrille(publication, 0); |
} |
private void ajouterDansGrille(Publication publication, int index) { |
if (publication != null) { |
if (!listePublicationsLiees.containsKey(publication.getId())) { |
PublicationAPersonne publicationLiee = new PublicationAPersonne(); |
publicationLiee.setPersonne(personneSelectionnee); |
publicationLiee.setPublicationLiee(publication); |
publicationLiee.setIdPublication(publication.getId()); |
publicationLiee.set("_etat_", aDonnee.ETAT_AJOUTE); |
listePublicationsLiees.put(publication.getId(), publicationLiee); |
// Ajout à la grille |
grille.stopEditing(); |
grille.getStore().insert(publicationLiee, 0); |
grille.startEditing(index, 0); |
grille.getSelectionModel().select(index, false); |
} else { |
Info.display("Information", "La publication choisie existe déjà dans la liste."); |
} |
} |
} |
/** |
* Met à jour la grille avec les informations contenus dans la variable listePublicationsLiees |
*/ |
private void mettreAJourGrille() { |
grille.getStore().removeAll(); |
grille.getStore().add(listePublicationsLiees.toList()); |
} |
private void supprimerDansGrille(PublicationAPersonne publicationLiee) { |
if (publicationLiee != null) { |
// Ajout de la personne supprimée à la liste |
if ((publicationLiee.get("_etat_").equals("") || !publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE)) |
&& publicationLiee.getId() != null |
&& !publicationLiee.getId().equals("")) { |
Debug.log("Nbre publications supprimées avant:"+publicationsSupprimees.size()); |
publicationsSupprimees.put("id"+idGenere++, publicationLiee); |
//GWT.log("Publications supprimée : "+publicationLiee.getIdPublication()+" "+publicationLiee.get.getNomComplet(), null); |
Debug.log("Nbre publications supprimées :"+publicationsSupprimees.size()); |
} |
// Suppression de l'enregistrement de la grille |
grille.getStore().remove(publicationLiee); |
} |
} |
private EditorGrid<PublicationAPersonne> creerGrille() { |
ListStore<PublicationAPersonne> storeGrille = new ListStore<PublicationAPersonne>(); |
storeGrille.addListener(Store.Add, new Listener<StoreEvent<PublicationAPersonne>>() { |
public void handleEvent(StoreEvent<PublicationAPersonne> ce) { |
actualiserEtatBoutonsBarreOutils(); |
} |
}); |
storeGrille.addListener(Store.Remove, new Listener<StoreEvent<PublicationAPersonne>>() { |
public void handleEvent(StoreEvent<PublicationAPersonne> ce) { |
actualiserEtatBoutonsBarreOutils(); |
} |
}); |
RowNumberer numeroPlugin = new RowNumberer(); |
numeroPlugin.setHeader("#"); |
XTemplate infoTpl = XTemplate.create("<p>"+ |
"<span style='font-weight:bold;'>"+i18nC.publicationAuteurs()+" :</span> {fmt_auteur}<br />"+ |
"<span style='font-weight:bold;'>"+i18nC.publicationTitre()+" :</span> {titre}<br />"+ |
"<span style='font-weight:bold;'>"+i18nC.publicationRevueCollection()+" :</span> {collection}<br />"+ |
"<span style='font-weight:bold;'>"+i18nC.publicationEditeur()+" :</span> {_editeur_}"+ |
"</p>"); |
RowExpander expansionPlugin = new RowExpander(); |
expansionPlugin.setTemplate(infoTpl); |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>(); |
colonnes.add(expansionPlugin); |
colonnes.add(numeroPlugin); |
typeRelationCombo = new ComboBox<Valeur>(); |
typeRelationCombo.setForceSelection(true); |
typeRelationCombo.setTriggerAction(TriggerAction.ALL); |
typeRelationCombo.setDisplayField("nom"); |
typeRelationCombo.setStore(new ListStore<Valeur>()); |
typeRelationCombo.setEditable(false); |
typeRelationCombo.addStyleName(ComposantClass.OBLIGATOIRE); |
typeRelationCombo.addListener(Events.Select, Formulaire.creerEcouteurChampObligatoire()); |
CellEditor editeurRelation = new CellEditor(typeRelationCombo) { |
@Override |
public Object preProcessValue(Object valeur) { |
Valeur retour = null; |
if (valeur != null ) { |
Debug.log(valeur.toString()); |
if (typeRelationCombo.getStore().findModel("nom", valeur.toString()) != null) { |
retour = typeRelationCombo.getStore().findModel("nom", valeur.toString()); |
} else if (typeRelationCombo.getStore().findModel("abr", valeur.toString()) != null) { |
retour = typeRelationCombo.getStore().findModel("abr", valeur.toString()); |
} else if (typeRelationCombo.getStore().findModel("id_valeur", valeur.toString()) != null) { |
retour = typeRelationCombo.getStore().findModel("id_valeur", valeur.toString()); |
} |
} |
return retour; |
} |
@Override |
public Object postProcessValue(Object valeur) { |
String retour = null; |
if (valeur != null ) { |
if (valeur instanceof Valeur) { |
Valeur valeurOntologie = (Valeur) valeur; |
retour = valeurOntologie.getId(); |
} |
} |
return retour; |
} |
}; |
GridCellRenderer<PublicationAPersonne> relationRendu = new GridCellRenderer<PublicationAPersonne>() { |
@Override |
public String render(PublicationAPersonne modele, String property, ColumnData config, int rowIndex, int colIndex, ListStore<PublicationAPersonne> store, Grid<PublicationAPersonne> grille) { |
// Gestion du texte afficher dans la cellule |
String role = modele.get("_role_"); |
String roleNom = ""; |
if (typeRelationCombo.getStore() != null && role!=null && role.matches("[0-9]+")) { |
roleNom = typeRelationCombo.getStore().findModel("id_valeur", role).getNom(); |
role = typeRelationCombo.getStore().findModel("id_valeur", role).getId(); |
} |
modele.set("_role_", role); |
modele.set("_etat_", aDonnee.ETAT_MODIFIE); |
return roleNom; |
} |
}; |
ColumnConfig typeRelationColonne = new ColumnConfig("_role_", i18nC.typeRelationPersonneCollection(), 75); |
typeRelationColonne.setEditor(editeurRelation); |
typeRelationColonne.setRenderer(relationRendu); |
colonnes.add(typeRelationColonne); |
colonnes.add(new ColumnConfig("fmt_auteur", i18nC.publicationAuteurs(), 150)); |
colonnes.add(new ColumnConfig("titre", i18nC.publicationTitre(), 150)); |
colonnes.add(new ColumnConfig("collection", i18nC.publicationRevueCollection(), 75)); |
colonnes.add(creerColonneEditeur()); |
colonnes.add(creerColonneAnneePublication()); |
colonnes.add(new ColumnConfig("indication_nvt", i18nC.publicationNvt(), 75)); |
colonnes.add(new ColumnConfig("fascicule", i18nC.publicationFascicule(), 75)); |
colonnes.add(new ColumnConfig("truk_pages", i18nC.publicationPage(), 50)); |
GridSelectionModel<PublicationAPersonne> modeleDeSelection = new GridSelectionModel<PublicationAPersonne>(); |
ColumnModel modeleDeColonnes = new ColumnModel(colonnes); |
modeleDeColonnes.getColumn(0).setWidget(Images.ICONES.information().createImage(), "Info"); |
EditorGrid<PublicationAPersonne> grillePublications = new EditorGrid<PublicationAPersonne>(storeGrille, modeleDeColonnes); |
grillePublications.setHeight("100%"); |
grillePublications.setBorders(true); |
grillePublications.setSelectionModel(modeleDeSelection); |
grillePublications.addPlugin(expansionPlugin); |
grillePublications.addPlugin(numeroPlugin); |
grillePublications.getView().setForceFit(true); |
grillePublications.setAutoExpandColumn("titre"); |
grillePublications.setStripeRows(true); |
grillePublications.setTrackMouseOver(true); |
return grillePublications; |
} |
private ColumnConfig creerColonneEditeur() { |
GridCellRenderer<PublicationAPersonne> editeurRendu = new GridCellRenderer<PublicationAPersonne>() { |
@Override |
public String render(PublicationAPersonne model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<PublicationAPersonne> store, Grid<PublicationAPersonne> grid) { |
String editeur = model.getPublicationLiee().getNomEditeur(); |
model.set("_editeur_", editeur); |
return editeur; |
} |
}; |
ColumnConfig editeurColonne = new ColumnConfig("_editeur_", Mediateur.i18nC.publicationEditeur(), 135); |
editeurColonne.setRenderer(editeurRendu); |
return editeurColonne; |
} |
private ColumnConfig creerColonneAnneePublication() { |
GridCellRenderer<PublicationAPersonne> datePublicationRendu = new GridCellRenderer<PublicationAPersonne>() { |
@Override |
public String render(PublicationAPersonne model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<PublicationAPersonne> store, Grid<PublicationAPersonne> grid) { |
String annee = model.getPublicationLiee().getAnneeParution(); |
model.set("_annee_", annee); |
return annee; |
} |
}; |
ColumnConfig datePublicationColonne = new ColumnConfig("_annee_", Mediateur.i18nC.publicationDateParution(), 75); |
datePublicationColonne.setRenderer(datePublicationRendu); |
return datePublicationColonne; |
} |
public void actualiserEtatBoutonsBarreOutils() { |
// Activation des boutons si la grille contient un élément |
if (grille.getStore().getCount() > 0) { |
publicationsBoutonSupprimer.enable(); |
publicationsBoutonModifier.enable(); |
} |
// Désactivation des boutons si la grille ne contient plus d'élément |
if (grille.getStore().getCount() == 0) { |
publicationsBoutonSupprimer.disable(); |
publicationsBoutonModifier.disable(); |
} |
} |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof Information) { |
Information info = (Information) nouvellesDonnees; |
rafraichirInformation(info); |
} else if (nouvellesDonnees instanceof ValeurListe) { |
ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees; |
if (listeValeurs.getId().equals(config.getListeId("relationPersonnePublication"))) { |
Formulaire.rafraichirComboBox(listeValeurs, typeRelationCombo); |
roles = listeValeurs.toList(); |
mettreAJourPersonne(); |
} |
} else if (nouvellesDonnees instanceof PublicationListe) { |
PublicationListe listePublications = (PublicationListe) nouvellesDonnees; |
rafraichirPublicationListe(listePublications); |
} else if (nouvellesDonnees instanceof PublicationAPersonneListe) { |
PublicationAPersonneListe papl = (PublicationAPersonneListe) nouvellesDonnees; |
List<PublicationAPersonne> paplListe = papl.toList(); |
if (paplListe.size()>0){ |
Iterator<PublicationAPersonne> it = paplListe.iterator(); |
while (it.hasNext()) { |
PublicationAPersonne pap = it.next(); |
listePublicationsLiees.put(pap.getPublicationLiee().getId(), pap); |
} |
mettreAJourGrille(); |
} |
} else { |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null); |
} |
} |
private void rafraichirPublicationListe(PublicationListe listePublications) { |
publicationsSaisiesComboBox.getStore().removeAll(); |
publicationsSaisiesComboBox.getStore().add(listePublications.toList()); |
publicationsSaisiesComboBox.expand(); |
} |
public void rafraichirInformation(Information info) { |
if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) { |
GWT.log("MESSAGES:\n"+info.getMessages().toString(), null); |
} |
String type = info.getType(); |
if (type.equals("publication_liees")) { |
if (info.getDonnee(0) != null) { |
initialiser(); |
personneSelectionnee.setPublicationsLiees((PublicationAPersonneListe) info.getDonnee(0)); |
peupler(); |
} |
} else if (type.equals("publication_modifiee")) { |
if (info.getDonnee(0) != null) { |
Publication publication = (Publication) info.getDonnee(0); |
PublicationAPersonne publicationDansGrille = grille.getStore().findModel("id_publication", publication.getId()); |
int index = grille.getStore().indexOf(publicationDansGrille); |
grille.getStore().remove(publicationDansGrille); |
ajouterDansGrille(publication, index); |
} |
} else if (type.equals("publication_ajoutee")) { |
if (info.getDonnee(0) != null) { |
Publication publication = (Publication) info.getDonnee(0); |
ajouterDansGrille(publication); |
} |
} else if (type.equals("suppression_collection_a_publication")) { |
Info.display("Suppression des publications liées à la collection", info.toString()); |
} else if (type.equals("ajout_collection_a_publication")) { |
Info.display("Ajout des publications liées à la collection", info.toString()); |
} else { |
GWT.log(Mediateur.i18nM.erreurRafraichir(info.getClass(), this.getClass()), null); |
} |
} |
public void peupler() { |
grille.getStore().removeAll(); |
grille.getStore().add(personneSelectionnee.getPublicationsLiees().toList()); |
layout(); |
Info.display(i18nC.chargementPublication(), i18nC.ok()); |
} |
public void collecter() { |
if (etreAccede()) { |
int nbrePublication = grille.getStore().getCount(); |
for (int i = 0; i < nbrePublication; i++) { |
PublicationAPersonne publicationLiee = grille.getStore().getAt(i); |
if (publicationLiee.get("_etat_") != null) { |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_MODIFIE)) { |
// Comme il est impossible de modifier les relations nous supprimons l'ancien enregistrement et ajoutons un nouveau avec le nouveau id_role |
publicationsSupprimees.put("id"+idGenere++, publicationLiee); |
PublicationAPersonne relationAAjouter = (PublicationAPersonne) publicationLiee.cloner(new PublicationAPersonne()); |
publicationsAjoutees.put("id"+idGenere++, relationAAjouter); |
Debug.log(publicationLiee.toString()); |
} |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE)) { |
publicationsAjoutees.put("id"+idGenere++, publicationLiee); |
Debug.log(publicationLiee.toString()); |
} |
// Initialisation de la grille |
publicationLiee.set("_etat_", ""); |
} |
} |
grille.getStore().commitChanges(); |
} |
} |
public List verifier() { |
List lstMessageErreur = new LinkedList<String>(); |
//Vérifier les roles |
List<PublicationAPersonne> listePublis = grille.getStore().getModels(); |
Iterator<PublicationAPersonne> itPublis = listePublis.iterator(); |
while (itPublis.hasNext()) { |
PublicationAPersonne publi = itPublis.next(); |
if (UtilString.isEmpty((String) publi.get("_role_"))) { |
lstMessageErreur.add("Vous devez choisir le rôle de la relation " + (grille.getStore().indexOf(publi) + 1)); |
} |
} |
return lstMessageErreur; |
} |
public void soumettre() { |
if (mode.equals(Formulaire.MODE_MODIFIER)) { |
if (publicationsAjoutees.size() == 0 && publicationsSupprimees.size() == 0) { |
Info.display("Modification des publications liées", "Rien n'a été enregistré car le formulaire n'a pas été modifié."); |
} else { |
// Ajout des relations CollectionAPublication |
if (publicationsAjoutees.size() != 0) { |
//TODO : utiliser le role d'une liste déroulante |
mediateur.ajouterPublicationAPersonne(this, publicationsAjoutees, personneSelectionnee.getId(), null); |
} |
// Suppression des relations CollectionAPublication |
if (publicationsSupprimees.size() != 0) { |
mediateur.supprimerPublicationAPersonne(this, publicationsSupprimees); |
} |
} |
} |
} |
private void obtenirPublicationsSaisies(String nom) { |
mediateur.selectionnerPublicationParNomComplet(this, null, "%"+nom+"%"); |
} |
} |
/branches/v1.0-syrah/src/org/tela_botanica/client/vues/personne/PersonneVue.java |
---|
New file |
0,0 → 1,65 |
package org.tela_botanica.client.vues.personne; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.RegistreId; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.Information; |
import org.tela_botanica.client.modeles.personne.Personne; |
import org.tela_botanica.client.modeles.personne.PersonneListe; |
import org.tela_botanica.client.util.Debug; |
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.LayoutRegion; |
import com.extjs.gxt.ui.client.util.Margins; |
import com.extjs.gxt.ui.client.widget.Info; |
import com.extjs.gxt.ui.client.widget.LayoutContainer; |
import com.extjs.gxt.ui.client.widget.layout.BorderLayout; |
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData; |
import com.google.gwt.core.client.GWT; |
public class PersonneVue extends LayoutContainer implements Rafraichissable { |
private PersonneListeVue panneauPersonneListe; |
private PersonneDetailVue panneauPersonneDetail; |
private Mediateur mediateur = null; |
public PersonneVue(Mediateur mediateur) { |
this.mediateur = mediateur; |
BorderLayout layout = new BorderLayout(); |
layout.setEnableState(false); |
setLayout(layout); |
panneauPersonneListe = new PersonneListeVue(); |
this.add(panneauPersonneListe, new BorderLayoutData(LayoutRegion.CENTER)); |
panneauPersonneDetail = new PersonneDetailVue(mediateur); |
BorderLayoutData southData = new BorderLayoutData(LayoutRegion.SOUTH, .5f, 200, 1000); |
southData.setSplit(true); |
southData.setMargins(new Margins(5, 0, 0, 0)); |
this.add(panneauPersonneDetail, southData); |
} |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof Personne) { |
panneauPersonneDetail.rafraichir((Personne) nouvellesDonnees); |
} else if (nouvellesDonnees instanceof PersonneListe) { |
panneauPersonneListe.rafraichir((PersonneListe) nouvellesDonnees); |
} else if (nouvellesDonnees instanceof Information) { |
Information info = (Information) nouvellesDonnees; |
// Affichage des éventuels messages de déboguage ou d'alerte |
if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) { |
GWT.log(info.getMessages().toString(), null); |
} |
// Traitement en fonction des types d'information |
if (info.getType().equals("liste_personne")) { |
panneauPersonneListe.rafraichir((PersonneListe) info.getDonnee(0)); |
Info.display("Chargement d'une liste de personnes", ""); |
} else { |
panneauPersonneListe.rafraichir(info); |
} |
} else { |
GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null); |
} |
} |
} |
/branches/v1.0-syrah/src/org/tela_botanica/client/vues/personne/PersonneListeVue.java |
---|
New file |
0,0 → 1,205 |
package org.tela_botanica.client.vues.personne; |
import java.util.ArrayList; |
import java.util.List; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.RegistreId; |
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.Utilisateur; |
import org.tela_botanica.client.modeles.personne.Personne; |
import org.tela_botanica.client.modeles.personne.PersonneListe; |
import org.tela_botanica.client.vues.BarrePaginationVue; |
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.SortDir; |
import com.extjs.gxt.ui.client.event.BaseEvent; |
import com.extjs.gxt.ui.client.event.ButtonEvent; |
import com.extjs.gxt.ui.client.event.Events; |
import com.extjs.gxt.ui.client.event.Listener; |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent; |
import com.extjs.gxt.ui.client.event.SelectionChangedListener; |
import com.extjs.gxt.ui.client.event.SelectionListener; |
import com.extjs.gxt.ui.client.store.ListStore; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Info; |
import com.extjs.gxt.ui.client.widget.button.Button; |
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.Grid; |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel; |
import com.extjs.gxt.ui.client.widget.layout.FitLayout; |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; |
import com.google.gwt.core.client.GWT; |
public class PersonneListeVue extends ContentPanel implements Rafraichissable { |
private Mediateur mediateur = null ; |
private Grid<Personne> grille = null; |
private ListStore<Personne> store = null; |
private BarrePaginationVue pagination = null; |
private ColumnModel modeleColonnes = null; |
private Button ajouter = null; |
private Button modifier = null; |
private Button supprimer = null; |
public PersonneListeVue() { |
mediateur = Registry.get(RegistreId.MEDIATEUR); |
setHeading(Mediateur.i18nC.personneListeLabel()); |
setLayout(new FitLayout()); |
//Définition de la barre d'outil |
ToolBar toolBar = new ToolBar(); |
ajouter = new Button(Mediateur.i18nC.ajouter()); |
ajouter.setIcon(Images.ICONES.ajouter()); |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent ce) { |
mediateur.clicAjouterPersonne(); |
} |
}); |
toolBar.add(ajouter); |
modifier = new Button(Mediateur.i18nC.modifier()); |
modifier.setIcon(Images.ICONES.formModifier()); |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent ce) { |
mediateur.clicModifierPersonne(grille.getSelectionModel().getSelectedItems()); |
} |
}); |
toolBar.add(modifier); |
supprimer = new Button(Mediateur.i18nC.supprimer()); |
supprimer.setIcon(Images.ICONES.supprimer()); |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent ce) { |
clicSupprimerPersonne(grille.getSelectionModel().getSelectedItems()); |
} |
}); |
toolBar.add(supprimer); |
setTopComponent(toolBar); |
// Définition des colomnes de la grille: |
List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>(); |
lstColumns.add(new ColumnConfig("id_personne", "Id", 45)); |
lstColumns.add(new ColumnConfig("nom", "Nom", 100)); |
lstColumns.add(new ColumnConfig("prenom", "Prénom", 100)); |
lstColumns.add(new ColumnConfig("fmt_nom_complet", "Nom Complet", 200)); |
lstColumns.add(new ColumnConfig("code_postal", "Code postal", 100)); |
lstColumns.add(new ColumnConfig("ville", "Ville", 100)); |
lstColumns.add(new ColumnConfig("_courriel_princ_", "Courriel", 200)); |
lstColumns.get(0).setHidden(true); |
lstColumns.get(1).setHidden(true); |
lstColumns.get(2).setHidden(true); |
modeleColonnes = new ColumnModel(lstColumns); |
// Définition de la grille |
GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>(); |
gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() { |
public void selectionChanged(SelectionChangedEvent<Personne> event) { |
Personne personneSelectionnee = (Personne) event.getSelectedItem(); |
clicListe(personneSelectionnee); |
} |
}); |
store = new ListStore<Personne>(); |
store.sort("fmt_nom_complet", SortDir.ASC); |
grille = new Grid<Personne>(store, modeleColonnes); |
grille.setSelectionModel(gsmSelectionGrille); |
grille.setWidth("100%"); |
grille.setAutoExpandColumn("fmt_nom_complet"); |
grille.getView().setAutoFill(true); |
grille.getView().setForceFit(true); |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() { |
@Override |
public void handleEvent(BaseEvent be) { |
grille.getStore().sort("fmt_nom_complet", SortDir.ASC); |
grille.getSelectionModel().select(0, false); |
} |
}); |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){ |
@Override |
public void handleEvent(BaseEvent be) { |
modifier.fireEvent(Events.Select); |
} |
}); |
add(grille); |
// Définition de la barre de pagination |
pagination = new BarrePaginationVue(new PersonneListe(), mediateur); |
setBottomComponent(pagination); |
} |
private void clicListe(Personne personne) { |
if (personne != null && store.getCount() > 0) { |
mediateur.clicListePersonne(personne); |
} |
} |
private void clicSupprimerPersonne(List<Personne> personnesASupprimer) { |
if (store.getCount() > 0) { |
mediateur.clicSupprimerPersonne(this, personnesASupprimer); |
} |
} |
private void gererEtatActivationBouton() { |
int nbreElementDuMagazin = store.getCount(); |
ajouter.enable(); |
if (nbreElementDuMagazin == 0) { |
supprimer.disable(); |
modifier.disable(); |
} else if (nbreElementDuMagazin > 0) { |
modifier.enable(); |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) { |
supprimer.enable(); |
} |
} |
} |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof PersonneListe) { |
PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees; |
pagination.setlistePaginable(listePersonnes); |
pagination.rafraichir(listePersonnes.getPageTable()); |
if (listePersonnes != null) { |
List<Personne> liste = (List<Personne>) listePersonnes.toList(); |
store.removeAll(); |
store.add(liste); |
mediateur.desactiverChargement(); |
mediateur.actualiserPanneauCentral(); |
grille.fireEvent(Events.ViewReady); |
} |
} else if (nouvellesDonnees instanceof Information) { |
Information info = (Information) nouvellesDonnees; |
if (info.getType().equals("suppression_personne")) { |
Info.display("Suppression de personne", info.getMessages().toString()); |
pagination.getlistePaginable().recharger(); |
gererEtatActivationBouton(); |
} else if (info.getType().equals("maj_utilisateur")) { |
gererEtatActivationBouton(); |
} else { |
Info.display("Erreur", info.getMessages().toString()); |
} |
} else { |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null); |
} |
layout(); |
} |
} |
/branches/v1.0-syrah/src/org/tela_botanica/client/vues/personne/PersonneDetailVue.java |
---|
New file |
0,0 → 1,368 |
package org.tela_botanica.client.vues.personne; |
import java.util.Collection; |
import java.util.HashMap; |
import java.util.Iterator; |
import java.util.LinkedList; |
import java.util.MissingResourceException; |
import org.tela_botanica.client.ComposantId; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.RegistreId; |
import org.tela_botanica.client.configuration.Configuration; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.Valeur; |
import org.tela_botanica.client.modeles.ValeurListe; |
import org.tela_botanica.client.modeles.personne.Personne; |
import org.tela_botanica.client.util.Debug; |
import org.tela_botanica.client.vues.DetailVue; |
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.Scroll; |
import com.extjs.gxt.ui.client.util.Format; |
import com.extjs.gxt.ui.client.util.Params; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Html; |
import com.extjs.gxt.ui.client.widget.TabItem; |
import com.extjs.gxt.ui.client.widget.TabPanel; |
import com.extjs.gxt.ui.client.widget.form.FieldSet; |
import com.extjs.gxt.ui.client.widget.form.LabelField; |
import com.extjs.gxt.ui.client.widget.layout.AnchorLayout; |
import com.extjs.gxt.ui.client.widget.layout.FitLayout; |
import com.extjs.gxt.ui.client.widget.layout.FlowLayout; |
import com.google.gwt.user.client.ui.Image; |
public class PersonneDetailVue extends DetailVue implements Rafraichissable { |
private TabPanel tabPanel; |
private Html entete; |
private TabItem tabIdentite; |
private TabItem tabAdresse; |
private TabItem tabInfosNat; |
private TabItem tabLogos; |
private HashMap hmLabelFieldRegion = new HashMap(); |
private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG); |
private boolean ontologieRecue = false; |
private Personne personneAAfficher = null; |
private void chargerOntologie() { |
mediateur.obtenirListeValeurEtRafraichir(this, "pays"); |
mediateur.obtenirListeValeurEtRafraichir(this, "tel"); |
} |
public PersonneDetailVue(Mediateur mediateur) { |
super(mediateur); |
chargerOntologie(); |
mediateur.obtenirListeValeurEtRafraichir(this, "pays"); |
setLayout(new FitLayout()); |
entete = new Html(); |
entete.setId(ComposantId.ZONE_DETAIL_ENTETE); |
ContentPanel panneauPrincipal = new ContentPanel(); |
panneauPrincipal.setLayout(new FitLayout()); |
panneauPrincipal.setHeaderVisible(false); |
panneauPrincipal.setBodyBorder(true); |
panneauPrincipal.setTopComponent(entete); |
tabIdentite = new TabItem(i18nC.personneIdentite()); |
tabIdentite.setLayout(new AnchorLayout()); |
tabIdentite.setScrollMode(Scroll.AUTO); |
tabAdresse = new TabItem(i18nC.personneAdresses()); |
tabAdresse.setLayout(new FitLayout()); |
tabAdresse.setScrollMode(Scroll.AUTO); |
tabInfosNat = new TabItem(i18nC.personneInfoNat()); |
tabInfosNat.setScrollMode(Scroll.AUTO); |
tabLogos = new TabItem(i18nC.personneLogos()); |
tabLogos.setScrollMode(Scroll.AUTO); |
tabLogos.setLayout(new FlowLayout()); |
tabPanel = new TabPanel(); |
tabPanel.setId(ComposantId.ZONE_DETAIL_CORPS); |
tabPanel.setBodyBorder(false); |
tabPanel.add(tabIdentite); |
tabPanel.add(tabAdresse); |
tabPanel.add(tabInfosNat); |
tabPanel.add(tabLogos); |
panneauPrincipal.add(tabPanel); |
add(panneauPrincipal); |
} |
public void afficherDetailPersonne(Personne personne) { |
if (personne != null) { |
String tplEntete = initialiserTplEntete(); |
Params enteteParams = new Params(); |
enteteParams.set("nom", (String) personne.get("fmt_nom_complet")); |
enteteParams.set("mail", (String) personne.getCourrielPrinc()); |
LinkedList lstLogos = (LinkedList) personne |
.getChaineDenormaliseAsMapOrList("truk_logo"); |
if (lstLogos != null && lstLogos.size() > 0) { |
tabLogos.removeAll(); |
String urlLogoPrinc = (String) lstLogos.get(0); |
if (!urlLogoPrinc.trim().equals("")) { |
tplEntete = "<div id='personne-logo-div'><img src='{image}' alt='logo' /></div>" |
+ tplEntete; |
enteteParams.set("image", urlLogoPrinc); |
} |
Iterator<String> itLogo = lstLogos.iterator(); |
while (itLogo.hasNext()) { |
String urlLogoCourant = itLogo.next(); |
Image imgCourante = new Image(urlLogoCourant); |
tabLogos.add(imgCourante); |
} |
tabLogos.enable(); |
} else { |
enteteParams.set("image", ""); |
tabLogos.disable(); |
} |
entete.el().setInnerHtml(Format.substitute(tplEntete, enteteParams)); |
String tplIdentite = initialiserTplIdentite(); |
Params tabIdentiteParams = new Params(); |
tabIdentiteParams.set("nom_complet", personne.getString("fmt_nom_complet")); |
tabIdentiteParams.set("abreviation", personne.getString("abreviation")); |
tabIdentiteParams.set("naissance_date", personne.getNaissanceDate()); |
tabIdentiteParams.set("naissance_lieu", personne.getString("naissance_lieu")); |
String tplDeces = ""; |
if (personne.estDecedee()) { |
tplDeces = " <h2>Décès:</h2>" |
+ " <span><b>" |
+ i18nC.personneDateDeces() |
+ ":</b></span> {deces_date}<br />" |
+ " <span><b>" |
+ i18nC.personneLieuDeces() |
+ ":</b></span> {deces_lieu}<br /><br />"; |
tabIdentiteParams.set("deces_date", personne.getDecesDate()); |
tabIdentiteParams.set("deces_lieu", personne.getString("deces_lieu")); |
} |
Params paramsDeces = new Params(); |
paramsDeces.set("tplDeces", tplDeces); |
tplIdentite = Format.substitute(tplIdentite, paramsDeces); |
tabIdentiteParams.set("description", personne.getString("description")); |
tabInfosNat.removeAll(); |
tabIdentiteParams.set("nom_autre", construireTxtTruck(personne.getString("truk_nom_autre"))); |
tabIdentiteParams.set("abreviation_autre", construireTxtTruck(personne.getString("truk_abreviation_autre"))); |
tplIdentite += construireTxtListeOntologie(personne.getString("truk_telephone")); |
// Courriel :Champ truk de la forme |
// "Adresse@adr.com;; adr2@adr.fr ..." |
LinkedList<String> listeCourriel = (LinkedList<String>) personne |
.getChaineDenormaliseAsMapOrList("truk_courriel"); |
if ((listeCourriel != null) && (listeCourriel.size() > 0)) { |
String strLabelCourriel = "Courriel"; |
if (listeCourriel.size() > 1) { |
strLabelCourriel += "s"; |
} |
String valeurCourriel = ""; |
Iterator<String> itCourriel = listeCourriel.iterator(); |
while (itCourriel.hasNext()) { |
String valeurCourante = itCourriel.next(); |
valeurCourriel += "<br /><a href=\"mailto:" |
+ valeurCourante + "\">" + valeurCourante + "</a>"; |
} |
tplIdentite += valeurCourriel; |
} |
// Url Site Webs |
LinkedList listeUrl = (LinkedList) personne |
.getChaineDenormaliseAsMapOrList("truk_url"); |
if (listeUrl != null && listeUrl.size() > 0) { |
tplIdentite += "<br /><br /><b>Sites web:</b><br /><span style='display:inline-block'>"; |
String strUrl = ""; |
Iterator<String> urlIt = listeUrl.iterator(); |
while (urlIt.hasNext()) { |
String urlCourante = urlIt.next(); |
strUrl += "<a href=\"" + urlCourante + "\">" + urlCourante |
+ "</a> <br/>"; |
} |
tplIdentite += strUrl + "</span><br />"; |
} |
tplIdentite += "</div>"; |
afficherOnglet(tplIdentite, tabIdentiteParams, tabIdentite); |
String tabAdresseTpl = "<div class='{css_corps}'>" |
+ " <div class='{css_fieldset}'>" |
+ " <h2>Adresse personnelle:</h2>" |
+ " <b>Adresse:</b> {adresse01} <br />" |
+ " <b>Complément d'adresse: </b>{adresse02} <br />" |
+ " <b>Boite postale: </b>{boitePostale}<br />" |
+ " <b>Code postal:</b>{codePostal} <br />" |
+ " <b>Région:</b>{region}<br />" |
+ " <span style='uppercase'>{pays}</span><br />" |
+ "</div>"; |
// Adresses : |
Params paramAdresseTpl = new Params(); |
paramAdresseTpl.set("adresse01", (String) personne |
.obtenirValeurChamp("adresse_01")); |
paramAdresseTpl.set("adresse02", (String) personne |
.obtenirValeurChamp("adresse_02")); |
paramAdresseTpl.set("boitePostale", (String) personne |
.obtenirValeurChamp("bp")); |
paramAdresseTpl.set("codePostal", (String) personne |
.obtenirValeurChamp("code_postal")); |
paramAdresseTpl.set("ville", (String) personne |
.obtenirValeurChamp("ville")); |
paramAdresseTpl.set("region", (String) personne |
.obtenirValeurChamp("region")); |
paramAdresseTpl.set("pays", (String) personne |
.obtenirValeurChamp("pays")); |
afficherOnglet(tabAdresseTpl, paramAdresseTpl, tabAdresse); |
tabAdresse.setStyleAttribute("padding", "15px"); |
// Infos naturalistes :Biographie, Spécialité (typé) |
String tplInfosNat = "<div class='{css_corps}'>" |
+ " <div class='{css_fieldset}'>" + " <h2>" |
+ i18nC.personneSpecialite() + "</h1>" |
+ " {specialites}" + " <h2>" |
+ i18nC.personneRecolte() + "</h2>" |
+ " {recoltes}" + " </div>" + "</div>"; |
Params prmInfosNat = new Params(); |
// TODO : replace id region par valeur |
String specialite = construireTxtTruck(personne.getSpecialite()); |
prmInfosNat.set("specialites", specialite); |
String recolte = construireTxtListeOntologie(personne.getString("truk_recolte")); |
prmInfosNat.set("recoltes", recolte); |
afficherOnglet(tplInfosNat, prmInfosNat, tabInfosNat); |
tabAdresse.setStyleAttribute("padding", "15px"); |
changerLabelRegions(); |
layout(); |
} |
} |
public String initialiserTplEntete() { |
return "<div id='{css_id}'>" + "<h1>{nom}</h1>" |
+ "<h2><a href='{mail}'>{mail}</a></h2>" + "</div>"; |
} |
public String initialiserTplIdentite() { |
return "<div class='{css_corps}'>" + " <div class='{css_fieldset}'>" |
+ " <h2>Noms:</h2>" + " <span><b>" |
+ i18nC.personneNomComplet() |
+ ":</b></span> {nom_complet}<br />" |
+ " <span><b>" |
+ i18nC.personneNomAutre() |
+ ":</b></span> {nom_autre}<br />" |
+ " <span><b>" |
+ i18nC.personneAbreviation() |
+ ":</b></span> {abreviation}<br />" |
+ " <span><b>" |
+ i18nC.personneAbreviationAutre() |
+ ":</b></b></span> {abreviation_autre}<br /><br />" |
+ " <h2>Naissance:</h2>" |
+ " <span><b>" |
+ i18nC.personneDateNaissance() |
+ ":</b></span> {naissance_date}<br />" |
+ " <span><b>" |
+ i18nC.personneLieuNaissance() |
+ ":</b></span> {naissance_lieu}<br /><br />" |
+ "{tplDeces}" |
+ " </div>" |
+ "</div>" |
+ "<div class='{css_corps}'>" |
+ " <div class='css_fieldset'> " |
+ " <h2>Description:</h2>" |
+ " {description}<br />" + " </div>" + "<br />"; |
} |
private void changerLabelRegions() { |
Collection<String> colClesComposants = hmLabelFieldRegion.keySet(); |
Iterator<String> itComposants = colClesComposants.iterator(); |
while (itComposants.hasNext()) { |
String region = itComposants.next(); |
mediateur.obtenirValeurEtRafraichir(this, "region", region); |
} |
} |
private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue) { |
if ((tfValue != null) && (!tfValue.toString().trim().equals(""))) { |
LabelField tf = new LabelField(); |
tf.setFieldLabel(tfLabel + ":"); |
if ((tfLabel == null) || ("".equals(tfLabel))) { |
tf.setHideLabel(true); |
tf.setStyleAttribute("margin", "0 0 0 105px"); |
} |
tf.setValue(tfValue); |
// Ajout au fieldSet |
fs.add(tf); |
} |
} |
public void rafraichir(Object nouvellesDonnees) { |
// Si on a reçu une personne on en affiche les détails |
if (nouvellesDonnees instanceof Personne) { |
personneAAfficher = (Personne) nouvellesDonnees; |
} else if (nouvellesDonnees instanceof ValeurListe) { |
ValeurListe ontologieReceptionnee = (ValeurListe) nouvellesDonnees; |
ajouterListeValeursAOntologie(ontologieReceptionnee); |
ontologieRecue = true; |
// Remplacer ci-dessous par Ontologie |
ValeurListe listeValeur = (ValeurListe) nouvellesDonnees; |
if (listeValeur.getId().equals(config.getListeId("region"))) { |
Collection colCleListeValeur = listeValeur.keySet(); |
Iterator<String> itLv = colCleListeValeur.iterator(); |
while (itLv.hasNext()) { |
String idRegion = itLv.next(); |
Valeur region = listeValeur.get(idRegion); |
if (region != null) { |
String strRegionId = region.getAbreviation(); |
LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId); |
for (int i = 0; i < listComposantsRegion.size(); i++) { |
LabelField lfRegion = listComposantsRegion.get(i); |
lfRegion.setFieldLabel(region.getNom()); |
} |
} |
} |
} |
} |
if (ontologieRecue && personneAAfficher != null) { |
afficherDetailPersonne(personneAAfficher); |
} |
} |
} |
/branches/v1.0-syrah/src/org/tela_botanica/client/vues/personne/PersonneForm.java |
---|
New file |
0,0 → 1,1278 |
package org.tela_botanica.client.vues.personne; |
import java.util.ArrayList; |
import java.util.Collection; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.Iterator; |
import java.util.LinkedList; |
import java.util.List; |
import org.tela_botanica.client.ComposantClass; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.RegistreId; |
import org.tela_botanica.client.composants.ChampMultiValeurs; |
import org.tela_botanica.client.composants.ChampMultiValeursImage; |
import org.tela_botanica.client.composants.ChampMultiValeursMultiTypes; |
import org.tela_botanica.client.composants.HashMapComposants; |
import org.tela_botanica.client.configuration.Configuration; |
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.MenuApplicationId; |
import org.tela_botanica.client.modeles.Valeur; |
import org.tela_botanica.client.modeles.ValeurListe; |
import org.tela_botanica.client.modeles.personne.Personne; |
import org.tela_botanica.client.modeles.personne.PersonneListe; |
import org.tela_botanica.client.modeles.projet.Projet; |
import org.tela_botanica.client.modeles.projet.ProjetListe; |
import org.tela_botanica.client.modeles.publication.Publication; |
import org.tela_botanica.client.modeles.publication.PublicationAPersonneListe; |
import org.tela_botanica.client.modeles.publication.PublicationListe; |
import org.tela_botanica.client.util.Pattern; |
import org.tela_botanica.client.util.UtilString; |
import org.tela_botanica.client.vues.Formulaire; |
import com.extjs.gxt.ui.client.event.Events; |
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.Scroll; |
import com.extjs.gxt.ui.client.Style.VerticalAlignment; |
import com.extjs.gxt.ui.client.binding.FormBinding; |
import com.extjs.gxt.ui.client.event.ButtonEvent; |
import com.extjs.gxt.ui.client.event.ComponentEvent; |
import com.extjs.gxt.ui.client.event.KeyListener; |
import com.extjs.gxt.ui.client.event.Listener; |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent; |
import com.extjs.gxt.ui.client.event.SelectionChangedListener; |
import com.extjs.gxt.ui.client.event.SelectionListener; |
import com.extjs.gxt.ui.client.store.ListStore; |
import com.extjs.gxt.ui.client.widget.LayoutContainer; |
import com.extjs.gxt.ui.client.widget.MessageBox; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Info; |
import com.extjs.gxt.ui.client.widget.TabItem; |
import com.extjs.gxt.ui.client.widget.TabPanel; |
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.DateField; |
import com.extjs.gxt.ui.client.widget.form.FieldSet; |
import com.extjs.gxt.ui.client.widget.form.LabelField; |
import com.extjs.gxt.ui.client.widget.form.Radio; |
import com.extjs.gxt.ui.client.widget.form.RadioGroup; |
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.layout.ColumnData; |
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout; |
import com.extjs.gxt.ui.client.widget.layout.FitLayout; |
import com.extjs.gxt.ui.client.widget.layout.FormData; |
import com.extjs.gxt.ui.client.widget.layout.FormLayout; |
import com.extjs.gxt.ui.client.widget.layout.RowLayout; |
import com.extjs.gxt.ui.client.widget.layout.TableData; |
import com.extjs.gxt.ui.client.widget.layout.TableLayout; |
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.DateTimeFormat; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.Widget; |
public class PersonneForm extends Formulaire implements Rafraichissable { |
// VARIABLES |
private TabItem tiIdentite, tiAdresses, tiInfosNat; |
PersonneFormPublication tiPubli; |
private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG); |
protected Personne personneSelectionnee, personneSauvegarde = null; |
//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite |
private HashMapComposants hmIdentite = new HashMapComposants(); |
private HashMapComposants hmAdresse = new HashMapComposants(); |
private HashMapComposants hmInfosNat = new HashMapComposants(); |
private HashMap<String, Valeur> hmCbSelectionnee = new HashMap(); |
private FormData fd100 = new FormData("95%"); |
private Button enregistrer, enregistrerEtRevenir; |
private Personne personne = null; |
private String personneId = null; |
private FormBinding binding = null; |
//Publi |
private ComboBox<Publication> cbPubli; |
private ListStore<Publication> storePubli; |
// CONSTRUCTEUR |
public PersonneForm(Mediateur mediateurCourrant, String personneId) { |
initialiserPersonneForm(mediateurCourrant, personneId); |
} |
public PersonneForm(Mediateur mediateurCourrant, String personneId, Rafraichissable vueARafraichirApresValidation) { |
vueExterneARafraichirApresValidation = vueARafraichirApresValidation; |
initialiserPersonneForm(mediateurCourrant, personneId); |
} |
private void initialiserPersonneForm(Mediateur mediateurCourrant, String personneIdCourrant) { |
personne = new Personne(); |
personne.setId(personneIdCourrant); |
personneId = personneIdCourrant; |
String modeDeCreation = (UtilString.isEmpty(personneId) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER); |
initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.PERSONNE); |
initialiserComposants(); |
genererTitreFormulaire(); |
mediateur.obtenirListeValeurEtRafraichir(this, "relationPersonnePublication"); |
if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) { |
mediateur.selectionnerPersonne(this, personne, null); |
} |
} |
private void genererTitreFormulaire() { |
String titre = i18nC.personneModeAjout(); |
if (mode.equals(Formulaire.MODE_MODIFIER)) { |
titre = i18nC.personneModeModifier()+" - "+i18nC.id()+": "+personneId; |
} |
panneauFormulaire.setHeading(titre); |
} |
public void initialiserComposants() { |
personneSelectionnee = new Personne(); |
personneSauvegarde = new Personne(); |
initialiserOnglets(); |
creerComposantsIdentite(); |
creerComposantsAdresse(); |
creerComposantsInfosNat(); |
//creerComposantsPubli(); |
binderPersonne(personneSelectionnee); |
} |
/** |
* Crée les onglets identité, adresse et informations naturaliste |
* |
* */ |
public void initialiserOnglets() { |
//TabPanel |
TabPanel formulaireOnglets = new TabPanel(); |
//Tab 1 : identite |
tiIdentite = creerOnglet(i18nC.personneIdentite(), "tiIdentite"); |
tiIdentite.setStyleAttribute("padding", "0"); |
formulaireOnglets.add(tiIdentite); |
//Tab 2 : Adresse |
tiAdresses = creerOnglet(i18nC.adresse(), "tiAdresses"); |
formulaireOnglets.add(tiAdresses); |
//Tab 3 : Infos Naturalistes |
tiInfosNat = creerOnglet(i18nC.personneInfoNat(), "tiInfosNat"); |
formulaireOnglets.add(tiInfosNat); |
tiPubli = new PersonneFormPublication(this); |
formulaireOnglets.add(tiPubli); |
getFormulaire().add(formulaireOnglets); |
} |
/** |
* Crée les widgets pour l'onglet identité |
* |
* */ |
public void creerComposantsIdentite() { |
// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite |
LayoutContainer left = new LayoutContainer(); |
left.setLayout(new FormLayout()); |
left.setStyleAttribute("padding", "15px"); |
LayoutContainer right = new LayoutContainer(); |
right.setLayout(new FormLayout()); |
right.setStyleAttribute("padding", "15px"); |
LayoutContainer main = new LayoutContainer(); |
main.add(left, new ColumnData(.45)); |
main.add(right, new ColumnData(.45)); |
main.setLayout(new ColumnLayout()); |
main.setHeight("100%"); |
main.setScrollMode(Scroll.AUTO); |
// Création des champs |
FormLayout formLayout = new FormLayout(); |
formLayout.setLabelAlign(LabelAlign.LEFT); |
//+------------------------------------------------------------------------------------------------------------+ |
// Fieldset PROJET |
FieldSet fsProjet = new FieldSet(); |
fsProjet.setHeading(i18nC.menuProjet()); |
fsProjet.setLayout(new FormLayout()); |
ListStore<Projet> storeProjets = new ListStore<Projet>(); |
ComboBox cbProjets = new ComboBox<Projet>(); |
cbProjets.setFieldLabel(i18nC.personneProjet()+ " :"); |
cbProjets.setEmptyText(i18nC.txtListeProjetDefaut()); |
cbProjets.setLabelSeparator(""); |
cbProjets.setDisplayField("nom"); |
cbProjets.setEditable(false); |
cbProjets.setTriggerAction(TriggerAction.ALL); |
cbProjets.setStore(storeProjets); |
cbProjets.setAllowBlank(false); |
cbProjets.addStyleName(ComposantClass.OBLIGATOIRE); |
cbProjets.addListener(Events.Valid, creerEcouteurChampObligatoire()); |
fsProjet.add(cbProjets, new FormData(450, 0)); |
hmIdentite.put("cbProjets", cbProjets); |
mediateur.selectionnerProjet(this, null); |
left.add(fsProjet); |
//+------------------------------------------------------------------------------------------------------------+ |
// Fieldset NOM |
FieldSet fsNoms = new FieldSet(); |
fsNoms.setHeading("Noms"); |
fsNoms.setLayout(formLayout); |
// Nom complet : Affiché que si valeurs saisies |
LabelField nomComplet = new LabelField(); |
nomComplet.setFieldLabel(i18nC.personneNomComplet() +" :"); |
nomComplet.hide(); |
fsNoms.add(nomComplet); |
hmIdentite.put("nomComplet", nomComplet); |
//Préfixe |
ListStore<Valeur> storePrefixe = new ListStore<Valeur>(); |
ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>(); |
cbPrefixe.setStore(storePrefixe); |
cbPrefixe.setDisplayField("nom"); |
cbPrefixe.setEmptyText("Choisissez le préfixe:"); |
cbPrefixe.setFieldLabel("Prefix"); |
fsNoms.add(cbPrefixe); |
hmIdentite.put("cbPrefixe", cbPrefixe); |
mediateur.obtenirListeValeurEtRafraichir(this, "prefixe"); |
//Prénom |
TextField<String> tfPrenom = new TextField<String>(); |
tfPrenom.setFieldLabel("Prénom"); |
tfPrenom.setName("prenom"); |
fsNoms.add(tfPrenom, new FormData(300, 0)); |
hmIdentite.put("tfPrenom", tfPrenom); |
//Nom |
TextField<String> tfNom = new TextField<String>(); |
tfNom.setFieldLabel("Nom"); |
tfNom.setAllowBlank(false); |
tfNom.setName("nom"); |
tfNom.addStyleName(ComposantClass.OBLIGATOIRE); |
tfNom.addListener(Events.Valid, creerEcouteurChampObligatoire()); |
fsNoms.add(tfNom, new FormData(300, 0)); |
hmIdentite.put("tfNom", tfNom); |
//Suffixe |
ListStore<Valeur> storeSuffixe = new ListStore<Valeur>(); |
ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>(); |
cbSuffixe.setStore(storeSuffixe); |
cbSuffixe.setFieldLabel("Suffixe"); |
cbSuffixe.setDisplayField("nom"); |
cbSuffixe.setEmptyText("Choisissez un suffixe:"); |
fsNoms.add(cbSuffixe); |
hmIdentite.put("cbSuffixe", cbSuffixe); |
mediateur.obtenirListeValeurEtRafraichir(this, "suffixes"); |
TextField<String> tfAbreviation = new TextField<String>(); |
tfAbreviation.setFieldLabel("Abréviation"); |
tfAbreviation.setName("abreviation"); |
fsNoms.add(tfAbreviation); |
hmIdentite.put("tfAbreviation", tfAbreviation); |
TableLayout layoutAutreNoms = new TableLayout(2); |
layoutAutreNoms.setCellVerticalAlign(VerticalAlignment.TOP); |
LayoutContainer autresNoms = new LayoutContainer(layoutAutreNoms); |
ChampMultiValeurs nomAutre = new ChampMultiValeurs("Autres noms",150); |
hmIdentite.put("nomAutre", nomAutre); |
autresNoms.add(nomAutre, new TableData("200px", "15px")); |
ChampMultiValeurs abreviationAutre = new ChampMultiValeurs("Autres abréviation",150); |
hmIdentite.put("abreviationAutre", abreviationAutre); |
autresNoms.add(abreviationAutre, new TableData("200px", "15px")); |
fsNoms.add(autresNoms); |
left.add(fsNoms); |
//+------------------------------------------------------------------------------------------------------------+ |
// Fieldset NAISSANCE ET DÉCÈS |
FieldSet fsNaissanceEtDeces = new FieldSet(); |
fsNaissanceEtDeces.setHeading("Naissance et Décès"); |
fsNaissanceEtDeces.setLayout(new ColumnLayout()); |
formLayout = new FormLayout(); |
formLayout.setLabelAlign(LabelAlign.TOP); |
LayoutContainer containerNaissance = new LayoutContainer(formLayout); |
DateField dfDateNaissance = new DateField(); |
dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy")); |
dfDateNaissance.setFieldLabel("Date de naissance"); |
dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa»."); |
containerNaissance.add(dfDateNaissance); |
hmIdentite.put("dfDateNaissance", dfDateNaissance); |
// Lieu naissance |
TextField<String> tfLieuNaissance = new TextField<String>(); |
tfLieuNaissance.setFieldLabel("Lieu de naissance"); |
tfLieuNaissance.setName("naissance_lieu"); |
containerNaissance.add(tfLieuNaissance); |
hmIdentite.put("tfLieuNaissance", tfLieuNaissance); |
fsNaissanceEtDeces.add(containerNaissance, new ColumnData(.5)); |
left.add(fsNaissanceEtDeces); |
formLayout = new FormLayout(); |
formLayout.setLabelAlign(LabelAlign.TOP); |
LayoutContainer containerDeces = new LayoutContainer(formLayout); |
Radio rbEstDecedee = new Radio(); |
rbEstDecedee.setId("ce_deces"); |
rbEstDecedee.setBoxLabel("oui"); |
rbEstDecedee.setValueAttribute("1"); |
rbEstDecedee.setId("rbEstD"); |
rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() { |
public void handleEvent(ComponentEvent be) { |
if(((Radio) be.getComponent()).getValue().equals(true)) { |
hmIdentite.getDateField("dfDateDeces").setVisible(true); |
hmIdentite.getTextField("tfLieuDeces").setVisible(true); |
} else { |
DateField dfDateDeces = hmIdentite.getDateField("dfDateDeces"); |
dfDateDeces.setValue(null); |
dfDateDeces.setVisible(false); |
TextField tfLieuDeces = hmIdentite.getTextField("tfLieuDeces"); |
tfLieuDeces.setValue(null); |
tfLieuDeces.setVisible(false); |
} |
} |
}); |
DateField dfDateDeces = new DateField(); |
dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy")); |
dfDateDeces.setFormatValue(true); |
dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa»."); |
dfDateDeces.setFieldLabel("Date de décès"); |
dfDateDeces.setVisible(false); |
containerDeces.add(dfDateDeces); |
hmIdentite.put("dfDateDeces", dfDateDeces); |
TextField<String> tfLieuDeces = new TextField<String>(); |
tfLieuDeces.setFieldLabel("Lieu de décès"); |
tfLieuDeces.setName("deces_lieu"); |
tfLieuDeces.setVisible(false); |
containerDeces.add(tfLieuDeces); |
hmIdentite.put("tfLieuDeces", tfLieuDeces); |
hmIdentite.put("rbEstDecedee", rbEstDecedee); |
Radio rbNestPasDecedee = new Radio(); |
rbNestPasDecedee.setValueAttribute("0"); |
rbNestPasDecedee.setBoxLabel("non"); |
rbNestPasDecedee.setValue(true); |
RadioGroup rbgDeces = new RadioGroup(); |
rbgDeces.setFieldLabel("Est décédée"); |
rbgDeces.add(rbEstDecedee); |
rbgDeces.add(rbNestPasDecedee); |
containerDeces.add(rbgDeces); |
fsNaissanceEtDeces.add(containerDeces, new ColumnData(.5)); |
tiIdentite.add(main); |
//+------------------------------------------------------------------------------------------------------------+ |
// Fieldset CONTACT |
FieldSet fsContact = new FieldSet(); |
fsContact.setHeading("Contact"); |
fsContact.setLayout(new RowLayout()); |
ChampMultiValeursMultiTypes telephones = new ChampMultiValeursMultiTypes("Téléphones", 180, 100); |
telephones.initialiserType("tel"); |
fsContact.add(telephones, new FormData(450, 0)); |
hmIdentite.put("telephones", telephones); |
ChampMultiValeurs courriels = new ChampMultiValeurs("Courriels", 280); |
courriels.setValidation(Pattern.email, "moi@domaine.fr"); |
fsContact.add(courriels, new FormData(450, 0)); |
hmIdentite.put("courriels", courriels); |
LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout()); |
fsContact.add(lcCourrielContainer); |
hmIdentite.put("lcCourrielContainer", lcCourrielContainer); |
fsContact.add(new Text("")); |
ChampMultiValeurs sites = new ChampMultiValeurs("Sites web"); |
sites.setValeurParDefaut("http://"); |
sites.setValidation(Pattern.url, "http://www.monsite.com"); |
fsContact.add(sites); |
hmIdentite.put("sites", sites); |
right.add(fsContact); |
//+------------------------------------------------------------------------------------------------------------+ |
// Fieldset AUTRES INFOS |
FieldSet fsAutresInfos = new FieldSet(); |
fsAutresInfos.setHeading("Autres informations"); |
formLayout = new FormLayout(); |
formLayout.setLabelAlign(LabelAlign.LEFT); |
fsAutresInfos.setLayout(formLayout); |
formLayout = new FormLayout(); |
formLayout.setLabelAlign(LabelAlign.TOP); |
LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout); |
ListStore<Valeur> storeSexe = new ListStore<Valeur>(); |
ComboBox<Valeur> cbSexe = new ComboBox<Valeur>(); |
cbSexe.setStore(storeSexe); |
cbSexe.setFieldLabel("Sexe"); |
cbSexe.setDisplayField("nom"); |
cbSexe.setEmptyText("Choisissez le sexe:"); |
cbSexe.setTypeAhead(true); |
cbSexe.setTriggerAction(TriggerAction.ALL); |
FormData fd = new FormData(); |
fd.setWidth(100); |
lcAutreInformations1.add(cbSexe, fd); |
hmIdentite.put("cbSexe", cbSexe); |
mediateur.obtenirListeValeurEtRafraichir(this, "sexe"); |
//Description |
TextArea taDescription = new TextArea(); |
taDescription.setEmptyText("Saisissez une description"); |
taDescription.setFieldLabel("Description"); |
taDescription.setWidth("100%"); |
taDescription.setName("description"); |
lcAutreInformations1.add(taDescription, new FormData(500, 200)); |
hmIdentite.put("taDescription", taDescription); |
fsAutresInfos.add(lcAutreInformations1); |
// Logo |
LayoutContainer lcLogoUrl = new LayoutContainer(); |
hmIdentite.put("lcLogoUrl", lcLogoUrl); |
ChampMultiValeursImage logo = new ChampMultiValeursImage(i18nC.personneLogos()); |
logo.setImageHeight("150px"); |
logo.setValeurParDefaut("http://"); |
logo.setValidation(Pattern.url, "http://www.monsite.com/mon_image.jpg"); |
logo.setValeurBoutonSupprimer("Supprimer"); |
hmIdentite.put("logos", logo); |
lcLogoUrl.add(logo); |
fsAutresInfos.add(logo); |
LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout()); |
hmIdentite.put("lcAutreInformations2", lcAutreInformations2); |
fsAutresInfos.add(lcAutreInformations2); |
right.add(fsAutresInfos); |
//+------------------------------------------------------------------------------------------------------------+ |
// Ajout des évènements saisi |
KeyListener klNoms = new KeyListener() { |
public void componentKeyUp(ComponentEvent ev) { |
rafraichir(null); |
} |
}; |
SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() { |
public void selectionChanged(SelectionChangedEvent se) { |
rafraichir(null); |
} |
}; |
cbPrefixe.addSelectionChangedListener(selectionChange); |
cbPrefixe.addKeyListener(klNoms); |
tfPrenom.addKeyListener(klNoms); |
tfNom.addKeyListener(klNoms); |
cbSuffixe.addSelectionChangedListener(selectionChange); |
} |
public void creerComposantsAdresse() { |
// Gauche |
LayoutContainer left = new LayoutContainer(); |
left.setLayout(new FormLayout()); |
left.setStyleAttribute("padding", "15px"); |
// Droite |
LayoutContainer right = new LayoutContainer(); |
right.setLayout(new FormLayout()); |
// Principal |
LayoutContainer main = new LayoutContainer(); |
main.setLayout(new TableLayout(2)); |
// Ajout au principal |
main.add(left); |
main.add(right); |
TextField<String> tfAdresse1 = new TextField(); |
tfAdresse1.setFieldLabel("Adresse"); |
tfAdresse1.setName("adresse_01"); |
left.add(tfAdresse1, fd100); |
hmAdresse.put("tfAdresse1", tfAdresse1); |
TextField<String> tfAdresse2 = new TextField(); |
tfAdresse2.setFieldLabel("Complément d'adresse"); |
tfAdresse2.setName("adresse_02"); |
left.add(tfAdresse2, fd100); |
hmAdresse.put("tfAdresse2", tfAdresse2); |
ComboBox<Valeur> cbPays = new ComboBox<Valeur>(); |
cbPays.setFieldLabel("Pays"); |
cbPays.setDisplayField("nom"); |
cbPays.setEmptyText("Sélectionnez le pays:"); |
ListStore<Valeur> storePays = new ListStore<Valeur>(); |
cbPays.setStore(storePays); |
right.add(cbPays, fd100); |
hmAdresse.put("cbPays", cbPays); |
SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() { |
public void selectionChanged(SelectionChangedEvent se) { |
// Rafraichir avec le pays sélectionné |
obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString()); |
//mettreAJourRegion(); |
} |
}; |
cbPays.addSelectionChangedListener(selectionChange); |
ComboBox<Valeur> cbRegion = new ComboBox<Valeur>(); |
cbRegion.setFieldLabel("Region"); |
cbRegion.setDisplayField("nom"); |
cbRegion.setEmptyText("Sélectionnez la région:"); |
cbRegion.setVisible(false); |
ListStore<Valeur> storeRegion = new ListStore<Valeur>(); |
cbRegion.setStore(storeRegion); |
right.add(cbRegion, fd100); |
hmAdresse.put("cbRegion", cbRegion); |
TextField<String> tfBoitePostale = new TextField<String>(); |
tfBoitePostale.setFieldLabel("Boite postale"); |
tfBoitePostale.setName("bp"); |
left.add(tfBoitePostale, fd100); |
hmAdresse.put("tfBoitePostale", tfBoitePostale); |
TextField<Integer> tfCodePostal = new TextField<Integer>(); |
tfCodePostal.setFieldLabel("Code postal"); |
tfCodePostal.setName("code_postal"); |
right.add(tfCodePostal, fd100); |
hmAdresse.put("tfCodePostal", tfCodePostal); |
TextField tfVille = new TextField(); |
tfVille.setFieldLabel("Ville"); |
tfVille.setName("ville"); |
right.add(tfVille, fd100); |
hmAdresse.put("tfVille", tfVille); |
// MAJ ComboBox |
mediateur.obtenirListeValeurEtRafraichir(this, "pays"); |
FieldSet fsAdresse = new FieldSet(); |
fsAdresse.setHeading("Adresse personnelle"); |
fsAdresse.add(main); |
tiAdresses.add(fsAdresse); |
} |
public void creerComposantsInfosNat() { |
FormLayout fl = new FormLayout(); |
fl.setLabelAlign(LabelAlign.TOP); |
FieldSet fsInfosNat = new FieldSet(); |
fsInfosNat.setLayout(fl); |
fsInfosNat.setTitle("Informations Naturaliste"); |
TextArea taBiographie = new TextArea(); |
taBiographie.setFieldLabel("Vie et renommée de l'auteur"); |
taBiographie.setWidth("400"); |
taBiographie.setName("biographie"); |
fsInfosNat.add(taBiographie, new FormData(800, 200)); |
ChampMultiValeurs specialite = new ChampMultiValeurs(i18nC.personneSpecialite()); |
fsInfosNat.add(specialite); |
hmInfosNat.put("specialite", specialite); |
ChampMultiValeursMultiTypes recolte = new ChampMultiValeursMultiTypes(i18nC.personneRecolte(), 200, 200); |
recolte.initialiserType("pays"); |
hmInfosNat.put("recolte", recolte); |
fsInfosNat.add(recolte); |
tiInfosNat.add(fsInfosNat); |
} |
public void creerComposantsPubli(){ |
//Création des composants de l'onglet publication |
ContentPanel cp = new ContentPanel(); |
cp.setHeading("Publications dont la personne est le sujet"); |
cp.setIcon(Images.ICONES.table()); |
cp.setLayout(new FitLayout()); |
cp.setFrame(true); |
ToolBar toolBar = new ToolBar(); |
Button ajouterPubli = new Button("Ajouter"); |
ajouterPubli.setIcon(Images.ICONES.vcardAjouter()); |
ajouterPubli.addSelectionListener(new SelectionListener<ButtonEvent>() { |
@Override |
public void componentSelected(ButtonEvent ce) { |
Window.alert("ajout publi"); |
/*StructureAPersonne membreDuPersonnel = new StructureAPersonne("", StructureAPersonne.ROLE_EQUIPE, StructureAPersonne.ETAT_AJOUTE); |
ajouterMembreAGrillePersonnel(membreDuPersonnel);*/ |
} |
}); |
toolBar.add(ajouterPubli); |
toolBar.add(new SeparatorToolItem()); |
Button supprimerPubli = new Button("Supprimer"); |
supprimerPubli.setIcon(Images.ICONES.vcardSupprimer()); |
supprimerPubli.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(); |
} |
}*/ |
Window.alert("supprimer"); |
} |
}); |
toolBar.add(supprimerPubli); |
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(); |
Window.alert("rafraichir"); |
} |
}); |
toolBar.add(rafraichirPersonnelBtn); |
//Ajout d'une ComboBox |
storePubli = new ListStore<Publication>(); |
storePubli.add(new ArrayList<Publication>()); |
cbPubli = new ComboBox<Publication>(); |
cbPubli.setWidth(200); |
cbPubli.setEmptyText("Chercher une publication existante..."); |
cbPubli.setTriggerAction(TriggerAction.ALL); |
cbPubli.setEditable(true); |
cbPubli.setDisplayField("fmt_nom_complet"); |
cbPubli.setStore(storePubli); |
cbPubli.addKeyListener(new KeyListener() { |
public void componentKeyUp(ComponentEvent ce) { |
if (!ce.isNavKeyPress() && cbPubli.getRawValue() != null && cbPubli.getRawValue().length() > 0) { |
rafraichirPublicationsExistante(cbPubli.getRawValue()); |
} |
} |
}); |
toolBar.add(cbPubli); |
toolBar.add(new SeparatorToolItem()); |
cp.setTopComponent(toolBar); |
tiPubli.add(cp); |
} |
public void rafraichirPublicationsExistante(String nomPubli) { |
nomPubli +="%"; |
mediateur.selectionnerPublicationParNomComplet(this, null, nomPubli); |
} |
/** |
* Ajouter le bouton annuler à la barre d'outils donnée |
* |
* @param barreOutils la barre d'outils à modifier |
* */ |
public static void ajouterBoutonAnnuler(ButtonBar barreOutils) { |
// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente |
Button annuler = new Button("Revenir à la liste"); |
annuler.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent ce) { |
((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes"); |
} |
}); |
annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER); |
barreOutils.add(annuler); |
} |
public void obtenirListeRegionParPays(String strPays) { |
mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays); |
} |
// RAFRAICHISSEMENT DU PANNEAU |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof PublicationAPersonneListe) { |
Information info = new Information(); |
info.setType("publication_liees"); |
info.setDonnee(0, (PublicationAPersonneListe) nouvellesDonnees); |
tiPubli.rafraichir(info); |
} else if (nouvellesDonnees instanceof ValeurListe) { |
ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees; |
// Créer une liste de valeurs |
List<Valeur> liste = new ArrayList<Valeur>(); |
for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) { |
liste.add(listeValeurs.get(it.next())); |
} |
if (listeValeurs.getId().equals(config.getListeId("relationPersonnePublication"))) { |
tiPubli.rafraichir(nouvellesDonnees); |
} else if (listeValeurs.getId().equals(config.getListeId("prefixe"))) { |
remplirCombobox("cbPrefixe", liste, "hmIdentite"); |
} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) { |
remplirCombobox("cbSuffixe", liste, "hmIdentite"); |
} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) { |
//Ajout de la valeur "Inconnu" |
ComboBox<Valeur> cbSexe = hmAdresse.getComboBoxValeur("cbSexe"); |
Valeur inconnu = new Valeur(); |
inconnu.set("nom", "Inconnu"); |
inconnu.set("id", "0"); |
liste.add(0, inconnu); |
remplirCombobox("cbSexe", liste, "hmIdentite"); |
/*List<Valeur> selection = new LinkedList<Valeur>(); |
selection.add(inconnu); |
cbSexe.setSelection(s);*/ |
} else if (listeValeurs.getId().equals(config.getListeId("tel"))) { |
remplirCombobox("cbTelephone", liste, "hmIdentite"); |
//Préselection du tél |
ComboBox<Valeur> cbTelephone = hmIdentite.getComboBoxValeur("cbTelephone"); |
cbTelephone.setValue(liste.get(1)); |
} else if (listeValeurs.getId().equals(config.getListeId("pays"))) { |
remplirCombobox("cbPays", liste, "hmAdresse"); |
} else if (listeValeurs.getId().equals(config.getListeId("region"))) { |
remplirCombobox("cbRegion", liste, "hmAdresse"); |
mettreAJourRegion(); |
hmAdresse.getComboBox("cbRegion").setVisible(true); |
} |
} else if (nouvellesDonnees instanceof ProjetListe) { |
ProjetListe projets = (ProjetListe) nouvellesDonnees; |
List<Projet> liste = projets.toList(); |
ComboBox cbProjets = hmIdentite.getComboBox("cbProjets"); |
ListStore<Projet> storeProjets= cbProjets.getStore(); |
storeProjets.removeAll(); |
storeProjets.add(liste); |
cbProjets.setStore(storeProjets); |
} else if (nouvellesDonnees instanceof PublicationListe) { |
PublicationListe publicationListe = (PublicationListe) nouvellesDonnees; |
List<Publication> liste = publicationListe.toList(); |
storePubli.removeAll(); |
storePubli.add(liste); |
cbPubli.setStore(storePubli); |
} else if (nouvellesDonnees instanceof Information) { |
Information info = (Information) nouvellesDonnees; |
if (info.getType().equals("ajout_personne")) { |
if (info.getDonnee(0) != null) { |
personneSelectionnee.setId(info.getDonnee(0).toString()); |
GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null); |
Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")"); |
repandreRafraichissement(); |
if (clicBoutonvalidation) { |
mediateur.clicMenu(menuIdCourant); |
} |
} else { |
Info.display("Enregistrement", info.getMessages().toString()); |
} |
} else if (info.getType().equals("modification_personne")) { |
Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées."); |
repandreRafraichissement(); |
if (clicBoutonvalidation) { |
mediateur.clicMenu(menuIdCourant); |
} |
} else if (info.getType().equals("maj_utilisateur")) { |
gererEtatActivationBouton(); |
} else if (info.getDonnee(0) instanceof PersonneListe) { |
Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values(); |
Iterator itPersonneListe = colPersonneListe.iterator(); |
Personne personne = (Personne) itPersonneListe.next(); |
//TODO : Je vois pas l'intérêt des lignes ci dessous.. |
personneSauvegarde = new Personne(); |
personneSauvegarde = (Personne) personne.cloner(personneSauvegarde); |
binderPersonne(personne); |
mettreAJourPersonne(personne); |
nouvellesDonnees = null; |
} else { |
Info.display("messages", info.getMessages().toString()); |
} |
} |
if (nouvellesDonnees == null) { |
ComboBox<Valeur> cb= hmIdentite.getComboBoxValeur("cbPrefixe"); |
//Met à jour le nom Complet du formulaire |
String valeurRetour = ""; |
// Prefixe |
String prefixe = ""; |
Valeur valPrefixe = cb.getValue(); |
if (valPrefixe != null) { |
prefixe = valPrefixe.getNom(); |
} else { |
prefixe = (String) cb.getRawValue(); |
} |
// Prénom |
String prenom = (String) hmIdentite.getTextField("tfPrenom").getValue(); |
// Nom |
String nom = (String) hmIdentite.getTextField("tfNom").getValue(); |
// Suffixe |
ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe"); |
String suffixe = ""; |
Valeur valSuffixe = cbSuffixe.getValue(); |
if (valSuffixe != null) { |
suffixe = valSuffixe.getNom(); |
} else { |
suffixe = (String) cbSuffixe.getRawValue(); |
} |
// Mettre à jour la valeur |
valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe; |
valeurRetour = valeurRetour.replaceAll("null", ""); |
hmIdentite.getLabelField("nomComplet").setValue(valeurRetour); |
if (!valeurRetour.trim().equals("")) { |
hmIdentite.getLabelField("nomComplet").show(); |
} else { |
hmIdentite.getLabelField("nomComplet").hide(); |
} |
} |
mediateur.masquerPopinChargement(); |
if (this.mode.equals(MODE_AJOUTER)) { |
gererEtatActivationBouton(); |
} |
} |
private void repandreRafraichissement() { |
if (vueExterneARafraichirApresValidation != null) { |
String type = "personne_modifiee"; |
if (mode.equals(Formulaire.MODE_AJOUTER)) { |
type = "personne_ajoutee"; |
} |
Information info = new Information(type); |
info.setDonnee(0, personneSelectionnee); |
vueExterneARafraichirApresValidation.rafraichir(info); |
} |
} |
private void mettreAJourRegion() { |
//Met à jour la combo box en sélectionnant la valeur enregistrée pour la personne |
ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion"); |
if (personneSelectionnee.get("ce_truk_region").toString().startsWith("AUTRE##")) { |
cbRegion.setRawValue(personneSelectionnee.get("ce_truk_region").toString().replaceFirst("^AUTRE##", "")); |
} else if (personneSelectionnee.get("ce_truk_region") != null && cbRegion.getStore().getCount() > 0) { |
Valeur valeurRegion = cbRegion.getStore().findModel("id_valeur", personneSelectionnee.get("ce_truk_region")); |
if (valeurRegion!=null) { |
cbRegion.setValue(valeurRegion); |
} |
} |
} |
private void mettreAJourPersonne(Personne personne) { |
//Mise à jour de la personne |
//Personne personne = (Personne) nouvellesDonnees; |
ComboBox cbProjets = hmIdentite.getComboBox("cbProjets"); |
cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet"))); |
//Prefixe |
String prefixe = personne.get("ce_truk_prefix"); |
ComboBox<Valeur> cbPrefixe = hmIdentite.getComboBoxValeur("cbPrefixe"); |
String prefixeCourant = personne.get("ce_truk_prefix"); |
if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null) { |
cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant)); |
} else { |
cbPrefixe.setRawValue(prefixeCourant); |
} |
hmIdentite.getTextField("tfPrenom").setValue(personne.get("prenom")); |
hmIdentite.getTextField("tfNom").setValue(personne.get("nom")); |
//Suffixe |
String suffixe = personne.get("ce_truk_suffixe"); |
ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe"); |
String suffixeCourant = personne.get("ce_truk_suffix"); |
if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null) { |
cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant)); |
} else { |
cbSuffixe.setRawValue(suffixeCourant); |
} |
hmIdentite.getChampMultiValeurs("nomAutre").peupler(personne.getString("truk_nom_autre")); |
hmIdentite.getTextField("tfAbreviation").setValue(personne.get("abreviation")); |
hmIdentite.getChampMultiValeurs("abreviationAutre").peupler(personne.getString("truk_abreviation_autre")); |
hmIdentite.getDateField("dfDateNaissance").setValue(personne.getDate("naissance_date")); |
hmIdentite.getTextField("tfLieuNaissance").setValue(personne.get("naissance_lieu")); |
if (personne.estDecedee()) { |
hmIdentite.getDateField("dfDateDeces").setValue(personne.getDate("deces_date")); |
hmIdentite.getTextField("tfLieuDeces").setValue(personne.get("deces_lieu")); |
Radio rbEstDecede = hmIdentite.getRadio("rbEstDecedee"); |
rbEstDecede.setValue(true); |
} |
hmIdentite.getChampMultiValeurs("telephones").peupler(personne.getString("truk_telephone")); |
//Courriel |
hmIdentite.getChampMultiValeurs("courriels").peupler(personne.getCourriel()); |
//Sites web |
hmIdentite.getChampMultiValeurs("sites").peupler(personne.getString("truk_url")); |
// Sexe |
String strSexe = personne.get("ce_sexe"); |
ComboBox<Valeur> cbSexe = hmIdentite.getComboBoxValeur("cbSexe"); |
if (cbSexe.getStore().findModel("id_valeur", strSexe) != null) { |
cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe)); |
} |
hmIdentite.getTextArea("taDescription").setRawValue((String) personne.get("description")); |
//Logo |
hmIdentite.getChampMultiValeurs("logos").peupler(personne.getString("truk_logo")); |
/*-------------------------------------------------- |
Adresse |
---------------------------------------------------*/ |
// Adresse |
hmAdresse.getTextField("tfAdresse1").setValue((String) personne.get("adresse_01")); |
// Complément |
hmAdresse.getTextField("tfAdresse2").setValue((String) personne.get("adresse_02")); |
//Boite postale |
hmAdresse.getTextField("tfBoitePostale").setValue((String) personne.get("bp")); |
//Pays |
String strPays = personne.get("ce_truk_pays"); |
ComboBox<Valeur> cbPays = hmAdresse.getComboBoxValeur("cbPays"); |
if (cbPays.getStore().findModel("id_valeur", strPays) != null) { |
cbPays.setValue(cbPays.getStore().findModel("id_valeur", strPays)); |
cbPays.fireEvent(Events.OnChange); |
} else { |
cbPays.setRawValue(strPays); |
} |
//Région : doit être chargé après chargement de la liste des régions... |
String strRegion = personne.get("ce_truk_region"); |
if ((strRegion!=null)&&(!strRegion.equals(""))) { |
ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion"); |
System.out.println(cbRegion.getStore().getCount()); |
cbRegion.setVisible(true); |
if (cbRegion.getStore().findModel("id_valeur", strRegion) != null) { |
cbRegion.setValue(cbRegion.getStore().findModel("id_valeur", strRegion)); |
} else { |
cbRegion.setRawValue(strRegion); |
} |
} |
//Cp |
hmAdresse.getTextField("tfCodePostal").setValue(personne.get("code_postal")); |
//Ville |
hmAdresse.getTextField("tfVille").setValue(personne.get("ville")); |
/*-------------------------------------------------------- |
* Infos naturalistes |
* -----------------------------------------------------*/ |
hmInfosNat.getChampMultiValeurs("specialite").peupler(personne.getString("ce_truk_specialite")); |
String tr = personne.getString("truk_recolte"); |
hmInfosNat.getChampMultiValeursMultiTypes("recolte").peupler(tr); |
//Onglet publi |
tiPubli.mettreAJourPersonne(); |
gererEtatActivationBouton(); |
} |
public void remplirCombobox(String idComboBox, List liste, String hashMapId) { |
HashMap hm = null; |
if (hashMapId.equals("hmIdentite")) { |
hm = hmIdentite; |
} else if (hashMapId.equals("hmAdresse")){ |
hm = hmAdresse; |
} else { |
hm = hmInfosNat; |
} |
ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore(); |
store.removeAll(); |
store.add(liste); |
((ComboBox) hm.get(idComboBox)).setStore(store); |
} |
private void gererEtatActivationBouton() { |
/* if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false) { |
enregistrer.setEnabled(false); |
enregistrerEtRevenir.setEnabled(false); |
} else { |
enregistrer.setEnabled(true); |
enregistrerEtRevenir.setEnabled(true); |
}*/ |
} |
public void reinitialiserFormulaire() { |
mediateur.afficherPopinChargement(); |
mettreAJourPersonne(personneSauvegarde); |
mediateur.masquerPopinChargement(); |
} |
public void binderPersonne(Personne personne) { |
binding = new FormBinding(getFormulaire()); |
personneSelectionnee = personne; |
binding.autoBind(); |
binding.bind(personneSelectionnee); |
layout(); |
} |
private String obtenirValeurCombo(String strComboName) { |
String strValeur = ""; |
Valeur valeur; |
ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur(strComboName); |
if (combo == null) { |
combo = hmAdresse.getComboBoxValeur(strComboName); |
} |
strValeur = combo.getRawValue(); |
valeur = combo.getValue(); |
if (valeur != null) { |
strValeur = valeur.getId(); |
} |
return strValeur; |
} |
public boolean soumettreFormulaire() { |
tiPubli.collecter(); |
if (verifierFormulaire()) { |
tiPubli.soumettre(); |
mediateur.enregistrerPersonne(this, personneSelectionnee); |
} |
return true; |
} |
public boolean verifierFormulaire() { |
boolean success = true; |
LinkedList<String> lstMessageErreur = new LinkedList<String>(); |
ComboBox<Projet> cbProjets = hmIdentite.getComboBox("cbProjets"); |
Projet projet = cbProjets.getValue(); |
if (projet == null) { |
lstMessageErreur.add("Le projet n'a pas été renseigné"); |
} else { |
personneSelectionnee.set("ce_projet", projet.getId()); |
} |
String strTfNom = (String) hmIdentite.getTextField("tfNom").getValue(); |
if ((strTfNom == null)||(strTfNom.trim().equals(""))) { |
lstMessageErreur.add("Le nom n'a pas été saisi"); |
} else { |
strTfNom = UtilString.ucFirst(strTfNom); |
personneSelectionnee.set("nom", strTfNom); |
} |
String strTfPrenom = (String) hmIdentite.getTextField("tfPrenom").getValue(); |
personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom)); |
//Préparer les données |
ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur("cbSexe"); |
Valeur valeur; |
String strValeur = ""; |
valeur = combo.getValue(); |
if (valeur!=null) { |
personneSelectionnee.set("ce_sexe", valeur.getId()); |
} |
strValeur = obtenirValeurCombo("cbPrefixe"); |
personneSelectionnee.set("ce_truk_prefix", strValeur); |
strValeur = obtenirValeurCombo("cbSuffixe"); |
personneSelectionnee.set("ce_truk_suffix", strValeur); |
String nomAutre = hmIdentite.getChampMultiValeurs("nomAutre").getValeurs(); |
personneSelectionnee.set("truk_nom_autre", nomAutre); |
String abreviationAutre = hmIdentite.getChampMultiValeurs("abreviationAutre").getValeurs(); |
personneSelectionnee.set("truk_abreviation_autre", abreviationAutre); |
personneSelectionnee.set("truk_courriel", hmIdentite.getChampMultiValeurs("courriels").getValeurs()); |
//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id |
String strPrefixe = ""; |
combo = hmIdentite.getComboBoxValeur("cbPrefixe"); |
valeur = combo.getValue(); |
if (valeur != null) { |
strPrefixe = valeur.getNom(); |
} else { |
strPrefixe = combo.getRawValue(); |
} |
String strSuffixe = ""; |
combo = hmIdentite.getComboBox("cbSuffixe"); |
valeur = combo.getValue(); |
if (valeur != null) { |
strSuffixe = valeur.getNom() + " "; |
} else { |
strSuffixe = combo.getRawValue() +" "; |
} |
personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe); |
DateField dfDateNaissance = hmIdentite.getDateField("dfDateNaissance"); |
Date naissanceDate = dfDateNaissance.getValue(); |
personneSelectionnee.setNaissanceDate(naissanceDate); |
Radio rbEstDecedee = hmIdentite.getRadio("rbEstDecedee"); |
if (rbEstDecedee.getValue() == true) { |
DateField dfDecesDate = hmIdentite.getDateField("dfDateDeces"); |
String decesLieu = (String) hmIdentite.getTextField("tfLieuDeces").getValue(); |
personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu); |
} else { |
personneSelectionnee.setNonDecedee(); |
} |
strValeur = obtenirValeurCombo("cbPays"); |
personneSelectionnee.set("ce_truk_pays", strValeur); |
strValeur = obtenirValeurCombo("cbRegion"); |
ComboBox<Valeur> cbRegions = hmAdresse.getComboBoxValeur("cbRegion"); |
if (cbRegions.getStore().findModel("id", strValeur) == null) { |
strValeur = "AUTRE##" + strValeur; |
} |
personneSelectionnee.set("ce_truk_region", strValeur); |
personneSelectionnee.set("truk_telephone", hmIdentite.getChampMultiValeursMultiTypes("telephones").getValeurs()); |
String logoUrls = hmIdentite.getChampMultiValeursImage("logos").getValeurs(); |
personneSelectionnee.set("truk_logo", logoUrls); |
personneSelectionnee.set("truk_url", hmIdentite.getChampMultiValeurs("sites").getValeurs()); |
//Infos Naturalistes |
String recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs(); |
personneSelectionnee.set("truk_recolte", recolte); |
String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs(); |
personneSelectionnee.set("ce_truk_specialite", specialite); |
lstMessageErreur.addAll(tiPubli.verifier()); |
if (lstMessageErreur.size() != 0) { |
String strMessagesErreur = "<span><br />"; |
Iterator<String> itMessagesErreur = lstMessageErreur.iterator(); |
while (itMessagesErreur.hasNext()) { |
strMessagesErreur += "<br /> - " + itMessagesErreur.next(); |
} |
strMessagesErreur += "</span>"; |
MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null); |
success = false; |
} |
return success; |
} |
} |