Rev 136 | Blame | Last modification | View Log | RSS feed
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 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() {//TabPanelTabPanel formulaireOnglets = new TabPanel();//Tab 1 : identitetiIdentite = new TabItem("Identité");tiIdentite.setLayout(new FormLayout());formulaireOnglets.add(tiIdentite);//Tab 2 : AdressetiAdresses = new TabItem("Adresse");tiAdresses.setLayout(new FlowLayout());formulaireOnglets.add(tiAdresses);//Tab 3 : Infos NaturalistestiInfosNat = 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 Identiteprivate 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// GaucheLayoutContainer left = new LayoutContainer();left.setLayout(new FormLayout());// DroiteLayoutContainer right = new LayoutContainer();right.setLayout(new FormLayout());// PrincipalLayoutContainer main = new LayoutContainer();main.setLayout(new ColumnLayout());// Ajout au principalmain.add(left, new ColumnData(.5));main.add(right, new ColumnData(.5));// Création des champs//FormLayout sera utilisé à plusieurs reprisesFormLayout formLayout = new FormLayout();FieldSet fsNoms = new FieldSet();fsNoms.setHeading("Noms");formLayout.setLabelAlign(LabelAlign.LEFT);fsNoms.setLayout(formLayout);// Nom complet// Affiché que si valeurs saisiesLabelField nomComplet = new LabelField();nomComplet.setFieldLabel("Nom complet:");nomComplet.hide();fsNoms.add(nomComplet);hmIdentite.put("nomComplet", nomComplet);//PréfixeTextField<String> tfPrefix = new TextField<String>();tfPrefix.setFieldLabel("Préfixe");fsNoms.add(tfPrefix);hmIdentite.put("tfPrefix", tfPrefix);//PrénomTextField<String> tfPrenom = new TextField<String>();tfPrenom.setFieldLabel("Prénom");fsNoms.add(tfPrenom);hmIdentite.put("tfPrenom", tfPrenom);//NomTextField<String> tfNom = new TextField<String>();tfNom.setFieldLabel("Nom");fsNoms.add(tfNom);hmIdentite.put("tfNom", tfNom);//SuffixeTextField<String> tfSuffix = new TextField<String>();tfSuffix.setFieldLabel("Suffixe");fsNoms.add(tfSuffix);hmIdentite.put("tfSuffix", tfSuffix);// Nom : autreTextField<String> tfNomAutre = new TextField();tfNomAutre.setFieldLabel("Autres noms");fsNoms.add(tfNomAutre);hmIdentite.put("tfNomAutre", tfNomAutre);//AbréviationTextField<String> tfAbreviation = new TextField<String>();tfAbreviation.setFieldLabel("Abréviation");fsNoms.add(tfAbreviation);hmIdentite.put("tfAbreviation", tfAbreviation);//Abréviation autresTextField<String> tfAbreviationAutre = new TextField<String>();tfAbreviationAutre.setFieldLabel("Autres Abrév.");fsNoms.add(tfAbreviationAutre);hmIdentite.put("tfAbreviation", tfAbreviation);left.add(fsNoms);// Naissance & décèsFieldSet fsVie = new FieldSet();fsVie.setHeading("Vie");formLayout = new FormLayout();formLayout.setLabelAlign(LabelAlign.LEFT);fsVie.setLayout(formLayout);// Date naissanceTextField<String> tfDateNaissance = new TextField();tiIdentite.add(main);// Ajout des évènements saisiKeyListener klNoms = new KeyListener() {public void componentKeyUp(ComponentEvent ev) {/** Met à jour le nom Complet du formulaire* */String valeurRetour = "";// PrefixeString prefixe = (String) ((TextField) hmIdentite.get("tfPrefix")).getValue();// PrénomString prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();// NomString nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();// SuffixeString suffixe = (String) ((TextField) hmIdentite.get("tfSuffix")).getValue();// Mettre à jour la valeurvaleurRetour = 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 informationsTextToolItem 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 informationsTextToolItem 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édenteTextToolItem 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}}