1,12 → 1,367 |
package org.tela_botanica.client.vues; |
|
import java.util.HashMap; |
|
import org.tela_botanica.client.ComposantClass; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.RegistreId; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
|
|
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.HorizontalAlignment; |
import com.extjs.gxt.ui.client.event.ComponentEvent; |
import com.extjs.gxt.ui.client.event.KeyListener; |
import com.extjs.gxt.ui.client.event.SelectionListener; |
import com.extjs.gxt.ui.client.widget.Container; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.LayoutContainer; |
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.form.TextField; |
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.FlowLayout; |
import com.extjs.gxt.ui.client.widget.layout.FormLayout; |
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem; |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; |
|
import com.google.gwt.user.client.ui.Panel; |
import com.google.gwt.user.client.ui.Widget; |
|
public class FormPersonneVue extends LayoutContainer implements Rafraichissable { |
|
|
public class FormPersonneVue extends ContentPanel implements Rafraichissable { |
|
|
/*-------------------------------------------------------------------------------------- |
* VARIABLES |
* ------------------------------------------------------------------------------------- |
*/ |
|
private TabItem tiIdentite, tiAdresses, tiInfosNat; |
|
|
/*-------------------------------------------------------------------------------------- |
* CONSTRUCTEUR |
* ------------------------------------------------------------------------------------- |
*/ |
/** |
* Constructeur du panneau |
* |
* Initialise le panneau et ajoute une barre d'outils à deux boutons (réinitialiser le |
* formulaire et annuler la saisie). |
* |
* */ |
public FormPersonneVue() { |
|
initialiserPanneau(this); |
|
ToolBar barreOutils = new ToolBar(); |
|
ajouterBoutonEnregistrer(barreOutils); |
ajouterBoutonReinitialiser(barreOutils); |
ajouterBoutonAnnuler(barreOutils); |
|
setTopComponent(barreOutils); |
|
initialiserOnglets(); |
|
creerComposantsIdentite(); |
} |
|
|
/*--------------------------------------------------------------------------------------- |
* SOUS-METHODES |
* -------------------------------------------------------------------------------------- |
*/ |
/** |
* Inialise le panneau donné |
* |
* @param contentPanel le panneau à initialiser |
* */ |
public void initialiserPanneau(ContentPanel contentPanel) { |
|
contentPanel.setLayout(new FitLayout()); |
contentPanel.setIconStyle("icone-form-ajouter"); |
contentPanel.setCollapsible(false); |
contentPanel.setHeading("Ajouter une personne"); |
contentPanel.setButtonAlign(HorizontalAlignment.CENTER); |
contentPanel.setLayout(new FormLayout()); |
} |
|
/** |
* Crée les onglets identité, adresse et informations naturaliste |
* |
* */ |
public void initialiserOnglets() { |
//TabPanel |
TabPanel formulaireOnglets = new TabPanel(); |
|
//Tab 1 : identite |
tiIdentite = new TabItem("Identité"); |
tiIdentite.setLayout(new FormLayout()); |
formulaireOnglets.add(tiIdentite); |
|
|
//Tab 2 : Adresse |
tiAdresses = new TabItem("Adresse"); |
tiAdresses.setLayout(new FlowLayout()); |
formulaireOnglets.add(tiAdresses); |
|
//Tab 3 : Infos Naturalistes |
tiInfosNat = new TabItem("Informations Naturalistes"); |
tiInfosNat.setLayout(new FormLayout()); |
formulaireOnglets.add(tiInfosNat); |
|
add(formulaireOnglets); |
} |
|
/** |
* Crée les widgets pour l'onglet identité |
* |
* */ |
|
//hmIdentite référence par une chaine de caractère tous les composants de l'onglet Identite |
private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>(); |
|
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 |
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(.5)); |
main.add(right, new ColumnData(.5)); |
|
|
// 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); |
|
hmIdentite.put("nomComplet", nomComplet); |
|
//Préfixe |
TextField<String> tfPrefix = new TextField<String>(); |
tfPrefix.setFieldLabel("Préfixe"); |
fsNoms.add(tfPrefix); |
|
hmIdentite.put("tfPrefix", tfPrefix); |
|
//Prénom |
TextField<String> tfPrenom = new TextField<String>(); |
tfPrenom.setFieldLabel("Prénom"); |
fsNoms.add(tfPrenom); |
|
hmIdentite.put("tfPrenom", tfPrenom); |
|
//Nom |
TextField<String> tfNom = new TextField<String>(); |
tfNom.setFieldLabel("Nom"); |
fsNoms.add(tfNom); |
|
hmIdentite.put("tfNom", tfNom); |
|
//Suffixe |
TextField<String> tfSuffix = new TextField<String>(); |
tfSuffix.setFieldLabel("Suffixe"); |
fsNoms.add(tfSuffix); |
|
hmIdentite.put("tfSuffix", tfSuffix); |
|
// Nom : autre |
TextField<String> tfNomAutre = new TextField(); |
tfNomAutre.setFieldLabel("Autres noms"); |
fsNoms.add(tfNomAutre); |
|
hmIdentite.put("tfNomAutre", tfNomAutre); |
|
//Abréviation |
TextField<String> tfAbreviation = new TextField<String>(); |
tfAbreviation.setFieldLabel("Abréviation"); |
fsNoms.add(tfAbreviation); |
|
hmIdentite.put("tfAbreviation", tfAbreviation); |
|
//Abréviation autres |
TextField<String> tfAbreviationAutre = new TextField<String>(); |
tfAbreviationAutre.setFieldLabel("Autres Abrév."); |
fsNoms.add(tfAbreviationAutre); |
|
hmIdentite.put("tfAbreviation", tfAbreviation); |
|
|
left.add(fsNoms); |
|
// Naissance & décès |
FieldSet fsVie = new FieldSet(); |
fsVie.setHeading("Vie"); |
|
formLayout = new FormLayout(); |
formLayout.setLabelAlign(LabelAlign.LEFT); |
fsVie.setLayout(formLayout); |
|
// Date naissance |
TextField<String> tfDateNaissance = new TextField(); |
|
|
|
tiIdentite.add(main); |
|
|
// Ajout des évènements saisi |
KeyListener klNoms = new KeyListener() { |
public void componentKeyUp(ComponentEvent ev) { |
/* |
* Met à jour le nom Complet du formulaire |
* */ |
String valeurRetour = ""; |
// Prefixe |
String prefixe = (String) ((TextField) hmIdentite.get("tfPrefix")).getValue(); |
|
// Prénom |
String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue(); |
|
// Nom |
String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue(); |
|
// Suffixe |
String suffixe = (String) ((TextField) hmIdentite.get("tfSuffix")).getValue(); |
|
// Mettre à jour la valeur |
valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe; |
valeurRetour = valeurRetour.replaceAll("null", ""); |
|
((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour); |
|
if (!valeurRetour.trim().equals("")) { |
((LabelField) hmIdentite.get("nomComplet")).show(); |
} else { |
((LabelField) hmIdentite.get("nomComplet")).hide(); |
} |
|
} |
}; |
|
tfPrefix.addKeyListener(klNoms); |
tfPrenom.addKeyListener(klNoms); |
tfNom.addKeyListener(klNoms); |
tfSuffix.addKeyListener(klNoms); |
|
|
//Prénom |
|
} |
|
public void ajouterTextField(String id, String strLabel, Panel panel) { |
|
TextField tf = new TextField(); |
tf.setFieldLabel(strLabel); |
panel.add(tf); |
|
hmIdentite.put(id, tf); |
} |
|
public void ajouterLabelField(String id, String strLabel, Panel panel) { |
|
LabelField tf = new LabelField(); |
tf.setFieldLabel(strLabel); |
panel.add(tf); |
|
hmIdentite.put(id, tf); |
} |
|
|
/** |
* Ajouter le bouton réinitialiser à la barre d'outils donnée |
* |
* @param barreOutils la barre d'outils à modifier |
* */ |
public static void ajouterBoutonReinitialiser(ToolBar barreOutils) { |
|
//Le bouton réintialiser recharge la page sans sauvegarder les informations |
TextToolItem reinitialiser = new TextToolItem("Réinitialiser"); |
reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR); |
reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne(); |
} |
}); |
barreOutils.add(reinitialiser); |
} |
|
/** |
* Ajouter le bouton Sauvegarder à la barre d'outils donnée |
* |
* @param barreOutils la barre d'outils à modifier |
* */ |
public static void ajouterBoutonEnregistrer(ToolBar barreOutils) { |
|
//Le bouton réintialiser recharge la page sans sauvegarder les informations |
TextToolItem reinitialiser = new TextToolItem("Enregistrer"); |
reinitialiser.setIconStyle(ComposantClass.ICONE_PREFERENCE); |
reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
// TODO : Enregistrer le formulaire |
} |
}); |
barreOutils.add(reinitialiser); |
} |
|
/** |
* Ajouter le bouton annuler à la barre d'outils donnée |
* |
* @param barreOutils la barre d'outils à modifier |
* */ |
public static void ajouterBoutonAnnuler(ToolBar barreOutils) { |
|
// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente |
TextToolItem annuler = new TextToolItem("Annuler"); |
annuler.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes"); |
} |
}); |
annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER); |
barreOutils.add(annuler); |
} |
|
|
|
/*--------------------------------------------------------------------------------------- |
* RAFRAICHISSEMENT DU PANNEAU |
* -------------------------------------------------------------------------------------- |
*/ |
public void rafraichir(Object nouvelleDonnees) { |
// TODO Auto-generated method stub |
|