Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 27 | Rev 36 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 31
Line 1... Line 1...
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
Line 2... Line 2...
2
 
2
 
-
 
3
import org.tela_botanica.client.image.ImageMediateur;
3
import org.tela_botanica.client.image.ImageMediateur;
4
import com.gwtext.client.core.Ext;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.VueListable;
6
import org.tela_botanica.client.interfaces.VueListable;
-
 
7
import com.google.gwt.user.client.Element;
6
import com.google.gwt.user.client.Element;
8
import com.google.gwt.user.client.ui.Label;
-
 
9
import com.gwtext.client.core.EventObject;
7
import com.gwtext.client.core.EventObject;
10
import com.gwtext.client.core.ExtElement;
8
import com.gwtext.client.core.XTemplate;
11
import com.gwtext.client.core.XTemplate;
9
import com.gwtext.client.data.FieldDef;
12
import com.gwtext.client.data.FieldDef;
10
import com.gwtext.client.data.IntegerFieldDef;
13
import com.gwtext.client.data.IntegerFieldDef;
11
import com.gwtext.client.data.Record;
14
import com.gwtext.client.data.Record;
12
import com.gwtext.client.data.RecordDef;
15
import com.gwtext.client.data.RecordDef;
13
import com.gwtext.client.data.Store;
16
import com.gwtext.client.data.Store;
14
import com.gwtext.client.data.StringFieldDef;
17
import com.gwtext.client.data.StringFieldDef;
15
import com.gwtext.client.util.Format;
18
import com.gwtext.client.util.Format;
16
import com.gwtext.client.widgets.Component;
19
import com.gwtext.client.widgets.Component;
-
 
20
import com.gwtext.client.widgets.DataView;
17
import com.gwtext.client.widgets.DataView;
21
import com.gwtext.client.widgets.PagingToolbar;
-
 
22
import com.gwtext.client.widgets.Panel;
-
 
23
import com.gwtext.client.widgets.ToolTip;
-
 
24
import com.gwtext.client.widgets.Toolbar;
-
 
25
import com.gwtext.client.widgets.ToolbarButton;
18
import com.gwtext.client.widgets.Panel;
26
import com.gwtext.client.widgets.ToolbarTextItem;
19
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
27
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
-
 
28
import com.gwtext.client.widgets.event.DataViewListenerAdapter;
-
 
29
import com.gwtext.client.widgets.form.Field;
-
 
30
import com.gwtext.client.widgets.form.NumberField;
Line 20... Line 31...
20
import com.gwtext.client.widgets.event.DataViewListenerAdapter;
31
import com.gwtext.client.widgets.form.event.FieldListenerAdapter;
21
 
32
 
22
/**
33
/**
23
 * Galerie d'images miniatures
34
 * Galerie d'images miniatures
24
 * 
35
 * Avec barre de pagination 
25
 * @author aurelien
36
 * @author aurelien
26
 */
37
 */
Line -... Line 38...
-
 
