Subversion Repositories eFlore/Archives.cel-v2

Rev

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

Rev 5 Rev 6
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
 
3
 
4
import org.tela_botanica.client.image.ImageMediateur;
4
import org.tela_botanica.client.image.ImageMediateur;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
 
6
 
7
 
7
 
8
import com.google.gwt.core.client.JavaScriptObject;
8
import com.google.gwt.core.client.JavaScriptObject;
9
import com.google.gwt.user.client.Element;
9
import com.google.gwt.user.client.Element;
10
import com.google.gwt.user.client.Event;
10
import com.google.gwt.user.client.Event;
11
import com.gwtext.client.core.EventObject;
11
import com.gwtext.client.core.EventObject;
12
import com.gwtext.client.core.XTemplate;
12
import com.gwtext.client.core.XTemplate;
13
import com.gwtext.client.data.ArrayReader;
13
import com.gwtext.client.data.ArrayReader;
14
import com.gwtext.client.data.FieldDef;
14
import com.gwtext.client.data.FieldDef;
15
import com.gwtext.client.data.MemoryProxy;
15
import com.gwtext.client.data.MemoryProxy;
16
import com.gwtext.client.data.RecordDef;
16
import com.gwtext.client.data.RecordDef;
17
import com.gwtext.client.data.Store;
17
import com.gwtext.client.data.Store;
18
import com.gwtext.client.data.StringFieldDef;
18
import com.gwtext.client.data.StringFieldDef;
19
import com.gwtext.client.util.Format;
19
import com.gwtext.client.util.Format;
20
import com.gwtext.client.widgets.BoxComponent;
20
import com.gwtext.client.widgets.BoxComponent;
21
import com.gwtext.client.widgets.Component;
21
import com.gwtext.client.widgets.Component;
22
import com.gwtext.client.widgets.Container;
22
import com.gwtext.client.widgets.Container;
23
import com.gwtext.client.widgets.DataView;
23
import com.gwtext.client.widgets.DataView;
24
import com.gwtext.client.widgets.Observable;
24
import com.gwtext.client.widgets.Observable;
25
import com.gwtext.client.widgets.Panel;
25
import com.gwtext.client.widgets.Panel;
26
import com.gwtext.client.widgets.DataView.Data;
26
import com.gwtext.client.widgets.DataView.Data;
27
import com.gwtext.client.widgets.event.ContainerListener;
27
import com.gwtext.client.widgets.event.ContainerListener;
28
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
28
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
29
import com.gwtext.client.widgets.event.DataViewListener;
29
import com.gwtext.client.widgets.event.DataViewListener;
30
import com.gwtext.client.widgets.event.DataViewListenerAdapter;
30
import com.gwtext.client.widgets.event.DataViewListenerAdapter;
31
 
31
 
