Subversion Repositories eFlore/Archives.cel-v2

Rev

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

Rev Author Line No. Line
4 aperonnet 1
package org.tela_botanica.client.vues;
2
 
3
import org.tela_botanica.client.image.ImageMediateur;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
19 aperonnet 5
import org.tela_botanica.client.interfaces.VueListable;
4 aperonnet 6
import com.google.gwt.user.client.Element;
7
import com.gwtext.client.core.EventObject;
8
import com.gwtext.client.core.XTemplate;
9
import com.gwtext.client.data.FieldDef;
22 aperonnet 10
import com.gwtext.client.data.IntegerFieldDef;
18 aperonnet 11
import com.gwtext.client.data.Record;
4 aperonnet 12
import com.gwtext.client.data.RecordDef;
13
import com.gwtext.client.data.Store;
14
import com.gwtext.client.data.StringFieldDef;
15
import com.gwtext.client.util.Format;
16
import com.gwtext.client.widgets.Component;
17
import com.gwtext.client.widgets.DataView;
18
import com.gwtext.client.widgets.Panel;
5 aperonnet 19
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
4 aperonnet 20
import com.gwtext.client.widgets.event.DataViewListenerAdapter;
21
 
12 aperonnet 22
/**
23
 * Galerie d'images miniatures
27 aperonnet 24
 *
12 aperonnet 25
 * @author aurelien
26
 */
