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