Subversion Repositories eFlore/Archives.cel-v2

Rev

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

package org.tela_botanica.client.vues;

import org.tela_botanica.client.image.ImageMediateur;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.interfaces.VueListable;
import com.google.gwt.user.client.Element;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.XTemplate;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.IntegerFieldDef;
import com.gwtext.client.data.Record;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.util.Format;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.DataView;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
import com.gwtext.client.widgets.event.DataViewListenerAdapter;

/**
 * Galerie d'images miniatures
 * 
 * @author aurelien
 */
public class GalerieImageVue extends Panel implements Rafraichissable,
                VueListable {

        // instance du médiateur
        private ImageMediateur  iMediateur      = null;
        private DataView                dView           = null;
        private Store                   st                      = null;

        public GalerieImageVue(ImageMediateur im) {
                super("Galerie");
                iMediateur = im;

                this.addListener(new ContainerListenerAdapter() {

                        public void onHide(Component component) {
                                // TODO Auto-generated method stub

                        }

                        public void onRender(Component component) {
                                // TODO Auto-generated method stub

                        }

                        public void onShow(Component component) {

                                if (dView == null) {
                                        initialiser();
                                }
                        }

                });

        }

        public void ajouterListenersDataView() {

                // ajout de listeners pour la gestion de la selection
                // dans la galerie
                dView.addListener(new DataViewListenerAdapter() {

                        public void onClick(DataView source, int index, Element node,
                                        EventObject e) {

                                getIMediateur().clicGalerieImage(index, node, e);

                        }

                        public void onContainerClick(DataView source, EventObject e) {
                                // TODO: appeler le mediateur

                        }

                        public void onContextMenu(DataView source, int index, Element node,
                                        EventObject e) {

                                e.stopEvent();
                                getIMediateur().montrerContextMenu(e);

                        }

                        public void onDblClick(DataView source, int index, Element node,
                                        EventObject e) {

                                // TODO: appeler le mediateur
                                getIMediateur().clicGalerieImage(index, node, e);

                        }

                        public void onSelectionChange(DataView view, Element[] selections) {

                                if (selections.length <= 0) {
                                        getIMediateur().aucuneSelection();
                                } else {
                                        getIMediateur().selection();
                                        getIMediateur().synchroniserSelection("galerie");
                                }
                        }

                });
        }

        public DataView getDView() {
                return dView;
        }

        public String[] getIdSelectionnees() {
                Record[] selection = getDView().getSelectedRecords();
                int taille = selection.length;
                String id_selection[] = new String[taille];

                for (int i = 0; i < selection.length; i++) {

                        id_selection[i] = selection[i].getAsString("num_image");
                }

                return id_selection;
        }

        public ImageMediateur getIMediateur() {
                return iMediateur;
        }

        public Store getSt() {
                return st;
        }

        // instantiation paresseuse
        public void initialiser() {
                // Preparation de la dataview et du template
                // le template va créer une div contenant une image
                // pour chacune des photos
                final XTemplate template = new XTemplate(
                                new String[] {
                                                "<tpl for='.'>",
                                                "<div class='thumb-wrap' id='{num_image}'>",
                                                "<div class='thumb'><img src='{url_image_M}' title='{num_image}'></div>",
                                                "<span>{nom}</span></div>", "</tpl>",
                                                "<div class='x-clear'></div>" });
                template.compile();

                // la dataview affichera les images en accord avec le template
                // cree precedemment
                dView = new DataView("div.thumb-wrap") {

                        public void prepareData(Data data) {
                                data.setProperty("shortName", Format.ellipsis(data
                                                .getProperty("num_image"), 15));
                        }
                };
                dView.setTpl(template);

                // parametre d'affichage de la dataview
                this.setAutoScroll(true);
                dView.setAutoHeight(true);
                dView.setMultiSelect(true);
                dView.setOverCls("x-view-over");
                dView.setEmptyText("Aucune image à afficher");

                // creation du store
                FieldDef defNumImage = new IntegerFieldDef("num_image");
                FieldDef defDatImage = new StringFieldDef("dat_image");
                FieldDef defLieImage = new StringFieldDef("lie_image");
                FieldDef defAppImage = new StringFieldDef("app_image");
                FieldDef defUrlImageS = new StringFieldDef("url_image_S");
                FieldDef defUrlImageM = new StringFieldDef("url_image_M");
                FieldDef defUrlImage = new StringFieldDef("url_image");
                FieldDef[] defTab = { defNumImage, defDatImage, defLieImage,
                                defAppImage, defUrlImageS, defUrlImageM, defUrlImage };
                RecordDef rd = new RecordDef(defTab);
                st = new Store(rd);
                dView.setStore(st);

                this.getDView().setLoadingText("chargement");

                // ajouts de la gestion des evenements pour la dataview
                ajouterListenersDataView();

                this.add(dView);

                getIMediateur().obtenirPhotoGalerie(this);
        }

        public void rafraichir(Object nouvelleDonnees,
                        boolean repandreRafraichissement) {

                if (nouvelleDonnees instanceof Store) {
                        st = (Store) nouvelleDonnees;
                        st.load();
                        dView.setStore(st);
                        dView.refresh();
                }

                if (repandreRafraichissement) {
                        getIMediateur().synchroniserDonneesZoomListeGalerie(
                                        nouvelleDonnees, this);
                }
        }

        public void selectionnerImages(int[] ids) {

                getDView().select(ids);

        }
}