Subversion Repositories eFlore/Applications.coel

Rev

Rev 703 | Rev 775 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.composants.ChampMultiValeurs;
import org.tela_botanica.client.images.Images;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Collection;
import org.tela_botanica.client.modeles.CollectionListe;
import org.tela_botanica.client.modeles.Configuration;
import org.tela_botanica.client.modeles.Information;
import org.tela_botanica.client.modeles.MenuApplicationId;
import org.tela_botanica.client.modeles.Projet;
import org.tela_botanica.client.modeles.ProjetListe;
import org.tela_botanica.client.modeles.Structure;
import org.tela_botanica.client.modeles.StructureListe;
import org.tela_botanica.client.modeles.Valeur;
import org.tela_botanica.client.modeles.ValeurListe;

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.ComponentEvent;
import com.extjs.gxt.ui.client.event.EventType;
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.event.WidgetListener;
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.store.StoreListener;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
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.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
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.NumberField;
import com.extjs.gxt.ui.client.widget.form.Radio;
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.Validator;
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.FormData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.ui.Widget;

public class CollectionForm extends Formulaire implements Rafraichissable {

        private Collection collection = null;
        private Collection collectionCollectee = null;

        private HashMap<String,ComboBox<Valeur>> champsCbv = new HashMap<String,ComboBox<Valeur>>();
        private HashMap<String,ListStore<Valeur>> champsLsv = new HashMap<String,ListStore<Valeur>>();
        
        private TabItem generalOnglet = null;
        private TabItem auteurOnglet = null;
        private TabItem publicationOnglet = null;
        private TabItem descriptionOnglet = null;
        private TabItem contenuOnglet = null;
        private TabItem documentOnglet = null;
        private TabItem inventaireOnglet = null;
        
        public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {
                initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
        }
        
        protected void creerOnglets() {
                onglets = new TabPanel();
                // NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner) 
                onglets.setHeight("100%");
                
                // Onlget formulaire GENERAL
                onglets.add(creerOngletGeneral());
                
                // Onlget formulaire AUTEUR
                onglets.add(creerOngletAuteur());
                
                // Onlget formulaire PUBLICATION
                onglets.add(creerOngletPublication());
                
                // Onlget formulaire DESCRIPTION
                onglets.add(creerOngletDescription());
                
                // Onlget formulaire CONTENU
                onglets.add(creerOngletContenu());
                
                // Onlget formulaire DOCUMENT
                onglets.add(creerOngletDocument());
                
                // Onlget formulaire INVENTAIRE
                onglets.add(creerOngletInventaire());
                
                // Sélection de l'onglet par défaut
                onglets.setSelection(auteurOnglet);
                
                // Ajout des onglets au formulaire général
                panneauFormulaire.add(onglets);
        }
        
        private TabItem creerOngletGeneral() {
                generalOnglet = new CollectionFormGeneral(this);
                return generalOnglet;
        }
        
        private TabItem creerOngletAuteur() {
                auteurOnglet = new CollectionFormAuteur(this);
                return auteurOnglet;
        }
        
        private TabItem creerOngletPublication() {
                publicationOnglet = new CollectionFormPublication(this);
                return publicationOnglet;
        }
        
        private TabItem creerOngletDescription() {
                descriptionOnglet = creerOnglet(i18nC.collectionDescription(), "description");
                descriptionOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {  
                        public void handleEvent(ComponentEvent be) {  
                                //peuplerOngletDescription();
                                descriptionOnglet.layout();
                        }  
                });
                
