Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 27 | Rev 36 | Go to most recent revision | Show entire file | Ignore 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
	/**
31
	private ImageMediateur	iMediateur	= null;
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()
-
 
66
	{
-
 
67
		super() ;
-
 
68
	}
-
 
69
	
-
 
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
34
 
73
	 */
35
	public GalerieImageVue(ImageMediateur im) {
74
	public GalerieImageVue(ImageMediateur im) {
-
 
75
		super("Galerie");
36
		super("Galerie");
76
		iMediateur = im;
Line 37... Line -...
37
		iMediateur = im;
-
 
38
 
-
 
39
		this.addListener(new ContainerListenerAdapter() {
-
 
40
 
-
 
41
			public void onHide(Component component) {
-
 
42
				// TODO Auto-generated method stub
77
		
43
 
-
 
44
			}
-
 
45
 
-
 
46
			public void onRender(Component component) {
-
 
47
				// TODO Auto-generated method stub
78
		// on ajoute des listeners au composant tout entier
Line 48... Line 79...
48
 
79
		this.addListener(new ContainerListenerAdapter() {
49
			}
80
 
50
 
81
			// pour gagner du temps on n'instancie la vue en elle même que lors du premier affichage (lazy rendering)
51
			public void onShow(Component component) {
82
			public void onShow(Component component) {
Line 52... Line 83...
52
 
83
 
-
 
84
				if (!estInstancie) {
-
 
85
					initialiser();
-
 
86
				}
-
 
87
			}
Line 53... Line 88...
53
				if (dView == null) {
88
 
Line -... Line 89...
-
 
89
		});
-
 
90
		
-
 
91
		// et on ajoute la tool bar
54
					initialiser();
92
		pt = new pageToolBarVue(im) ;
Line 55... Line 93...
55
				}
93
		this.setBottomToolbar(pt) ;
56
			}
94
 
57
 
95
	}
58
		});
96
 
-
 
97
	/**
59
 
98
	 * Ajoute tous les listeners nécessaires à l'intercation utilisateur avec la vue de données
60
	}
99
	 */
61
 
100
	public void ajouterListenersDataView() {
-
 
101
 
62
	public void ajouterListenersDataView() {
102
		// ajout de listeners pour la gestion de la selection
Line 63... Line 103...
63
 
103
		// dans la galerie
Line 64... Line -...
64
		// ajout de listeners pour la gestion de la selection
-
 
65
		// dans la galerie
104
		dView.addListener(new DataViewListenerAdapter() {
66
		dView.addListener(new DataViewListenerAdapter() {
-
 
67
 
-
 
68
			public void onClick(DataView source, int index, Element node,
-
 
69
					EventObject e) {
105
			
70
 
106
			// gestion du clic sur une image
Line -... Line 107...
-
 
107
			public void onClick(DataView source, int index, Element node,
71
				getIMediateur().clicGalerieImage(index, node, e);
108
					EventObject e) {
-
 
109
				
72
 
110
				// on en notifie le médiateur
Line 73... Line 111...
73
			}
111
				getIMediateur().clicGalerieImage(index, node, e);
Line -... Line 112...
-
 
112
 
74
 
113
			}
75
			public void onContainerClick(DataView source, EventObject e) {
114
 
Line 76... Line 115...
76
				// TODO: appeler le mediateur
115
			// gestion du clic droit
77
 
116
			public void onContextMenu(DataView source, int index, Element node,
78
			}
117
					EventObject e) {
79
 
118
 
Line -... Line 119...
-
 
119
				// on stoppe l'évenement       
80
			public void onContextMenu(DataView source, int index, Element node,
120
				e.stopEvent();
Line -... Line 121...
-
 
121
				// et on notifie le médiateur
81
					EventObject e) {
122
				getIMediateur().montrerContextMenu(e);
-
 
123
 
82
 
124
			}
83
				e.stopEvent();
125
 
-
 
126
			// gestion du double clic
84
				getIMediateur().montrerContextMenu(e);
127
			public void onDblClick(DataView source, int index, Element node,
-
 
128
					EventObject e) {
85
 
129
 
86
			}
130
				// on notife le mediateur
87
 
131
				getIMediateur().clicGalerieImage(index, node, e);
Line 88... Line 132...
88
			public void onDblClick(DataView source, int index, Element node,
132
				
89
					EventObject e) {
133
			}
Line -... Line 134...
-
 
134
 
-
 
135
			// gestion des actions en fonction de la selection
-
 
136
			public void onSelectionChange(DataView view, Element[] selections) {
-
 
137
 
90
 
138
				// s'il n'y a aucun élement sélectionné
91
				// TODO: appeler le mediateur
139
				if (selections.length <= 0) {
92
				getIMediateur().clicGalerieImage(index, node, e);
140
					// on en notifie le médiateur
Line -... Line 141...
-
 
141
					getIMediateur().aucuneSelection();
-
 
142
				} else {
-
 
143
					// sinon on notifie le médiateur
-
 
144
					getIMediateur().selection();
93
 
145
					// et on lui demande de synchroniser la séléction avec les autres vues
94
			}
146
					getIMediateur().synchroniserSelection("galerie");
95
 
147
				}
96
			public void onSelectionChange(DataView view, Element[] selections) {
148
			}
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
	 */
-
 
190
	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()
Line -... Line 199...
-
 
199
	{
130
	public Store getSt() {
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 174... Line 248...
174
		FieldDef[] defTab = { defNumImage, defDatImage, defLieImage,
248
		FieldDef[] defTab = { defNumImage, defDatImage, defLieImage,
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);
-
 
253
		
Line 179... Line 254...
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
183
		ajouterListenersDataView();
258
		ajouterListenersDataView();
-
 
259
 
184
 
260
		this.add(dView);
-
 
261
		
-
 
262
		// enfin on envoie une demande de données au médiateur
185
		this.add(dView);
263
		getIMediateur().obtenirPhotoGalerie(this);
Line -... Line 264...
-
 
264
		// et on déclare le composant comme instancié
-
 
265
		estInstancie = true ;
-
 
266
	}
186
 
267
 
187
		getIMediateur().obtenirPhotoGalerie(this);
268
	/**
Line -... Line 269...
-
 
269
	 * Méthode héritée de l'interface rafraichissable
188
	}
270
	 */
-
 
271
	public void rafraichir(Object nouvelleDonnees,
189
 
272
			boolean repandreRafraichissement) {
-
 
273
 
190
	public void rafraichir(Object nouvelleDonnees,
274
		// si l'objet reçu est un store
-
 
275
		if (nouvelleDonnees instanceof Store) {
191
			boolean repandreRafraichissement) {
276
			
-
 
277
			st = (Store) nouvelleDonnees;
192
 
278
			// on le charge
-
 
279
			st.load();
193
		if (nouvelleDonnees instanceof Store) {
280
			// on l'affecte à la vue
Line -... Line 281...
-
 
281
			dView.setStore(st);
194
			st = (Store) nouvelleDonnees;
282
			// et on rafrachit la vue
-
 
283
			dView.refresh();
195
			st.load();
284
			
196
			dView.setStore(st);
285
		}
197
			dView.refresh();
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(
-
 
291
					nouvelleDonnees, this);
198
		}
292
		}
Line -... Line 293...
-
 
293
		
-
 
294
		if(!estInstancie)
-
 
295
		{
-
 
296
			estInstancie = true ;
199
 
297
		}
Line 200... Line 298...
200
		if (repandreRafraichissement) {
298
	}
Line 201... Line 299...
201
			getIMediateur().synchroniserDonneesZoomListeGalerie(
299
 
-
 
300
	/**
202
					nouvelleDonnees, this);
301
	 * Sélectionne les images dans la galerie suivant les identifiants donnés en paramètres