Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 375 → Rev 376

/trunk/src/org/tela_botanica/client/vues/FormPersonneVue.java
2,6 → 2,7
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
24,6 → 25,9
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.binding.SimpleComboBoxFieldBinding;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
47,6 → 51,7
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.HiddenField;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
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.FormPanel.LabelAlign;
67,7 → 72,8
 
 
 
public class FormPersonneVue extends ContentPanel implements Rafraichissable {
 
public class FormPersonneVue extends FormPanel implements Rafraichissable {
/*--------------------------------------------------------------------------------------
78,8 → 84,11
private TabItem tiIdentite, tiAdresses, tiInfosNat;
private Mediateur mediateur = Registry.get(RegistreId.MEDIATEUR);
private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
private Personne personneSelectionnee = null;
private Personne personneSelectionnee, personneSauvegarde = null;
private FormBinding binding = null;
/*--------------------------------------------------------------------------------------
* CONSTRUCTEUR
* -------------------------------------------------------------------------------------
92,9 → 101,7
*
* */
public FormPersonneVue() {
initialiserComposants(null);
}
public FormPersonneVue(Personne personne) {
104,6 → 111,9
public void initialiserComposants(Personne personne) {
personneSelectionnee = new Personne();
personneSauvegarde = new Personne();
initialiserPanneau();
ButtonBar barreOutilsBas = new ButtonBar();
128,6 → 138,8
layout();
rafraichir(personne);
binderPersonne(personneSelectionnee);
}
142,12 → 154,18
* */
public void initialiserPanneau() {
setLayout(new FitLayout());
setIconStyle("icone-form-ajouter");
setCollapsible(false);
setHeading("Ajouter une personne");
setButtonAlign(HorizontalAlignment.CENTER);
setLayout(new FormLayout());
setBodyBorder(false);
setBorders(false);
setPadding(0);
setWidth("100%");
}
/**
157,7 → 175,9
public void initialiserOnglets() {
//TabPanel
TabPanel formulaireOnglets = new TabPanel();
formulaireOnglets.setBodyBorder(true);
//Tab 1 : identite
tiIdentite = new TabItem("Identité");
tiIdentite.setLayout(new FormLayout());
193,331 → 213,384
private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();
private FormData fd100 = new FormData("1");
public void creerComposantsIdentite() {
// Gestion de l'affichage en colonnes
// On crée 3 Layout container : un principal, un pour la colonne de gauche, un pour la colonne de droite
// Gauche
// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
LayoutContainer left = new LayoutContainer();
left.setLayout(new FormLayout());
// Droite
LayoutContainer right = new LayoutContainer();
right.setLayout(new FormLayout());
// Principal
LayoutContainer main = new LayoutContainer();
main.setLayout(new ColumnLayout());
// Ajout au principal
main.add(left, new ColumnData(.49));
main.add(right, new ColumnData(.49));
// Création des champs
//FormLayout sera utilisé à plusieurs reprises
FormLayout formLayout = new FormLayout();
FieldSet fsNoms = new FieldSet();
fsNoms.setHeading("Noms");
formLayout.setLabelAlign(LabelAlign.LEFT);
fsNoms.setLayout(formLayout);
// Nom complet
// Affiché que si valeurs saisies
LabelField nomComplet = new LabelField();
nomComplet.setFieldLabel("Nom complet:");
nomComplet.hide();
fsNoms.add(nomComplet);
FieldSet fsNoms = new FieldSet();
fsNoms.setHeading("Noms");
fsNoms.setLayout(formLayout);
hmIdentite.put("nomComplet", nomComplet);
// Nom complet : Affiché que si valeurs saisies
LabelField nomComplet = new LabelField();
nomComplet.setFieldLabel("Nom complet:");
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");
//Préfixe
ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
fsNoms.add(tfPrenom);
hmIdentite.put("tfPrenom", tfPrenom);
// Remplir la liste des préfixe
mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
//Nom
TextField<String> tfNom = new TextField<String>();
tfNom.setFieldLabel("Nom");
tfNom.setName("nom");
fsNoms.add(tfNom);
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");
ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
cbPrefixe.setStore(storePrefixe);
cbPrefixe.setDisplayField("nom");
cbPrefixe.setEmptyText("Choisissez le préfixe:");
cbPrefixe.setFieldLabel("Prefix");
fsNoms.add(cbPrefixe);
TextField<String> tfNomAutre = new TextField();
tfNomAutre.setFieldLabel("Autres noms");
fsNoms.add(tfNomAutre);
hmIdentite.put("tfNomAutre", tfNomAutre);
TextField<String> tfAbreviation = new TextField<String>();
tfAbreviation.setFieldLabel("Abréviation");
tfAbreviation.setName("abreviation");
fsNoms.add(tfAbreviation);
hmIdentite.put("tfAbreviation", tfAbreviation);
//Abréviation autres
TextField<String> tfAbreviationAutre = new TextField<String>();
tfAbreviationAutre.setFieldLabel("Autres Abrév.");
tfAbreviationAutre.setName("truk_abreviation_autre");
fsNoms.add(tfAbreviationAutre);
hmIdentite.put("tfAbreviationAutre", tfAbreviationAutre);
left.add(fsNoms);
hmIdentite.put("cbPrefixe", cbPrefixe);
formLayout = new FormLayout();
formLayout.setLabelAlign(LabelAlign.LEFT);
FieldSet fsNaissance = new FieldSet();
fsNaissance.setHeading("Naissance");
fsNaissance.setLayout(formLayout);
//Prénom
TextField<String> tfPrenom = new TextField<String>();
tfPrenom.setFieldLabel("Prénom");
fsNoms.add(tfPrenom);
DateField dfDateNaissance = new DateField();
dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
dfDateNaissance.setFieldLabel("Date");
dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
fsNaissance.add(dfDateNaissance);
hmIdentite.put("dfDateNaissance", dfDateNaissance);
// Lieu naissance
TextField<String> tfLieuNaissance = new TextField();
tfLieuNaissance.setFieldLabel("Lieu");
tfLieuNaissance.setName("naissance_lieu");
fsNaissance.add(tfLieuNaissance);
hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
left.add(fsNaissance);
hmIdentite.put("tfPrenom", tfPrenom);
formLayout = new FormLayout();
formLayout.setLabelAlign(LabelAlign.LEFT);
//Nom
TextField<String> tfNom = new TextField<String>();
tfNom.setFieldLabel("Nom");
fsNoms.add(tfNom);
FieldSet fsDeces = new FieldSet();
fsDeces.setHeading("Décès");
fsDeces.setLayout(formLayout);
hmIdentite.put("tfNom", tfNom);
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");
//Suffixe
ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
cbSuffixe.setStore(storeSuffixe);
cbSuffixe.setFieldLabel("Suffixe");
cbSuffixe.setDisplayField("nom");
cbSuffixe.setEmptyText("Choisissez un suffixe:");
fsNoms.add(cbSuffixe);
fsDeces.add(dfDateDeces);
hmIdentite.put("dfDateDeces", dfDateDeces);
 
TextField<String> tfLieuDeces = new TextField();
tfLieuDeces.setFieldLabel("Lieu");
tfLieuDeces.setName("deces_lieu");
fsDeces.add(tfLieuDeces);
hmIdentite.put("tfLieuDeces", tfLieuDeces);
left.add(fsDeces);
hmIdentite.put("cbSuffixe", cbSuffixe);
tiIdentite.add(main);
// Remplir la liste des suffixes:
mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
FieldSet fsContactTel = new FieldSet();
fsContactTel.setHeading("Contact - Téléphones");
fsContactTel.setLayout(new RowLayout());
right.add(fsContactTel);
hmIdentite.put("fsContactTel", fsContactTel);
LayoutContainer lcTelephone = new LayoutContainer();
lcTelephone.setLayout(new ColumnLayout());
TextField tfTelephone = new TextField();
tfTelephone.setFieldLabel("tel");
lcTelephone.add(tfTelephone, new ColumnData(0.40));
hmIdentite.put("tfTelephone", tfTelephone);
ListStore<Valeur> storeTel = new ListStore<Valeur>();
ComboBox<Valeur> cbTelephone = new ComboBox<Valeur>();
cbTelephone.setDisplayField("nom");
cbTelephone.setEmptyText("Choisissez:");
cbTelephone.setStore(storeTel);
lcTelephone.add(cbTelephone, new ColumnData(0.40));
hmIdentite.put("cbTelephone", cbTelephone);
// Nom : autre
TextField<String> tfNomAutre = new TextField();
tfNomAutre.setFieldLabel("Autres noms");
fsNoms.add(tfNomAutre);
mediateur.obtenirListeValeurEtRafraichir(this, "tel");
hmIdentite.put("tfNomAutre", tfNomAutre);
IconButton bAjouter = new IconButton(ComposantClass.ICONE_AJOUTER);
bAjouter.addSelectionListener(
new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
String strTelephone = ((TextField<String>) hmIdentite.get("tfTelephone")).getValue();
if ((strTelephone==null)||(strTelephone.trim().equals(""))) {
MessageBox.alert("Erreur de saisie", "Vous devez saisir un numéro de téléphone", null);
} else if (hmIdentite.get("tel-" + strTelephone) != null){
MessageBox.alert("Erreur de saisie", "Le numéro saisi est déjà présent dans la liste", null);
} else {
String strValeurTypeTel = "";
String idTel = "";
Valeur valeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getValue();
if (valeurTypeTel != null) {
strValeurTypeTel = valeurTypeTel.getNom();
idTel = valeurTypeTel.get("abreviation");
} else {
strValeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getRawValue();
idTel = strValeurTypeTel;
}
if (strValeurTypeTel.trim().equals("")) {
MessageBox.alert("Erreur de saisie", "Vous devez saisir un type de téléphone", null);
} else {
ajouterTelephone(strTelephone, strValeurTypeTel, idTel);
}
}
}
}
);
//Abréviation
TextField<String> tfAbreviation = new TextField<String>();
tfAbreviation.setFieldLabel("Abréviation");
fsNoms.add(tfAbreviation);
lcTelephone.add(bAjouter, new ColumnData(0.15));
HiddenField<String> hfTelephone = new HiddenField<String>();
add(hfTelephone);
hmIdentite.put("hfTelephone", hfTelephone);
fsContactTel.add(lcTelephone);
hmIdentite.put("tfAbreviation", tfAbreviation);
//Abréviation autres
TextField<String> tfAbreviationAutre = new TextField<String>();
tfAbreviationAutre.setFieldLabel("Autres Abrév.");
fsNoms.add(tfAbreviationAutre);
FieldSet fsContact = new FieldSet();
fsContact.setHeading("Contact - Autres");
fsContact.setId("fsContact");
fsContact.setLayout(new RowLayout());
hmIdentite.put("tfAbreviationAutre", tfAbreviationAutre);
right.add(fsContact);
hmIdentite.put("fsContact", fsContact);
 
LabelField lfCourriel = new LabelField();
lfCourriel.setText("<b>Courriels:</b>");
left.add(fsNoms);
fsContact.add(lfCourriel);
// Naissance
FieldSet fsNaissance = new FieldSet();
fsNaissance.setHeading("Naissance");
formLayout = new FormLayout();
formLayout.setLabelAlign(LabelAlign.LEFT);
fsNaissance.setLayout(formLayout);
LayoutContainer lcCourriel = new LayoutContainer();
lcCourriel.setLayout(new ColumnLayout());
// Date naissance
DateField dfDateNaissance = new DateField();
dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
TextField tfCourriel = new TextField();
lcCourriel.add(tfCourriel, new ColumnData(0.80));
HiddenField hfHiddenCourriel = new HiddenField();
hfHiddenCourriel.setId("tfHiddenCourriel");
hfHiddenCourriel.setValue("");
add(hfHiddenCourriel);
hmIdentite.put("hfHiddenCourriel", hfHiddenCourriel);
//tfHiddenCourriel.setVisible(true);
hmIdentite.put("tfCourriel", tfCourriel);
dfDateNaissance.setFieldLabel("Date");
fsNaissance.add(dfDateNaissance);
IconButton bAjouterCourriel = new IconButton(ComposantClass.ICONE_AJOUTER);
bAjouterCourriel.addSelectionListener(
new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
String strEmail = ((TextField<String>) hmIdentite.get("tfCourriel")).getValue();
if ((strEmail==null)||(strEmail.trim().equals(""))) {
MessageBox.alert("Erreur de saisie", "Vous devez saisir une adresse", null);
} else if (hmIdentite.get("email-" + strEmail) != null){
MessageBox.alert("Erreur de saisie", "L'adresse saisie est déjà dans la liste", null);
} else {
if (!strEmail.matches("(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*")) {
MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: me@domain.com)", null);
} else if (strEmail.length()>255){
MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
} else {
ajouterCourriel(strEmail);
}
}
}
});
hmIdentite.put("dfDateNaissance", dfDateNaissance);
lcCourriel.add(bAjouterCourriel, new ColumnData(0.15));
fsContact.add(lcCourriel);
// Lieu naissance
TextField<String> tfLieuNaissance = new TextField();
tfLieuNaissance.setFieldLabel("Lieu");
fsNaissance.add(tfLieuNaissance);
LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());
fsContact.add(lcCourrielContainer);
hmIdentite.put("lcCourrielContainer", lcCourrielContainer);
hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
 
LabelField lfUrl = new LabelField();
lfUrl.setText("<b>Sites Web:</b>");
fsContact.add(lfUrl);
left.add(fsNaissance);
LayoutContainer lcUrl = new LayoutContainer(new ColumnLayout());
hmIdentite.put("lcUrl", lcUrl);
// Deces
FieldSet fsDeces = new FieldSet();
fsDeces.setHeading("Décès");
TextField tfUrl = new TextField();
tfUrl.setValue("http://");
formLayout = new FormLayout();
formLayout.setLabelAlign(LabelAlign.LEFT);
fsDeces.setLayout(formLayout);
lcUrl.add(tfUrl, new ColumnData(0.8));
hmIdentite.put("tfUrl", tfUrl);
// Date décès
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");
fsDeces.add(dfDateDeces);
hmIdentite.put("dfDateDeces", dfDateDeces);
// Lieu décès
TextField<String> tfLieuDeces = new TextField();
tfLieuDeces.setFieldLabel("Lieu");
fsDeces.add(tfLieuDeces);
hmIdentite.put("tfLieuDeces", tfLieuDeces);
left.add(fsDeces);
tiIdentite.add(main);
// Contact - Téléphone
FieldSet fsContactTel = new FieldSet();
fsContactTel.setHeading("Contact - Téléphones");
fsContactTel.setLayout(new RowLayout());
hmIdentite.put("fsContactTel", fsContactTel);
right.add(fsContactTel);
//Téléphone
LayoutContainer lcTelephone = new LayoutContainer();
lcTelephone.setLayout(new ColumnLayout());
TextField tfTelephone = new TextField();
tfTelephone.setFieldLabel("tel");
lcTelephone.add(tfTelephone, new ColumnData(0.40));
hmIdentite.put("tfTelephone", tfTelephone);
//Type de téléphone
ComboBox<Valeur> cbTelephone = new ComboBox<Valeur>();
cbTelephone.setDisplayField("nom");
cbTelephone.setEmptyText("Choisissez:");
ListStore<Valeur> storeTel = new ListStore<Valeur>();
cbTelephone.setStore(storeTel);
lcTelephone.add(cbTelephone, new ColumnData(0.40));
hmIdentite.put("cbTelephone", cbTelephone);
mediateur.obtenirListeValeurEtRafraichir(this, "tel");
// Bouton ajouter
IconButton bAjouter = new IconButton(ComposantClass.ICONE_AJOUTER);
// Evenement bouton
bAjouter.addSelectionListener(
new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
String strTelephone = ((TextField<String>) hmIdentite.get("tfTelephone")).getValue();
if ((strTelephone==null)||(strTelephone.trim().equals(""))) {
MessageBox.alert("Erreur de saisie", "Vous devez saisir un numéro de téléphone", null);
} else if (hmIdentite.get("tel-" + strTelephone) != null){
MessageBox.alert("Erreur de saisie", "Le numéro saisi est déjà présent dans la liste", null);
} else {
IconButton ibAjouterUrl = new IconButton(ComposantClass.ICONE_AJOUTER);
ibAjouterUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
 
public void componentSelected(ComponentEvent ce) {
String strValeurTypeTel = "";
Valeur valeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getValue();
TextField<String> tfUrl = (TextField) hmIdentite.get("tfUrl");
String strUrl = tfUrl.getValue();
if (valeurTypeTel != null) {
strValeurTypeTel = valeurTypeTel.getNom();
} else {
strValeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getRawValue();
if ((strUrl == null)||(strUrl.trim().equals("http://"))||(strUrl.trim().equals(""))) {
MessageBox.alert("Erreur de saisie", "Vous devez saisir un URL", null);
} else if(hmIdentite.get("url-" + strUrl) != null) {
MessageBox.alert("Erreur de saisie", "L'url est déjà présente dans la liste.", null);
} else {
tfUrl.setValue("");
if (!strUrl.matches("[a-z]{3,}://[a-z0-9-]+.[.a-z0-9-]+(?::[0-9]*)?")) {
MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: http://www.domain.com)", null);
} else if (strUrl.length()>255){
MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
} else {
ajouterUrl(strUrl);
}
}
if (strValeurTypeTel.trim().equals("")) {
MessageBox.alert("Erreur de saisie", "Vous devez saisir un type de téléphone", null);
} else {
ajouterTelephone(strTelephone, strValeurTypeTel);
}
}
}
}
);
});
lcTelephone.add(bAjouter, new ColumnData(0.15));
fsContactTel.add(lcTelephone);
lcUrl.add(ibAjouterUrl, new ColumnData(0.15));
fsContact.add(lcUrl);
//Contact - autres
FieldSet fsContact = new FieldSet();
fsContact.setHeading("Contact - Autres");
fsContact.setId("fsContact");
fsContact.setLayout(new RowLayout());
LayoutContainer lcUrlContainer = new LayoutContainer(new RowLayout());
fsContact.add(lcUrlContainer);
hmIdentite.put("lcUrlContainer", lcUrlContainer);
 
FieldSet fsAutresInfos = new FieldSet();
fsAutresInfos.setHeading("Autres informations");
right.add(fsContact);
formLayout = new FormLayout();
formLayout.setLabelAlign(LabelAlign.LEFT);
fsAutresInfos.setLayout(formLayout);
// Courriels
LabelField lfCourriel = new LabelField();
lfCourriel.setFieldLabel("Courriel:");
lfCourriel.setText("<b>Courriels:</b>");
//Civilité
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:");
fsContact.add(lfCourriel);
fsAutresInfos.add(cbSexe, fd100);
hmIdentite.put("cbSexe", cbSexe);
mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
LayoutContainer lcCourriel = new LayoutContainer();
ColumnLayout clLayout = new ColumnLayout();
lcCourriel.setLayout(clLayout);
TextField tfCourriel = new TextField();
lcCourriel.add(tfCourriel, new ColumnData(0.80));
// Bouton ajouter
IconButton bAjouterCourriel = new IconButton(ComposantClass.ICONE_AJOUTER);
lcCourriel.add(bAjouterCourriel, new ColumnData(0.15));
fsContact.add(lcCourriel);
TextArea taCourriel = new TextArea();
taCourriel.setFieldLabel("Courriels");
taCourriel.setEmptyText("Saisissez les adresses courriels séparées par un saut de ligne");
//fsContact.add(taCourriel, fd100);
hmIdentite.put("taCourriel", taCourriel);
// URLS
TextArea taUrl = new TextArea();
taUrl.setFieldLabel("Sites");
taUrl.setWidth("100%");
taUrl.setEmptyText("Saisissez les adresses des sites séparées par un saut de ligne");
//fsContact.add(taUrl, fd100);
hmIdentite.put("taUrl", taUrl);
// Autres informations
FieldSet fsAutresInfos = new FieldSet();
fsAutresInfos.setHeading("Autres informations");
formLayout = new FormLayout();
formLayout.setLabelAlign(LabelAlign.LEFT);
fsAutresInfos.setLayout(formLayout);
right.add(fsAutresInfos);
//Civilité
ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
ListStore<Valeur> storeSexe = new ListStore<Valeur>();
cbSexe.setStore(storeSexe);
cbSexe.setFieldLabel("Sexe");
cbSexe.setDisplayField("nom");
cbSexe.setEmptyText("Choisissez le sexe:");
fsAutresInfos.add(cbSexe, fd100);
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");
fsAutresInfos.add(taDescription, fd100);
hmIdentite.put("taDescription", taDescription);
// Logo
TextArea taLogo = new TextArea();
taLogo.setFieldLabel("Logos");
527,8 → 600,8
hmIdentite.put("taLogo", taLogo);
right.add(fsAutresInfos);
// Ajout des évènements saisi
KeyListener klNoms = new KeyListener() {
public void componentKeyUp(ComponentEvent ev) {
570,11 → 643,13
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);
615,16 → 690,21
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);
648,7 → 728,7
*
* @param barreOutils la barre d'outils à modifier
* */
public static void ajouterBoutonReinitialiser(ToolBar barreOutils) {
public void ajouterBoutonReinitialiser(ToolBar barreOutils) {
//Le bouton réintialiser recharge la page sans sauvegarder les informations
TextToolItem reinitialiser = new TextToolItem("Réinitialiser le formulaire");
655,7 → 735,9
reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
reinitialiser();
//System.out.println(personneSelectionnee);
}
});
barreOutils.add(reinitialiser);
684,7 → 766,7
*
* @param barreOutils la barre d'outils à modifier
* */
public static void ajouterBoutonEnregistrer(ButtonBar barreOutils) {
public void ajouterBoutonEnregistrer(ButtonBar barreOutils) {
//Le bouton réintialiser recharge la page sans sauvegarder les informations
Button enregistrer = new Button("Enregistrer");
692,7 → 774,9
enregistrer.setId("main-button");
enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
// TODO : Enregistrer le formulaire
enregistrer();
}
});
barreOutils.add(enregistrer);
772,6 → 856,7
} else if (nouvellesDonnees instanceof Information) {
Information info = (Information) nouvellesDonnees;
if (info.getDonnee(0) instanceof PersonneListe) {
780,17 → 865,25
Iterator itPersonneListe = colPersonneListe.iterator();
Personne personne = (Personne) itPersonneListe.next();
personneSauvegarde = new Personne();
personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
binderPersonne(personne);
//Mise à jour de la personne
//Personne personne = (Personne) nouvellesDonnees;
personneSelectionnee = personne;
//Prefixe
String prefixe = personne.get("ce_truk_prefix");
ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
String prefixeCourant = personne.get("ce_truk_prefix");
if (cbPrefixe.getStore().findModel("nom", prefixeCourant) != null) {
cbPrefixe.setValue(cbPrefixe.getStore().findModel("nom", prefixeCourant));
if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null) {
cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
} else {
cbPrefixe.setRawValue(prefixeCourant);
}
804,8 → 897,8
ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
String suffixeCourant = personne.get("ce_truk_suffix");
if (cbSuffixe.getStore().findModel("nom", suffixeCourant) != null) {
cbSuffixe.setValue(cbSuffixe.getStore().findModel("nom", suffixeCourant));
if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null) {
cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
} else {
cbSuffixe.setRawValue(suffixeCourant);
}
823,43 → 916,53
// Telephone
HashMap<String, String> hmTelephone = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
Collection<String> colTelephone = hmTelephone.keySet();
Iterator<String> itTelephone = colTelephone.iterator();
if (hmTelephone!=null) {
ListStore storeTelephone = ((ComboBox) hmIdentite.get("cbTelephone")).getStore();
List lstModelsTelephone = storeTelephone.getModels();
Iterator<Valeur> itStore = lstModelsTelephone.iterator();
HashMap<String, String> hmTel = new HashMap();
while (itStore.hasNext()) {
Valeur v = itStore.next();
hmTel.put(v.getAbreviation(), v.getNom());
}
Collection<String> colTelephone = hmTelephone.keySet();
Iterator<String> itTelephone = colTelephone.iterator();
while (itTelephone.hasNext()) {
String strTelephone = itTelephone.next();
String strTypeTelephone = hmTelephone.get(strTelephone);
ajouterTelephone(strTelephone, strTypeTelephone);
while (itTelephone.hasNext()) {
String strTypeTelephone = itTelephone.next();
String strTelephone = hmTelephone.get(strTypeTelephone);
String idTel = hmTel.get(strTypeTelephone);
if (idTel == null) {
idTel = strTypeTelephone;
}
ajouterTelephone(strTelephone, idTel, strTypeTelephone);
}
}
//Courriel
TextArea taCourriels = (TextArea) hmIdentite.get("taCourriel");
LinkedList<String> lCourriels = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
Iterator<String> itCourriels = lCourriels.iterator();
String strValeurCourriel = "";
while (itCourriels.hasNext()) {
strValeurCourriel += itCourriels.next() + "\n";
String strEmail = itCourriels.next();
ajouterCourriel(strEmail);
}
if (!strValeurCourriel.trim().equals("")) {
taCourriels.setRawValue(strValeurCourriel);
}
// Sites
TextArea taUrl = (TextArea) hmIdentite.get("taUrl");
LinkedList<String> lUrl = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_url");
Iterator<String> itUrl = lUrl.iterator();
String strValeurUrl = "";
while (itUrl.hasNext()) {
strValeurUrl += itUrl.next() + "\n";
String strUrl = itUrl.next();
ajouterUrl(strUrl);
}
if (!strValeurUrl.trim().equals("")) {
taUrl.setRawValue(strValeurUrl);
}
// Sexe
String strSexe = personne.get("ce_sexe");
ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
932,6 → 1035,8
//Ville
((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
}
}
998,21 → 1103,19
}
ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
store.removeAll();
store.add(liste);
((ComboBox) hm.get(idComboBox)).setStore(store);
}
public void ajouterTelephone(String strTelephone, String strValeurTypeTel) {
public void ajouterTelephone(String strTelephone, String strValeurTypeTel, String idTel) {
//Ajout d'un champ à la liste
HiddenField<String> hfTelephone = new HiddenField<String>();
hfTelephone.setId("hidden-" + strTelephone);
hfTelephone.setFieldLabel(strValeurTypeTel);
hfTelephone.setValue(strTelephone);
hmIdentite.put("hidden-" + strTelephone, hfTelephone);
String strIdTelephone = idTel + "##" + strTelephone + ";;";
FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1022,38 → 1125,39
Text tTypeTelephone = new Text();
tTypeTelephone.setText(strValeurTypeTel+":");
hmIdentite.put("type-" + strTelephone, tTypeTelephone);
hmIdentite.put("type-" + strIdTelephone, tTypeTelephone);
lcTelephone.add(tTypeTelephone, new ColumnData(0.40));
Text tTelephone = new Text();
tTelephone.setText(strTelephone);
hmIdentite.put("tel-" + strTelephone, tTelephone);
hmIdentite.put("tel-" + strIdTelephone, tTelephone);
lcTelephone.add(tTelephone, new ColumnData(0.40));
IconButton bSupprimer = new IconButton(ComposantClass.ICONE_SUPPRIMER);
bSupprimer.setId(strTelephone);
bSupprimer.setId(strIdTelephone);
bSupprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
String strTelephone = ce.component.getId();
LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strTelephone);
String strIdTelephone = ce.component.getId();
LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strIdTelephone);
lcContactTel.remove(hmIdentite.get("type-" + strTelephone));
hmIdentite.remove("type-" + strTelephone);
lcContactTel.remove(hmIdentite.get("type-" + strIdTelephone));
hmIdentite.remove("type-" + strIdTelephone);
lcContactTel.remove(hmIdentite.get("tel-" + strTelephone));
hmIdentite.remove("tel-" + strTelephone);
lcContactTel.remove(hmIdentite.get("tel-" + strIdTelephone));
hmIdentite.remove("tel-" + strIdTelephone);
((TabItem) hmIdentite.get("tiIdentite")).remove(hmIdentite.get("hidden-" + strTelephone));
hmIdentite.remove("hidden-" + strTelephone);
lcContactTel.remove(ce.component);
FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
fsContactTel.remove(lcContactTel);
HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
String strValeurTelephone = hfTelephone.getValue();
strValeurTelephone = strValeurTelephone.replace(strIdTelephone, "");
hfTelephone.setValue(strValeurTelephone);
layout();
}
1061,10 → 1165,16
lcTelephone.add(bSupprimer, new ColumnData(0.15));
hmIdentite.put("lc-"+strTelephone, lcTelephone);
hmIdentite.put("lc-"+strIdTelephone, lcTelephone);
fsContactTel.add(lcTelephone);
((TabItem) hmIdentite.get("tiIdentite")).add(hfTelephone);
HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
String strValeurTelephone = hfTelephone.getValue();
if (strValeurTelephone==null) {
strValeurTelephone = "";
}
strValeurTelephone += strIdTelephone;
hfTelephone.setValue(strValeurTelephone);
layout();
1073,6 → 1183,208
}
public void ajouterCourriel(String strEmail) {
TextField<String> tfCourriel = (TextField<String>) hmIdentite.get("tfCourriel");
tfCourriel.setValue("");
//Ajouter adresse email
LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
LayoutContainer lcCourriel = new LayoutContainer();
lcCourriel.setLayout(new ColumnLayout());
LabelField lfCourriel = new LabelField();
lfCourriel.setText(strEmail);
lcCourriel.add(lfCourriel, new ColumnData(0.8));
hmIdentite.put("lc-" + strEmail, lcCourriel);
//Bouton supprimer
IconButton btnSupprimerCourriel = new IconButton(ComposantClass.ICONE_SUPPRIMER);
btnSupprimerCourriel.setId(strEmail);
btnSupprimerCourriel.addSelectionListener(new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
//Suppression de l'adresse email
String strEmail = ce.component.getId();
LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
LayoutContainer lcCourriel = (LayoutContainer) hmIdentite.get("lc-" + strEmail);
lcCourrielContainer.remove(lcCourriel);
hmIdentite.remove("lc-" + strEmail);
hmIdentite.remove("email-" + strEmail);
HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
String strValeurCourriel = hfHiddenCourriel.getValue();
strValeurCourriel = strValeurCourriel.replace(strEmail + ";;", "");
hfHiddenCourriel.setValue(strValeurCourriel);
}
});
lcCourriel.add(btnSupprimerCourriel);
lcCourrielContainer.add(lcCourriel);
hmIdentite.put("email-" + strEmail, lfCourriel);
HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
String strHiddenCourrielValue = hfHiddenCourriel.getValue();
if (strHiddenCourrielValue == null) {
strHiddenCourrielValue = "";
}
hfHiddenCourriel.setRawValue(strHiddenCourrielValue + strEmail + ";;");
layout();
}
public void ajouterUrl(String strUrl) {
LayoutContainer lcUrlContainer = (LayoutContainer) hmIdentite.get("lcUrlContainer");
LayoutContainer lcUrl = new LayoutContainer();
lcUrl.setLayout(new ColumnLayout());
hmIdentite.put("lc-" + strUrl, lcUrl);
Text tUrl = new Text(strUrl);
hmIdentite.put("url-"+strUrl, tUrl);
lcUrl.add(tUrl, new ColumnData(0.8));
IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
ibSupprimerUrl.setId(strUrl);
ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
 
public void componentSelected(ComponentEvent ce) {
//Suppression url
String strUrl = ce.component.getId();
LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
LayoutContainer lcUrlContainer = (LayoutContainer) hmIdentite.get("lcUrlContainer");
lcUrlContainer.remove(lcUrl);
}
});
lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
lcUrlContainer.add(lcUrl);
layout();
}
public void reinitialiser() {
mediateur.afficherPopinChargement();
binderPersonne(personneSauvegarde);
layout();
mediateur.masquerPopinChargement();
}
public void binderPersonne(Personne personne) {
binding = new FormBinding(this);
personneSelectionnee = personne;
binding.autoBind();
binding.bind(personneSelectionnee);
layout();
}
 