32
public class GalerieImageVue extends Panel implements Rafraichissable, Observable {
32
public class GalerieImageVue extends Panel implements Rafraichissable, Observable {
33
 
33
 
34
	// instance du médiateur
34
	// instance du médiateur
35
	private ImageMediateur iMediateur = null; 
35
	private ImageMediateur iMediateur = null; 
36
	private DataView dView = null ;
36
	private DataView dView = null ;
37
	private Store st = null ;
37
	private Store st = null ;
38
	
38
	
39
	public GalerieImageVue(ImageMediateur im)
39
	public GalerieImageVue(ImageMediateur im)
40
	{
40
	{
41
		super("Galerie");
41
		super("Galerie");
42
		iMediateur = im ;
42
		iMediateur = im ;
43
		
43
		
44
		this.addListener(new ContainerListenerAdapter() {
44
		this.addListener(new ContainerListenerAdapter() {
45
 
45
 
46
 
46
 
47
			public void onHide(Component component) {
47
			public void onHide(Component component) {
48
				// TODO Auto-generated method stub
48
				// TODO Auto-generated method stub
49
				
49
				
50
			}
50
			}
51
 
51
 
52
 
52
 
53
			public void onRender(Component component) {
53
			public void onRender(Component component) {
54
				// TODO Auto-generated method stub
54
				// TODO Auto-generated method stub
55
				
55
				
56
			}
56
			}
57
 
57
 
58
 
58
 
59
			public void onShow(Component component) {
59
			public void onShow(Component component) {
60
				
60
				
61
				
61
				
62
				if(dView == null)
62
				if(dView == null)
63
				{
63
				{
64
					initialiser();
64
					initialiser();
65
				}
65
				}
66
			}
66
			}
67
			
67
			
68
		});
68
		});
69
		
69
		
70
	}
70
	}
71
	
71
	
72
	
72
	
73
	public void ajouterListenersDataView()
73
	public void ajouterListenersDataView()
74
	{
74
	{
75
		
75
		
76
		// ajout de listeners pour la gestion de la selection
76
		// ajout de listeners pour la gestion de la selection
77
		// dans la galerie
77
		// dans la galerie
78
		dView.addListener(new DataViewListenerAdapter() {
78
		dView.addListener(new DataViewListenerAdapter() {
79
 
79
 
80
 
80
 
81
 
81
 
82
			public void onClick(DataView source, int index, Element node,
82
			public void onClick(DataView source, int index, Element node,
83
					EventObject e) {
83
					EventObject e) {
84
				
84
				
85
				getIMediateur().ClicGalerieImage(index, node, e);
85
				getIMediateur().ClicGalerieImage(index, node, e);
86
				
86
				
87
			}
87
			}
88
 
88
 
89
 
89
 
90
			public void onContainerClick(DataView source, EventObject e) {
90
			public void onContainerClick(DataView source, EventObject e) {
91
				//TODO: appeler le mediateur
91
				//TODO: appeler le mediateur
92
				
92
				
93
			}
93
			}
94
 
94
 
95
 
95
 
96
			public void onContextMenu(DataView source, int index, Element node,
96
			public void onContextMenu(DataView source, int index, Element node,
97
					EventObject e) {
97
					EventObject e) {
98
				//TODO: appeler le mediateur
98
				//TODO: appeler le mediateur
99
				
99
				
100
			}
100
			}
101
 
101
 
102
 
102
 
103
			public void onDblClick(DataView source, int index, Element node,
103
			public void onDblClick(DataView source, int index, Element node,
104
					EventObject e) {
104
					EventObject e) {
105
				
105
				
106
				//TODO: appeler le mediateur
106
				//TODO: appeler le mediateur
107
				getIMediateur().ClicGalerieImage(index, node, e);
107
				getIMediateur().ClicGalerieImage(index, node, e);
108
				
108
				
109
			}
109
			}
110
 
110
 
111
 
111
 
112
			public void onSelectionChange(DataView view, Element[] selections) {
112
			public void onSelectionChange(DataView view, Element[] selections) {
113
				//TODO: appeler le mediateur
113
				//TODO: appeler le mediateur
114
				
114
				
115
			}
115
			}
116
			
116
			
117
		});
117
		});
118
	}
118
	}
119
	
119
	
120
	
120
	
121
	// instantiation paresseuse
121
	// instantiation paresseuse
122
	public void initialiser()
122
	public void initialiser()
123
	{
123
	{
124
		// Preparation de la dataview et du template		
124
		// Preparation de la dataview et du template		
125
		// le template va créer une div contenant une image
125
		// le template va créer une div contenant une image
126
		// pour chacune des photos
126
		// pour chacune des photos
127
		final XTemplate template = new XTemplate(
127
		final XTemplate template = new XTemplate(
128
				new String[]{
128
				new String[]{
129
						"<tpl for='.'>",
129
						"<tpl for='.'>",
130
						"<div class='thumb-wrap' id='{num_image}'>",
130
						"<div class='thumb-wrap' id='{num_image}'>",
131
						"<div class='thumb'><img src='{url_image}' title='{num_image}'></div>",
131
						"<div class='thumb'><img src='{url_image}' title='{num_image}'></div>",
132
						"<span>{nom}</span></div>", "</tpl>",
132
						"<span>{nom}</span></div>", "</tpl>",
133
						"<div class='x-clear'></div>"});
133
						"<div class='x-clear'></div>"});
134
		template.compile();
134
		template.compile();
135
 
135
 
136
		// la dataview affichera les images en accord avec le template
136
		// la dataview affichera les images en accord avec le template
137
		// cree precedemment
137
		// cree precedemment
138
		dView = new DataView("div.thumb-wrap") {
138
		dView = new DataView("div.thumb-wrap") {
139
			public void prepareData(Data data) {
139
			public void prepareData(Data data) {
140
				data.setProperty("shortName", Format.ellipsis(data
140
				data.setProperty("shortName", Format.ellipsis(data
141
						.getProperty("num_image"), 15));
141
						.getProperty("num_image"), 15));
142
			}
142
			}
143
		};
143
		};
144
		dView.setTpl(template);
144
		dView.setTpl(template);
145
		
145
		
146
		// parametre d'affichage de la dataview
146
		// parametre d'affichage de la dataview
147
		dView.setAutoHeight(true);
147
		dView.setAutoHeight(true);
148
		dView.setMultiSelect(true);
148
		dView.setMultiSelect(true);
149
		dView.setOverCls("x-view-over");
149
		dView.setOverCls("x-view-over");
150
		dView.setEmptyText("Aucune image à afficher");
150
		dView.setEmptyText("Aucune image à afficher");
151
		
151
		
152
		
152
		
153
		// creation du store
153
		// creation du store
154
		FieldDef defNumImage = new StringFieldDef("num_image");
154
		FieldDef defNumImage = new StringFieldDef("num_image");
155
		FieldDef defUrlImage = new StringFieldDef("url_image");
155
		FieldDef defUrlImage = new StringFieldDef("url_image");
156
		FieldDef[] defTab = {defNumImage,defUrlImage};
156
		FieldDef[] defTab = {defNumImage,defUrlImage};
157
		RecordDef rd = new RecordDef(defTab) ;
157
		RecordDef rd = new RecordDef(defTab) ;
158
		st = new Store(rd) ;
158
		st = new Store(rd) ;
159
		dView.setStore(st);
159
		dView.setStore(st);
160
		
160
		
161
		// ajouts de la gestion des evenements pour la dataview
161
		// ajouts de la gestion des evenements pour la dataview
162
		ajouterListenersDataView();
162
		ajouterListenersDataView();
163
		
163
		
164
		this.add(dView);	
164
		this.add(dView);	
165
		
165
		
166
		getIMediateur().ObtenirPhotoGalerie(this);
166
		getIMediateur().obtenirPhotoGalerie(this);
167
	}
167
	}
168
	
168
	
169
	
169
	
170
	
170
	
171
	public void rafraichir(Object nouvelleDonnees) {
171
	public void rafraichir(Object nouvelleDonnees) {
172
		
172
		
173
			Object[][] photoData = (Object[][])nouvelleDonnees ;
173
			Object[][] photoData = (Object[][])nouvelleDonnees ;
174
			final MemoryProxy dataProxy = new MemoryProxy(photoData);
174
			final MemoryProxy dataProxy = new MemoryProxy(photoData);
175
			final ArrayReader reader = new ArrayReader(new RecordDef(
175
			final ArrayReader reader = new ArrayReader(new RecordDef(
176
					new FieldDef[]{new StringFieldDef("num_image"),
176
					new FieldDef[]{new StringFieldDef("num_image"),
177
							new StringFieldDef("url_image")}));
177
							new StringFieldDef("url_image")}));
178
	
178
	
179
			final Store photoStore = new Store(dataProxy, reader);
179
			final Store photoStore = new Store(dataProxy, reader);
180
			photoStore.load();
180
			photoStore.load();
181
	
181
	
182
			st = photoStore;
182
			st = photoStore;
183
			dView.setStore(st);
183
			dView.setStore(st);
184
			dView.refresh();
184
			dView.refresh();
185
	}
185
	}
186
 
186
 
187
 
187
 
188
	public ImageMediateur getIMediateur() {
188
	public ImageMediateur getIMediateur() {
189
		return iMediateur;
189
		return iMediateur;
190
	}
190
	}
191
 
191
 
192
 
192
 
193
	public DataView getDView() {
193
	public DataView getDView() {
194
		return dView;
194
		return dView;
195
	}
195
	}
196
 
196
 
197
 
197
 
198
	public Store getSt() {
198
	public Store getSt() {
199
		return st;
199
		return st;
200
	}
200
	}
201
}
201
}