| 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;
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
import com.google.gwt.core.client.JavaScriptObject;
|
|
|
9 |
import com.google.gwt.user.client.Element;
|
| 5 |
aperonnet |
10 |
import com.google.gwt.user.client.Event;
|
| 4 |
aperonnet |
11 |
import com.gwtext.client.core.EventObject;
|
|
|
12 |
import com.gwtext.client.core.XTemplate;
|
| 5 |
aperonnet |
13 |
import com.gwtext.client.data.ArrayReader;
|
| 4 |
aperonnet |
14 |
import com.gwtext.client.data.FieldDef;
|
| 5 |
aperonnet |
15 |
import com.gwtext.client.data.MemoryProxy;
|
| 4 |
aperonnet |
16 |
import com.gwtext.client.data.RecordDef;
|
|
|
17 |
import com.gwtext.client.data.Store;
|
|
|
18 |
import com.gwtext.client.data.StringFieldDef;
|
|
|
19 |
import com.gwtext.client.util.Format;
|
|
|
20 |
import com.gwtext.client.widgets.BoxComponent;
|
|
|
21 |
import com.gwtext.client.widgets.Component;
|
| 5 |
aperonnet |
22 |
import com.gwtext.client.widgets.Container;
|
| 4 |
aperonnet |
23 |
import com.gwtext.client.widgets.DataView;
|
| 5 |
aperonnet |
24 |
import com.gwtext.client.widgets.Observable;
|
| 4 |
aperonnet |
25 |
import com.gwtext.client.widgets.Panel;
|
|
|
26 |
import com.gwtext.client.widgets.DataView.Data;
|
| 5 |
aperonnet |
27 |
import com.gwtext.client.widgets.event.ContainerListener;
|
|
|
28 |
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
|
| 4 |
aperonnet |
29 |
import com.gwtext.client.widgets.event.DataViewListener;
|
|
|
30 |
import com.gwtext.client.widgets.event.DataViewListenerAdapter;
|
|
|
31 |
|
| 5 |
aperonnet |
32 |
public class GalerieImageVue extends Panel implements Rafraichissable, Observable {
|
| 4 |
aperonnet |
33 |
|
|
|
34 |
// instance du médiateur
|
|
|
35 |
private ImageMediateur iMediateur = null;
|
|
|
36 |
private DataView dView = null ;
|
|
|
37 |
private Store st = null ;
|
|
|
38 |
|
|
|
39 |
public GalerieImageVue(ImageMediateur im)
|
|
|
40 |
{
|
|
|
41 |
super("Galerie");
|
|
|
42 |
iMediateur = im ;
|
|
|
43 |
|
| 5 |
aperonnet |
44 |
this.addListener(new ContainerListenerAdapter() {
|
| 4 |
aperonnet |
45 |
|
| 5 |
aperonnet |
46 |
|
|
|
47 |
public void onHide(Component component) {
|
|
|
48 |
// TODO Auto-generated method stub
|
|
|
49 |
|
| 4 |
aperonnet |
50 |
}
|
| 5 |
aperonnet |
51 |
|
|
|
52 |
|
|
|
53 |
public void onRender(Component component) {
|
|
|
54 |
// TODO Auto-generated method stub
|
|
|
55 |
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
public void onShow(Component component) {
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
if(dView == null)
|
|
|
63 |
{
|
|
|
64 |
initialiser();
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
});
|
| 4 |
aperonnet |
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
|
| 5 |
aperonnet |
73 |
public void ajouterListenersDataView()
|
| 4 |
aperonnet |
74 |
{
|
| 5 |
aperonnet |
75 |
|
| 4 |
aperonnet |
76 |
// ajout de listeners pour la gestion de la selection
|
|
|
77 |
// dans la galerie
|
|
|
78 |
dView.addListener(new DataViewListenerAdapter() {
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
public void onClick(DataView source, int index, Element node,
|
|
|
83 |
EventObject e) {
|
|
|
84 |
|
| 5 |
aperonnet |
85 |
getIMediateur().ClicGalerieImage(index, node, e);
|
|
|
86 |
|
| 4 |
aperonnet |
87 |
}
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
public void onContainerClick(DataView source, EventObject e) {
|
|
|
91 |
//TODO: appeler le mediateur
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
public void onContextMenu(DataView source, int index, Element node,
|
|
|
97 |
EventObject e) {
|
|
|
98 |
//TODO: appeler le mediateur
|
|
|
99 |
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
public void onDblClick(DataView source, int index, Element node,
|
|
|
104 |
EventObject e) {
|
| 5 |
aperonnet |
105 |
|
| 4 |
aperonnet |
106 |
//TODO: appeler le mediateur
|
| 5 |
aperonnet |
107 |
getIMediateur().ClicGalerieImage(index, node, e);
|
| 4 |
aperonnet |
108 |
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
public void onSelectionChange(DataView view, Element[] selections) {
|
|
|
113 |
//TODO: appeler le mediateur
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
});
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
|
| 5 |
aperonnet |
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 |
}
|
| 4 |
aperonnet |
168 |
|
| 5 |
aperonnet |
169 |
|
|
|
170 |
|
| 4 |
aperonnet |
171 |
public void rafraichir(Object nouvelleDonnees) {
|
|
|
172 |
|
| 5 |
aperonnet |
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();
|
| 4 |
aperonnet |
185 |
}
|
| 5 |
aperonnet |
186 |
|
|
|
187 |
|
|
|
188 |
public ImageMediateur getIMediateur() {
|
|
|
189 |
return iMediateur;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
public DataView getDView() {
|
|
|
194 |
return dView;
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
public Store getSt() {
|
|
|
199 |
return st;
|
|
|
200 |
}
|
| 4 |
aperonnet |
201 |
}
|