/**
* Enregistre les information de la personne en cours
*
*/
public void enregistrer() {
LinkedList lstMessageErreur = new LinkedList<String>();
//Préparer les données
ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
Valeur valeur;
String strValeur = "";
if (combo.getValue()!=null) {
valeur = (Valeur) combo.getValue();
strValeur = valeur.getId();
}
if (!strValeur.trim().equals("")) {
personneSelectionnee.set("sexe", strValeur);
} else {
lstMessageErreur.add("Le champ Sexe n'a pas été renseigné");
}
strValeur = obtenirValeurCombo("cbPrefixe");
personneSelectionnee.set("ce_truk_prefix", strValeur);
strValeur = obtenirValeurCombo("cbSuffixe");
personneSelectionnee.set("ce_truk_suffix", strValeur);
personneSelectionnee.set("truk_courriel", ((HiddenField<String>) hmIdentite.get("hfHiddenCourriel")).getValue());
strValeur = personneSelectionnee.get("truk_prefix")
+ " " + personneSelectionnee.get("prenom")
+ " " + personneSelectionnee.get("nom")
+ " " + personneSelectionnee.get("truk_suffix");
personneSelectionnee.set("fmt_nom_complet", strValeur);
personneSelectionnee.set("naissance_date", (Date) ((DateField) hmIdentite.get("dfDateNaissance")).getValue());
strValeur = obtenirValeurCombo("cbPays");
personneSelectionnee.set("pays", strValeur);
strValeur = obtenirValeurCombo("cbRegion");
personneSelectionnee.set("region", strValeur);
personneSelectionnee.set("truk_telephone", ((HiddenField<String>) hmIdentite.get("hfTelephone")).getValue());
System.out.println(personneSelectionnee);
//tel
//fax
//logo
//url
}
private String obtenirValeurCombo(String strComboName) {
String strValeur = "";
Valeur valeur;
ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
if (combo == null) {
combo = (ComboBox) hmAdresse.get(strComboName);
}
if (combo.getValue()!=null) {
valeur = (Valeur) combo.getValue();
strValeur = valeur.getId();
} else {
strValeur = combo.getRawValue();
}
return strValeur;
}
}