Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.widgets;

import java.util.ArrayList;
import java.util.List;

import org.tela_botanica.client.AppEvenements;
import org.tela_botanica.client.modeles.Institution;

import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binder.TableBinder;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
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;

public class InstitutionListePanneau extends ContentPanel {
        
        private Table table;
        private ListStore<Institution> store;
        private TableBinder<Institution> binder;

        public InstitutionListePanneau() {
                ToolBar toolBar = new ToolBar();
                TextToolItem create = new TextToolItem("Create");
                create.setIconStyle("icon-email-add");
                toolBar.add(create);

                TextToolItem reply = new TextToolItem("Reply");
                reply.setIconStyle("icon-email-reply");
                toolBar.add(reply);

                setTopComponent(toolBar);

                List<TableColumn> columns = new ArrayList<TableColumn>();
                columns.add(new TableColumn("sender", "Sender", .2f));
                columns.add(new TableColumn("email", "Email", .3f));
                columns.add(new TableColumn("subject", "Subject", .5f));

                TableColumnModel cm = new TableColumnModel(columns);

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

                add(table);

                store = new ListStore<Institution>();

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

                setLayout(new FitLayout());
        }

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

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

        private void showMailItem(Institution item) {
                AppEvent evt = new AppEvent(AppEvenements.VoirInstitutionDetail, item);
                Dispatcher.forwardEvent(evt);
        }
}