Subversion Repositories eFlore/Archives.cel-v2

Rev

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