Subversion Repositories eFlore/Archives.cel-v2

Rev

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

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