Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 22 | Rev 31 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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