                return descriptionOnglet;
        }
        
        private TabItem creerOngletContenu() {
                contenuOnglet = creerOnglet(i18nC.collectionContenu(), "contenu");
                contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {  
                        public void handleEvent(ComponentEvent be) {  
                                //peuplerOngletContenu();
                                contenuOnglet.layout();
                        }  
                });
                
                return contenuOnglet;
        }
        
        private TabItem creerOngletDocument() {
                documentOnglet = creerOnglet(i18nC.collectionDocument(), "document");
                documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {  
                        public void handleEvent(ComponentEvent be) {  
                                //peuplerOngletDocument();
                                documentOnglet.layout();
                        }  
                });
                
                return documentOnglet;
        }
        
        private TabItem creerOngletInventaire() {
                inventaireOnglet = creerOnglet(i18nC.collectionInventaire(), "inventaire");
                inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {  
                        public void handleEvent(ComponentEvent be) {  
                                //peuplerOngletInventaire();
                                inventaireOnglet.layout();
                        }  
                });
                
                return inventaireOnglet;
        }
        
        public void rafraichir(Object nouvellesDonnees) {
                try {
                        if (nouvellesDonnees instanceof Information) {
                                Information info = (Information) nouvellesDonnees;
                                rafraichirInformation(info);
                        } else {
                                GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
                        }
                } catch (Exception e) {
                        GWT.log("rafraichir()", e);
                }
                verifierApresRafraichissement();
        }

        private void rafraichirInformation(Information info) {
                if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
                        GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
                }
                
                if (info.getType().equals("modif_structure")) {
                        Info.display("Modification d'une collection", info.toString());
                } else if (info.getType().equals("selection_collection")) {
                        Info.display("Modification d'une collection", info.toString());
                        if (info.getDonnee(0) != null) {
                                collection = (Collection) info.getDonnee(0);
                        }
                        actualiserPeuplementOnglet();
                        actualiserTitrePanneau();
                }
        }
        
        private void actualiserPeuplementOnglet() {
                onglets.setSelection(onglets.getSelectedItem());
        }

        private void actualiserTitrePanneau() {
                String titre = i18nC.titreModifFormCollection();
                // Composition du titre
                titre += " - ID : "+collection.getId();
                panneauFormulaire.setHeading(titre);            
        }

        @Override
        protected SelectionListener<ButtonEvent> creerEcouteurBoutonFormulaire(final String code) {
                SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
                        @Override
                        public void componentSelected(ButtonEvent ce) {
                                if (code.equals(Formulaire.CODE_BOUTON_VALIDER)) {
                                        soumettreFormulaire();
                                        clicBoutonvalidation = true;
                                } else if (code.equals(Formulaire.CODE_BOUTON_APPLIQUER)) {
                                        soumettreFormulaire();
                                } else if (code.equals(Formulaire.CODE_BOUTON_ANNULER)) {
                                        mediateur.clicMenu(menuIdCourant);
                                } else if (code.equals(Formulaire.CODE_BOUTON_REINITIALISER)) {
                                        if (mode.equals(StructureForm.MODE_MODIFIER)) {
                                                mediateur.afficherFormCollection(collection.getId());
                                        } else {
                                                mediateur.afficherFormCollection(null);
                                        }
                                }
                        }
                };
                
                return ecouteur;
        }
        
        protected void soumettreFormulaire() {
                // Vérification de la validité des champs du formulaire
                if (verifierFormulaire()) {
                        // Collecte des données du formulaire
                        Collection collection = collecterCollection();
                        
                        if (mode.equals(MODE_AJOUTER)) {
                                mediateur.ajouterCollection(this, collection);
                        } else if (mode.equals(MODE_MODIFIER)) {
                                if (collection == null) {
                                        Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
                                } else {
                                        mediateur.modifierCollection(this, collection);
                                }
                        }
                }
        }
        
        private Collection collecterCollection() {
                collectionCollectee = (Collection) collection.cloner(new Collection());
                
                collecterOngletGeneral();
                
                Collection collectionARetourner = null;
                if (!collectionCollectee.comparer(collection)) {
                        collectionARetourner = collection = collectionCollectee;
                }
                return collectionARetourner;
        }
        
        private void collecterOngletGeneral() {
                if (generalOnglet.getData("acces").equals(true)) {
                        
                }
        }
        
        private Boolean verifierFormulaire() {
                return true;
        }

        @Override
        protected void afficherChampSupplementaire(Radio radioBtn) {
                // TODO Auto-generated method stub
                
        }
}