38
public class GalerieImageVue extends Panel implements Rafraichissable,
27
public class GalerieImageVue extends Panel implements Rafraichissable,
39
		VueListable {
-
 
40
 
28
		VueListable {
41
	/**
-
 
42
	 * instance du médiateur
-
 
43
	 */ 
-
 
44
	private ImageMediateur	iMediateur	= null;
29
 
45
	/**
-
 
46
	 * Dataview, littéralement "vue de données" qui permet de définir la manière d'afficher les données
-
 
47
	 */ 
-
 
48
	private DataView		dView		= null;
30
	// instance du médiateur
49
	/**
-
 
50
	 * Dataview, littéralement "vue de données" qui permet de définir la manière d'afficher les données
-
 
51
	 */ 
-
 
52
	private Store			st			= null;
-
 
53
	/**
-
 
54
	 * Barre de pagination gérant l'affichage d'un nombre donné d'élements par page et la navigation entre eux
-
 
55
	 */ 
-
 
56
	private pageToolBarVue	pt 			= null ;
-
 
57
	/**
-
 
58
	 * Booleen indiquant si la galerie est instanciée ou pas
-
 
59
	 */ 
-
 
60
	private boolean 		estInstancie = false ;
-
 
61
 
-
 
62
	/**
-
 
63
	 * Constructeur sans argument, privé car ne doit pas être utilisé
-
 
64
	 */
-
 
65
	private GalerieImageVue()
Line -... Line 66...
-
 
66
	{
-
 
67
		super() ;
-
 
68
	}
-
 
69
	
31
	private ImageMediateur	iMediateur	= null;
70
	/**
32
	private DataView		dView		= null;
71
	 * Constructeur avec argument
33
	private Store			st			= null;
72
	 * @param im le médiateur avec lequel la vue va communiquer
Line -... Line 73...
-
 
73
	 */
34
 
74
	public GalerieImageVue(ImageMediateur im) {
Line 35... Line -...
35
	public GalerieImageVue(ImageMediateur im) {
-
 
36
		super("Galerie");
-
 
37
		iMediateur = im;
-
 
38
 
-
 
39
		this.addListener(new ContainerListenerAdapter() {
-
 
40
 
75
		super("Galerie");
41
			public void onHide(Component component) {
-
 
42
				// TODO Auto-generated method stub
-
 
43
 
-
 
44
			}
-
 
45
 
76
		iMediateur = im;
Line 46... Line 77...
46
			public void onRender(Component component) {
77
		
47
				// TODO Auto-generated method stub
78
		// on ajoute des listeners au composant tout entier
48
 
79
		this.addListener(new ContainerListenerAdapter() {
49
			}
80
 
Line 50... Line 81...
50
 
81
			// pour gagner du temps on n'instancie la vue en elle même que lors du premier affichage (lazy rendering)
Line -... Line 82...
-
 
82
			public void onShow(Component component) {
-
 
83
 
-
 
84
				if (!estInstancie) {
-
 
85
					initialiser();
51
			public void onShow(Component component) {
86
				}
Line -... Line 87...
-
 
87
			}
-
 
88
 
-
 
89
		});
52
 
90
		
Line 53... Line 91...
53
				if (dView == null) {
91
		// et on ajoute la tool bar
54
					initialiser();
92
		pt = new pageToolBarVue(im) ;
55
				}
93
		this.setBottomToolbar(pt) ;
Line -... Line 94...
-
 
94
 
56
			}
95
	}
57
 
96
 
Line -... Line 97...
-
 
97
	/**
58
		});
98
	 * Ajoute tous les listeners nécessaires à l'intercation utilisateur avec la vue de données
Line 59... Line 99...
59
 
99
	 */
Line 60... Line -...
60
	}
-
 
61
 
100
	public void ajouterListenersDataView() {
62
	public void ajouterListenersDataView() {
-
 
63
 
-
 
64
		// ajout de listeners pour la gestion de la selection
-
 
65
		// dans la galerie
101
 
66
		dView.addListener(new DataViewListenerAdapter() {
102
		// ajout de listeners pour la gestion de la selection
Line -... Line 103...
-
 
103
		// dans la galerie
67
 
104
		dView.addListener(new DataViewListenerAdapter() {
-
 
105
			
68
			public void onClick(DataView source, int index, Element node,
106
			// gestion du clic sur une image
Line 69... Line 107...
69
					EventObject e) {
107
			public void onClick(DataView source, int index, Element node,
Line -... Line 108...
-
 
108
					EventObject e) {
70
 
109
				
71
				getIMediateur().clicGalerieImage(index, node, e);
110
				// on en notifie le médiateur
Line 72... Line 111...
72
 
111
				getIMediateur().clicGalerieImage(index, node, e);
73
			}
112
 
Line 74... Line 113...
74
 
113
			}
Line -... Line 114...
-
 
114
 
75
			public void onContainerClick(DataView source, EventObject e) {
115
			// gestion du clic droit
Line -... Line 116...
-
 
116
			public void onContextMenu(DataView source, int index, Element node,
76
				// TODO: appeler le mediateur
117
					EventObject e) {
-
 
118
 
77
 
119
				// on stoppe l'évenement       
78
			}
120
				e.stopEvent();
-
 
121
				// et on notifie le médiateur
79
 
122
				getIMediateur().montrerContextMenu(e);
-
 
123
 
80
			public void onContextMenu(DataView source, int index, Element node,
124
			}
81
					EventObject e) {
125
 
82
 
126
			// gestion du double clic
Line 83... Line 127...
83
				e.stopEvent();
127
			public void onDblClick(DataView source, int index, Element node,
84
				getIMediateur().montrerContextMenu(e);
128
					EventObject e) {
Line -... Line 129...
-
 
129
 
-
 
130
				// on notife le mediateur
-
 
131
				getIMediateur().clicGalerieImage(index, node, e);
-
 
132
				
85
 
133
			}
86
			}
134
 
87
 
135
			// gestion des actions en fonction de la selection
Line -... Line 136...
-
 
136
			public void onSelectionChange(DataView view, Element[] selections) {
-
 
137
 
-
 
138
				// s'il n'y a aucun élement sélectionné
-
 
139
				if (selections.length <= 0) {
88
			public void onDblClick(DataView source, int index, Element node,
140
					// on en notifie le médiateur
89
					EventObject e) {
141
					getIMediateur().aucuneSelection();
90
 
142
				} else {
91
				// TODO: appeler le mediateur
143
					// sinon on notifie le médiateur
Line 121... Line 173...
121
		}
173
		}
Line 122... Line 174...
122
 
174
 
123
		return id_selection;
175
		return id_selection;
Line -... Line 176...
-
 
176
	}
-
 
177
 
-
 
178
	/**
-
 
179
	 * Accesseur pour le médiateur
124
	}
180
	 * @return le mdéiateur associé à la vue
125
 
181
	 */
126
	public ImageMediateur getIMediateur() {
182
	public ImageMediateur getIMediateur() {
Line -... Line 183...
-
 
183
		return iMediateur;
-
 
184
	}
-
 
185
 
-
 
186
	/**
127
		return iMediateur;
187
	 * Accesseur pour le store
128
	}
188
	 * @return le store associée à la vue
129
 
189
	 */
Line -... Line 190...
-
 
190
	public Store getSt() {
130
	public Store getSt() {
191
		return st;
-
 
192
	}
-
 
193
	
-
 
194
	/**
-
 
195
	 * Accesseur pour la toolbar 
-
 
196
	 * @return la toolbar associée à la vue
-
 
197
	 */
-
 
198
	public pageToolBarVue getToolBarVue()
-
 
199
	{
-
 
200
		return pt ;
-
 
201
	}
131
		return st;
202
 
-
 
203
	/**
-
 
204
	 * Fonction d'initialisation du contenu (appelée lors du premier affichage de la liste)
132
	}
205
	 */
133
 
206
	public void initialiser() {
134
	// instantiation paresseuse
207
		
135
	public void initialiser() {
208
		
136
		// Preparation de la dataview et du template
209
		// Preparation de la dataview et du template
137
		// le template va créer une div contenant une image
210
		// le template va créer une div contenant une image
138
		// pour chacune des photos
211
		// pour chacune des photos
139
		final XTemplate template = new XTemplate(
212
		final XTemplate template = new XTemplate(
140
				new String[] {
213
				new String[] {
141
						"<tpl for='.'>",
214
						"<tpl for='.'>",
-
 
215
						"<div class='thumb-wrap' id='{num_image}'>",
142
						"<div class='thumb-wrap' id='{num_image}'>",
216
						"<div class='thumb'><img src='{url_image_M}' title='{num_image}'></div>",
Line 143... Line 217...
143
						"<div class='thumb'><img src='{url_image_M}' title='{num_image}'></div>",
217
						"<span>{nom}</span></div>", "</tpl>",
144
						"<span>{nom}</span></div>", "</tpl>",
218
						"<div class='x-clear'></div>" });
145
						"<div class='x-clear'></div>" });
219
		// pour des raisons de performances on compile le template en une fonction
Line 175... Line 249...
175
				defAppImage, defUrlImageS, defUrlImageM, defUrlImage };
249
				defAppImage, defUrlImageS, defUrlImageM, defUrlImage };
176
		RecordDef rd = new RecordDef(defTab);
250
		RecordDef rd = new RecordDef(defTab);
177
		st = new Store(rd);
251
		st = new Store(rd);
178
		dView.setStore(st);
252
		dView.setStore(st);
Line -... Line 253...
-
 
253
		
179
 
254
 
Line 180... Line 255...
180
		this.getDView().setLoadingText("chargement");
255
		this.getDView().setLoadingText("chargement");
181
 
256
 
Line 182... Line 257...
182
		// ajouts de la gestion des evenements pour la dataview
257
		// ajouts de la gestion des evenements pour la dataview
Line -... Line 258...
-
 
258
		ajouterListenersDataView();
183
		ajouterListenersDataView();
259
 
-
 
260
		this.add(dView);
-
 
261
		
184
 
262
		// enfin on envoie une demande de données au médiateur
Line -... Line 263...
-
 
263
		getIMediateur().obtenirPhotoGalerie(this);
-
 
264
		// et on déclare le composant comme instancié
-
 
265
		estInstancie = true ;
185
		this.add(dView);
266
	}
186
 
267
 
Line -... Line 268...
-
 
268
	/**
187
		getIMediateur().obtenirPhotoGalerie(this);
269
	 * Méthode héritée de l'interface rafraichissable
-
 
270
	 */
188
	}
271
	public void rafraichir(Object nouvelleDonnees,
-
 
272
			boolean repandreRafraichissement) {
189
 
273
 
-
 
274
		// si l'objet reçu est un store
190
	public void rafraichir(Object nouvelleDonnees,
275
		if (nouvelleDonnees instanceof Store) {
-
 
276
			
191
			boolean repandreRafraichissement) {
277
			st = (Store) nouvelleDonnees;
-
 
278
			// on le charge
192
 
279
			st.load();
Line -... Line 280...
-
 
280
			// on l'affecte à la vue
193
		if (nouvelleDonnees instanceof Store) {
281
			dView.setStore(st);
-
 
282
			// et on rafrachit la vue
194
			st = (Store) nouvelleDonnees;
283
			dView.refresh();
195
			st.load();
284
			
196
			dView.setStore(st);
285
		}
-
 
286
 
-
 
287
		// si le com)posant doit répandre le rafraichissement
-
 
288
		if (repandreRafraichissement) {
-
 
289
			// il en notifie le médiateur en lui donnant une copie des données
-
 
290
			getIMediateur().synchroniserDonneesZoomListeGalerie(
197
			dView.refresh();
291
					nouvelleDonnees, this);
Line -... Line 292...
-
 
292
		}
-
 
293
		
-
 
294
		if(!estInstancie)
-
 
295
		{
198
		}
296
			estInstancie = true ;
Line 199... Line 297...
199
 
297
		}
Line 200... Line 298...
200
		if (repandreRafraichissement) {
298
	}
-
 
299
 
201
			getIMediateur().synchroniserDonneesZoomListeGalerie(
300
	/**