Subversion Repositories eFlore/Archives.cel-v2

Rev

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

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