Subversion Repositories eFlore/Applications.coel

Rev

Rev 462 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues;

import java.util.ArrayList;
import java.util.Iterator;
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.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Information;
import org.tela_botanica.client.modeles.Personne;
import org.tela_botanica.client.modeles.PersonneListe;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.SortDir;
import com.extjs.gxt.ui.client.binder.TableBinder;
import com.extjs.gxt.ui.client.event.ComponentEvent;
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.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.table.Table;
import com.extjs.gxt.ui.client.widget.table.TableColumn;
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
import com.extjs.gxt.ui.client.widget.table.TableItem;
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;

public class PersonneListeVue extends ContentPanel implements Rafraichissable {
        
        private Mediateur mediateur = null ;
        private Table table = null;
        private ListStore<Personne> store = null;
        private TableBinder<Personne> binder = null;
        private Personne personneSelectionnee = null;
        
        public PersonneListeVue() {
                mediateur = Registry.get(RegistreId.MEDIATEUR);
                
                //Définition de la barre d'outil
                ToolBar toolBar = new ToolBar();
                TextToolItem ajouter = new TextToolItem(mediateur.i18nC.ajouter());
                ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
                ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {  
                        public void componentSelected(ComponentEvent ce) {  
                                mediateur.clicAjouterPersonne();
                        }  
                });
                toolBar.add(ajouter);
                
                
                final Rafraichissable r = this ;

                // TODO : ajouter btn mod & supp
                final TextToolItem modifier = new TextToolItem(mediateur.i18nC.modifier());
                modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
                modifier.addSelectionListener(new SelectionListener<ComponentEvent>() {  
                        public void componentSelected(ComponentEvent ce) {  
                                mediateur.clicModifierPersonne(personneSelectionnee);
                        }  
                });
                toolBar.add(modifier);
                
                final TextToolItem supprimer = new TextToolItem(mediateur.i18nC.supprimer());
                supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {  
                        public void componentSelected(ComponentEvent ce) {  
                        
                                mediateur.clicSupprimerPersonne(r, binder.getSelection());
                        }  
                });
                
                supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
                toolBar.add(supprimer);
                
                setTopComponent(toolBar);
                
                List<TableColumn> columns = new ArrayList<TableColumn>();
                
                // ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
                columns.add(new TableColumn("fmt_nom_complet", mediateur.i18nC.personneNomComplet(), .30f));
                columns.add(new TableColumn("code_postal", mediateur.i18nC.personneCodePostal(), .10f));
                columns.add(new TableColumn("ville", mediateur.i18nC.personneVille(), .20f));
                columns.add(new TableColumn("courriel_princ", mediateur.i18nC.personneCourriel(), .25f));
                columns.add(new TableColumn("nom", mediateur.i18nC.personneNom(), .10f));
                columns.add(new TableColumn("prenom", mediateur.i18nC.personnePrenom(), .10f));
                
                columns.get(4).setHidden(true);
                columns.get(5).setHidden(true);
                
                TableColumnModel cm = new TableColumnModel(columns);
                
                table = new Table(cm);
                table.setSelectionMode(SelectionMode.MULTI);
                table.setBorders(false);
                
                table.setHorizontalScroll(true);
                
                add(table);

                store = new ListStore<Personne>();

                binder = new TableBinder<Personne>(table, store);
                binder.setAutoSelect(true);
                
                binder.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
                public void selectionChanged(SelectionChangedEvent<Personne> event) {
                                Personne p = (Personne) event.getSelectedItem();
                                personneSelectionnee = p;
                                clicListe(p);
                        }
                });
                
                setLayout(new FitLayout());
        }

        private void clicListe(Personne personne) {
                mediateur.clicListePersonne(personne);
        }

        public void rafraichir(Object nouvellesDonnees) {
                
                if (nouvellesDonnees instanceof PersonneListe) {
                        
                        setHeading(mediateur.i18nC.personneListeLabel());
                        PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
                        
                        List<Personne> liste = new ArrayList<Personne>();
                        for (Iterator<String> it = listePersonnes.keySet().iterator(); it.hasNext();) {
                                liste.add(listePersonnes.get(it.next()));
                        }
                        
                        store.removeAll();
                        store.add(liste);
                        
                        mediateur.actualiserPanneauCentral();
                        
                        table.sort(0, SortDir.ASC);
                        if (store.getCount() > 0) {
                                table.getSelectionModel().select(0);
                        }
                        
                        
                        
                } else if (nouvellesDonnees instanceof Information)     {
                        
                        Information info = (Information) nouvellesDonnees;
                        Info.display("Erreur", info.getMessages().toString());
                        
                        if (info.getType().equals("suppression_personne"))      {
                        
                                        List<TableItem> selectionPersonnes = table.getSelectedItems();
                                        final int taille = selectionPersonnes.size();
                                        for (int i = 0; i < taille; i++) {
                                                //GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
                                                table.remove(selectionPersonnes.get(i));
                                        }
                        }
                        
                        
                        
                } else {
                        GWT.log(mediateur.messages.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
                }
                layout();
        }
}