Subversion Repositories eFlore/Applications.coel

Rev

Rev 69 | 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.Structure;
import org.tela_botanica.client.modeles.StructureListe;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.SelectionMode;
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.layout.FitLayout;
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.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 StructureListePanneauVue extends ContentPanel implements Rafraichissable {
        
        private Rafraichissable structureListePanneauVue = null ;
        private Mediateur coelMediateur = null ;
        private Table table = null;
        private ListStore<Structure> store = null;
        private TableBinder<Structure> binder = null;

        public StructureListePanneauVue() {
                coelMediateur = Registry.get(RegistreId.MEDIATEUR);
                structureListePanneauVue = this;
                
                ToolBar toolBar = new ToolBar();
                TextToolItem ajouter = new TextToolItem("Ajouter");
                ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
                ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {  
                        public void componentSelected(ComponentEvent ce) {  
                                coelMediateur.clicAjouterStructure();
                        }
                });
                toolBar.add(ajouter);

                TextToolItem modifier = new TextToolItem("Modifier");
                modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
                toolBar.add(modifier);
                
                TextToolItem supprimer = new TextToolItem("Supprimer");
                supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
                supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
                        public void componentSelected(ComponentEvent ce) {
                                coelMediateur.clicSupprimerStructure(structureListePanneauVue, binder.getSelection());
                        }
                });
                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("ville", "Ville", .3f));
                columns.add(new TableColumn("nom", "Nom", .7f));
                
                TableColumnModel cm = new TableColumnModel(columns);

                table = new Table(cm);
                table.setSelectionMode(SelectionMode.MULTI);
                table.setBorders(false);

                add(table);

                store = new ListStore<Structure>();

                binder = new TableBinder<Structure>(table, store);
                binder.setAutoSelect(true);
                binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
                        public void selectionChanged(SelectionChangedEvent<Structure> event) {
                                Structure m = (Structure) event.getSelectedItem();
                                clicListe(m);
                        }
                });

                setLayout(new FitLayout());
        }

        public ListStore<Structure> getStore() {
                return store;
        }

        public TableBinder<Structure> getBinder() {
                return binder;
        }

        private void clicListe(Structure institution) {
                coelMediateur.clicListeInstitution(institution);
        }

        public void rafraichir(Object nouvelleDonnees) {
                if (nouvelleDonnees instanceof StructureListe) {
                        StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
                        setHeading("Institutions");

                        List<Structure> liste = new ArrayList<Structure>();
                        for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
                                liste.add(listeInstitutions.get(it.next()));
                        }
                        
                        store.removeAll();
                        store.add((List<Structure>) liste);
                        
                        // Test pour savoir si la liste contient des éléments
                        if (listeInstitutions.size() > 0) {
                                binder.setSelection((Structure) listeInstitutions.get(0));
                        }
                } else if (nouvelleDonnees instanceof Information) {
                        Information info = (Information) nouvelleDonnees;
                        if (info.getType().equals("suppression_structure")) {
                                GWT.log(info.getMessages().toString(), null);
                                Info.display("Suppression Structure", info.toString());
                        }
                }
                
        }
}