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