Subversion Repositories eFlore/Archives.cel-v2

Rev

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

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