27 aperonnet 27
public class GalerieImageVue extends Panel implements Rafraichissable,
28
		VueListable {
4 aperonnet 29
 
30
	// instance du médiateur
27 aperonnet 31
	private ImageMediateur	iMediateur	= null;
32
	private DataView		dView		= null;
33
	private Store			st			= null;
34
 
35
	public GalerieImageVue(ImageMediateur im) {
4 aperonnet 36
		super("Galerie");
27 aperonnet 37
		iMediateur = im;
38
 
5 aperonnet 39
		this.addListener(new ContainerListenerAdapter() {
4 aperonnet 40
 
5 aperonnet 41
			public void onHide(Component component) {
42
				// TODO Auto-generated method stub
27 aperonnet 43
 
4 aperonnet 44
			}
5 aperonnet 45
 
46
			public void onRender(Component component) {
47
				// TODO Auto-generated method stub
27 aperonnet 48
 
5 aperonnet 49
			}
50
 
27 aperonnet 51
			public void onShow(Component component) {
5 aperonnet 52
 
27 aperonnet 53
				if (dView == null) {
5 aperonnet 54
					initialiser();
55
				}
56
			}
27 aperonnet 57
 
5 aperonnet 58
		});
27 aperonnet 59
 
4 aperonnet 60
	}
27 aperonnet 61
 
62
	public void ajouterListenersDataView() {
63
 
4 aperonnet 64
		// ajout de listeners pour la gestion de la selection
65
		// dans la galerie
66
		dView.addListener(new DataViewListenerAdapter() {
67
 
68
			public void onClick(DataView source, int index, Element node,
69
					EventObject e) {
27 aperonnet 70
 
12 aperonnet 71
				getIMediateur().clicGalerieImage(index, node, e);
27 aperonnet 72
 
4 aperonnet 73
			}
74
 
27 aperonnet 75
			public void onContainerClick(DataView source, EventObject e) {
76
				// TODO: appeler le mediateur
4 aperonnet 77
 
78
			}
79
 
80
			public void onContextMenu(DataView source, int index, Element node,
81
					EventObject e) {
27 aperonnet 82
 
83
				e.stopEvent();
84
				getIMediateur().montrerContextMenu(e);
85
 
4 aperonnet 86
			}
87
 
88
			public void onDblClick(DataView source, int index, Element node,
89
					EventObject e) {
27 aperonnet 90
 
91
				// TODO: appeler le mediateur
12 aperonnet 92
				getIMediateur().clicGalerieImage(index, node, e);
27 aperonnet 93
 
4 aperonnet 94
			}
95
 
27 aperonnet 96
			public void onSelectionChange(DataView view, Element[] selections) {
4 aperonnet 97
 
27 aperonnet 98
				if (selections.length <= 0) {
22 aperonnet 99
					getIMediateur().aucuneSelection();
27 aperonnet 100
				} else {
101
					getIMediateur().selection();
102
					getIMediateur().synchroniserSelection("galerie");
22 aperonnet 103
				}
4 aperonnet 104
			}
27 aperonnet 105
 
4 aperonnet 106
		});
107
	}
27 aperonnet 108
 
109
	public DataView getDView() {
110
		return dView;
111
	}
112
 
113
	public String[] getIdSelectionnees() {
114
		Record[] selection = getDView().getSelectedRecords();
115
		int taille = selection.length;
116
		String id_selection[] = new String[taille];
117
 
118
		for (int i = 0; i < selection.length; i++) {
119
 
120
			id_selection[i] = selection[i].getAsString("num_image");
121
		}
122
 
123
		return id_selection;
124
	}
125
 
126
	public ImageMediateur getIMediateur() {
127
		return iMediateur;
128
	}
129
 
130
	public Store getSt() {
131
		return st;
132
	}
133
 
5 aperonnet 134
	// instantiation paresseuse
27 aperonnet 135
	public void initialiser() {
136
		// Preparation de la dataview et du template
5 aperonnet 137
		// le template va créer une div contenant une image
138
		// pour chacune des photos
139
		final XTemplate template = new XTemplate(
27 aperonnet 140
				new String[] {
5 aperonnet 141
						"<tpl for='.'>",
142
						"<div class='thumb-wrap' id='{num_image}'>",
22 aperonnet 143
						"<div class='thumb'><img src='{url_image_M}' title='{num_image}'></div>",
5 aperonnet 144
						"<span>{nom}</span></div>", "</tpl>",
27 aperonnet 145
						"<div class='x-clear'></div>" });
5 aperonnet 146
		template.compile();
147
 
148
		// la dataview affichera les images en accord avec le template
149
		// cree precedemment
150
		dView = new DataView("div.thumb-wrap") {
27 aperonnet 151
 
5 aperonnet 152
			public void prepareData(Data data) {
153
				data.setProperty("shortName", Format.ellipsis(data
154
						.getProperty("num_image"), 15));
155
			}
156
		};
157
		dView.setTpl(template);
27 aperonnet 158
 
5 aperonnet 159
		// parametre d'affichage de la dataview
12 aperonnet 160
		this.setAutoScroll(true);
5 aperonnet 161
		dView.setAutoHeight(true);
162
		dView.setMultiSelect(true);
163
		dView.setOverCls("x-view-over");
164
		dView.setEmptyText("Aucune image à afficher");
27 aperonnet 165
 
5 aperonnet 166
		// creation du store
22 aperonnet 167
		FieldDef defNumImage = new IntegerFieldDef("num_image");
168
		FieldDef defDatImage = new StringFieldDef("dat_image");
169
		FieldDef defLieImage = new StringFieldDef("lie_image");
170
		FieldDef defAppImage = new StringFieldDef("app_image");
171
		FieldDef defUrlImageS = new StringFieldDef("url_image_S");
172
		FieldDef defUrlImageM = new StringFieldDef("url_image_M");
5 aperonnet 173
		FieldDef defUrlImage = new StringFieldDef("url_image");
27 aperonnet 174
		FieldDef[] defTab = { defNumImage, defDatImage, defLieImage,
175
				defAppImage, defUrlImageS, defUrlImageM, defUrlImage };
176
		RecordDef rd = new RecordDef(defTab);
177
		st = new Store(rd);
5 aperonnet 178
		dView.setStore(st);
27 aperonnet 179
 
19 aperonnet 180
		this.getDView().setLoadingText("chargement");
27 aperonnet 181
 
5 aperonnet 182
		// ajouts de la gestion des evenements pour la dataview
183
		ajouterListenersDataView();
184
 
27 aperonnet 185
		this.add(dView);
5 aperonnet 186
 
27 aperonnet 187
		getIMediateur().obtenirPhotoGalerie(this);
5 aperonnet 188
	}
189
 
27 aperonnet 190
	public void rafraichir(Object nouvelleDonnees,
191
			boolean repandreRafraichissement) {
5 aperonnet 192
 
27 aperonnet 193
		if (nouvelleDonnees instanceof Store) {
194
			st = (Store) nouvelleDonnees;
195
			st.load();
196
			dView.setStore(st);
197
			dView.refresh();
198
		}
5 aperonnet 199
 
27 aperonnet 200
		if (repandreRafraichissement) {
201
			getIMediateur().synchroniserDonneesZoomListeGalerie(
202
					nouvelleDonnees, this);
18 aperonnet 203
		}
204
	}
22 aperonnet 205
 
27 aperonnet 206
	public void selectionnerImages(int[] ids) {
22 aperonnet 207
 
27 aperonnet 208
		getDView().select(ids);
209
 
22 aperonnet 210
	}
4 aperonnet 211
}