Rev 7 | Rev 16 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;
import java.util.Iterator;
import org.tela_botanica.client.image.ImageMediateur;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.ImageCarnet;
import org.tela_botanica.client.modeles.ListeImage;
import com.google.gwt.user.client.Window;
import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.IntegerFieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.Record;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StoreMgr;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.event.ContainerListener;
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
import com.gwtext.client.widgets.event.PanelListener;
import com.gwtext.client.widgets.event.PanelListenerAdapter;
import com.gwtext.client.widgets.grid.CellMetadata;
import com.gwtext.client.widgets.grid.ColumnConfig;
import com.gwtext.client.widgets.grid.ColumnModel;
import com.gwtext.client.widgets.grid.GridPanel;
import com.gwtext.client.widgets.grid.GridView;
import com.gwtext.client.widgets.grid.Renderer;
import com.gwtext.client.widgets.layout.AnchorLayout;
import com.gwtext.client.widgets.layout.FitLayout;
import com.gwtextux.client.data.BufferedStore;
/**
* Liste d'image composée de miniatures et d'information sur l'image
* @author aurelien
*
*/
public class ListeImageVue extends GridPanel implements Rafraichissable {
// instance du médiateur
private ImageMediateur iMediateur = null;
private ColumnConfig numImage ;
private ColumnConfig urlImage ;
private ColumnConfig lieImage ;
private ColumnConfig datImage ;
private ColumnConfig appImage ;
private ColumnModel modeleColonnes ;
// données locales
// store qui gère les données de la liste d'images
private Store st = null ;
private ColumnConfig cl = null ;
public ListeImageVue(ImageMediateur im) {
super() ;
this.iMediateur = im ;
numImage = new ColumnConfig("numéro","num_image",100,true);
datImage = new ColumnConfig("date","dat_image",120,true);
lieImage = new ColumnConfig("lieu","lie_image",120,true);
appImage = new ColumnConfig("appareil","app_image",200,true);
urlImage = new ColumnConfig("Image","url_image",200,true,new Renderer() {
public String render(Object value, CellMetadata cellMetadata,
Record record, int rowIndex, int colNum, Store store) {
String ImgUrl = record.getAsString("url_image");
String ImgNum = record.getAsString("num_image");
return "<div class=\"img-list\"> <img src=\""+ImgUrl+"\" title='"+ImgNum+"'> </div>";
}
});
ColumnConfig[] cm = {numImage,datImage,lieImage,appImage,urlImage};
modeleColonnes = new ColumnModel(cm);
this.setColumnModel(modeleColonnes);
this.setAutoScroll(true);
this.setAutoWidth(true);
FieldDef defNumImage = new StringFieldDef("num_image");
FieldDef defDatImage = new StringFieldDef("dat_image");
FieldDef defLieImage = new StringFieldDef("lie_image");
FieldDef defAppImage = new StringFieldDef("app_image");
FieldDef defUrlImage = new StringFieldDef("url_image");
FieldDef[] defTab = {defNumImage,defDatImage,defLieImage,defAppImage,defUrlImage};
RecordDef rd = new RecordDef(defTab) ;
st = new Store(rd) ;
this.setStore(st);
this.getView().setAutoFill(true) ;
ajouterListeners() ;
}
// role : configurer les colonnes affichées dans la grille
private void initialiser() {
getIMediateur().obtenirPhotoGalerie(this);
}
public void ajouterListeners()
{
this.addListener(new ContainerListenerAdapter() {
public boolean doBeforeRender(Component component)
{
initialiser();
return true ;
}
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) {
}
});
}
public void rafraichir(Object nouvelleDonnees) {
if(nouvelleDonnees instanceof ListeImage)
{
ListeImage data = (ListeImage) nouvelleDonnees ;
Object[][] photoData = new Object[data.size()][5];
for(int i = 0 ; i<data.size();i++)
{
ImageCarnet im = (ImageCarnet) data.elementAt(i);
photoData[i][0] = im.getOrdre() ;
photoData[i][1] = im.getDate() ;
photoData[i][2] = im.getIptcCity() ;
photoData[i][3] = im.getMake()+" "+im.getModel() ;
photoData[i][4] = im.getUrl() ;
}
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 defUrlImage = new StringFieldDef("url_image");
FieldDef[] defTab = {defNumImage,defDatImage,defLieImage,defAppImage,defUrlImage};
final MemoryProxy dataProxy = new MemoryProxy(photoData);
final ArrayReader reader = new ArrayReader(new RecordDef(defTab));
final Store photoStore = new Store(dataProxy, reader);
st = photoStore;
this.reconfigure(st, this.getColumnModel());
photoStore.load();
}
}
public ImageMediateur getIMediateur() {
return iMediateur;
}
public ColumnConfig getNumImage() {
return numImage;
}
public ColumnConfig getUrlImage() {
return urlImage;
}
public ColumnModel getModeleColonnes() {
return modeleColonnes;
}
public Store getSt() {
return st;
}
public ColumnConfig getCl() {
return cl;
}
}