Subversion Repositories eFlore/Archives.cel-v2

Rev

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

Rev 27 Rev 28
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
import java.util.Iterator;
3
import java.util.Iterator;
4
 
4
 
5
import org.tela_botanica.client.image.ImageMediateur;
5
import org.tela_botanica.client.image.ImageMediateur;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
7
import org.tela_botanica.client.interfaces.VueListable;
7
import org.tela_botanica.client.interfaces.VueListable;
8
import org.tela_botanica.client.modeles.ImageCarnet;
8
import org.tela_botanica.client.modeles.ImageCarnet;
9
import org.tela_botanica.client.modeles.ListeImageCarnet;
9
import org.tela_botanica.client.modeles.ListeImageCarnet;
10
 
10
 
11
import com.google.gwt.core.client.JavaScriptObject;
11
import com.google.gwt.core.client.JavaScriptObject;
12
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.Window;
13
import com.gwtext.client.core.EventObject;
13
import com.gwtext.client.core.EventObject;
14
import com.gwtext.client.data.ArrayReader;
14
import com.gwtext.client.data.ArrayReader;
15
import com.gwtext.client.data.FieldDef;
15
import com.gwtext.client.data.FieldDef;
16
import com.gwtext.client.data.IntegerFieldDef;
16
import com.gwtext.client.data.IntegerFieldDef;
17
import com.gwtext.client.data.MemoryProxy;
17
import com.gwtext.client.data.MemoryProxy;
18
import com.gwtext.client.data.Record;
18
import com.gwtext.client.data.Record;
19
import com.gwtext.client.data.RecordDef;
19
import com.gwtext.client.data.RecordDef;
20
import com.gwtext.client.data.Store;
20
import com.gwtext.client.data.Store;
21
import com.gwtext.client.data.StoreMgr;
21
import com.gwtext.client.data.StoreMgr;
22
import com.gwtext.client.data.StringFieldDef;
22
import com.gwtext.client.data.StringFieldDef;
23
import com.gwtext.client.widgets.BoxComponent;
23
import com.gwtext.client.widgets.BoxComponent;
24
import com.gwtext.client.widgets.Component;
24
import com.gwtext.client.widgets.Component;
25
import com.gwtext.client.widgets.Container;
25
import com.gwtext.client.widgets.Container;
26
import com.gwtext.client.widgets.Panel;
26
import com.gwtext.client.widgets.Panel;
27
import com.gwtext.client.widgets.event.ComponentListenerAdapter;
27
import com.gwtext.client.widgets.event.ComponentListenerAdapter;
28
import com.gwtext.client.widgets.event.ContainerListener;
28
import com.gwtext.client.widgets.event.ContainerListener;
29
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
29
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
30
import com.gwtext.client.widgets.event.PanelListener;
30
import com.gwtext.client.widgets.event.PanelListener;
31
import com.gwtext.client.widgets.event.PanelListenerAdapter;
31
import com.gwtext.client.widgets.event.PanelListenerAdapter;
32
import com.gwtext.client.widgets.grid.CellMetadata;
32
import com.gwtext.client.widgets.grid.CellMetadata;
33
import com.gwtext.client.widgets.grid.ColumnConfig;
33
import com.gwtext.client.widgets.grid.ColumnConfig;
34
import com.gwtext.client.widgets.grid.ColumnModel;
34
import com.gwtext.client.widgets.grid.ColumnModel;
35
import com.gwtext.client.widgets.grid.GridPanel;
35
import com.gwtext.client.widgets.grid.GridPanel;
36
import com.gwtext.client.widgets.grid.GridView;
36
import com.gwtext.client.widgets.grid.GridView;
37
import com.gwtext.client.widgets.grid.Renderer;
37
import com.gwtext.client.widgets.grid.Renderer;
38
import com.gwtext.client.widgets.grid.RowSelectionModel;
38
import com.gwtext.client.widgets.grid.RowSelectionModel;
39
import com.gwtext.client.widgets.grid.event.GridCellListener;
39
import com.gwtext.client.widgets.grid.event.GridCellListener;
40
import com.gwtext.client.widgets.grid.event.GridListener;
40
import com.gwtext.client.widgets.grid.event.GridListener;
41
import com.gwtext.client.widgets.grid.event.GridRowListener;
41
import com.gwtext.client.widgets.grid.event.GridRowListener;
42
import com.gwtext.client.widgets.grid.event.RowSelectionListener;
42
import com.gwtext.client.widgets.grid.event.RowSelectionListener;
43
import com.gwtext.client.widgets.grid.event.RowSelectionListenerAdapter;
43
import com.gwtext.client.widgets.grid.event.RowSelectionListenerAdapter;
44
import com.gwtext.client.widgets.layout.AnchorLayout;
44
import com.gwtext.client.widgets.layout.AnchorLayout;
45
import com.gwtext.client.widgets.layout.FitLayout;
45
import com.gwtext.client.widgets.layout.FitLayout;
46
import com.gwtextux.client.data.BufferedStore;
46
import com.gwtextux.client.data.BufferedStore;
47
 
47
 
48
/**
48
/**
49
 * Liste d'image composée de miniatures et d'information sur l'image
49
 * Liste d'image composée de miniatures et d'information sur l'image
50
 * 
50
 * 
51
 * @author aurelien
51
 * @author aurelien
52
 */
52
 */
53
public class ListeImageVue extends GridPanel implements Rafraichissable,
53
public class ListeImageVue extends GridPanel implements Rafraichissable,
54
		VueListable {
54
		VueListable {
55
 
55
 
56
	// instance du médiateur
56
	// instance du médiateur
57
	private ImageMediateur	iMediateur		= null;
57
	private ImageMediateur	iMediateur		= null;
58
 
58
 
59
	private ColumnConfig	numImage;
59
	private ColumnConfig	numImage;
60
	private ColumnConfig	urlImage;
60
	private ColumnConfig	urlImage;
61
	private ColumnConfig	lieImage;
61
	private ColumnConfig	lieImage;
62
	private ColumnConfig	datImage;
62
	private ColumnConfig	datImage;
63
	private ColumnConfig	appImage;
63
	private ColumnConfig	appImage;
64
	private ColumnModel		modeleColonnes;
64
	private ColumnModel		modeleColonnes;
65
 
65
 
66
	private boolean			estInstancie	= false;
66
	private boolean			estInstancie	= false;
67
 
67
 
68
	// données locales
68
	// données locales
69
	// store qui gère les données de la liste d'images
69
	// store qui gère les données de la liste d'images
70
	private Store			st				= null;
70
	private Store			st				= null;
71
	private ColumnConfig	cl				= null;
71
	private ColumnConfig	cl				= null;
72
 
72
 
73
	public ListeImageVue(ImageMediateur im) {
73
	public ListeImageVue(ImageMediateur im) {
74
 
74
 
75
		super();
75
		super();
76
 
76
 
77
		this.setId("listeImageGrid");
77
		this.setId("listeImageGrid");
78
 
78
 
79
		this.iMediateur = im;
79
		this.iMediateur = im;
80
 
80
 
81
		numImage = new ColumnConfig("numéro", "num_image", 100, true);
81
		numImage = new ColumnConfig("numéro", "num_image", 100, true);
82
		datImage = new ColumnConfig("date", "dat_image", 120, true);
82
		datImage = new ColumnConfig("date", "dat_image", 120, true);
83
		lieImage = new ColumnConfig("lieu", "lie_image", 120, true);
83
		lieImage = new ColumnConfig("lieu", "lie_image", 120, true);
84
		appImage = new ColumnConfig("appareil", "app_image", 200, true);
84
		appImage = new ColumnConfig("appareil", "app_image", 200, true);
85
		urlImage = new ColumnConfig("Image", "url_image_S", 200, true,
85
		urlImage = new ColumnConfig("Image", "url_image_S", 200, true,
86
				new Renderer() {
86
				new Renderer() {
87
 
87
 
88
					public String render(Object value,
88
					public String render(Object value,
89
							CellMetadata cellMetadata, Record record,
89
							CellMetadata cellMetadata, Record record,
90
							int rowIndex, int colNum, Store store) {
90
							int rowIndex, int colNum, Store store) {
91
 
91
 
92
						String ImgUrl = record.getAsString("url_image_S");
92
						String ImgUrl = record.getAsString("url_image_S");
93
						String ImgNum = record.getAsString("num_image");
93
						String ImgNum = record.getAsString("num_image");
94
						return "<div class=\"img-list\"> <img src=\"" + ImgUrl
94
						return "<div class=\"img-list\"> <img src=\"" + ImgUrl
95
								+ "\" title='" + ImgNum + "'> </div>";
95
								+ "\" title='" + ImgNum + "'> </div>";
96
					}
96
					}
97
 
97
 
98
				});
98
				});
99
 
99
 
100
		ColumnConfig[] cm = { numImage, datImage, lieImage, appImage, urlImage };
100
		ColumnConfig[] cm = { numImage, datImage, lieImage, appImage, urlImage };
101
		modeleColonnes = new ColumnModel(cm);
101
		modeleColonnes = new ColumnModel(cm);
102
		this.setColumnModel(modeleColonnes);
102
		this.setColumnModel(modeleColonnes);
103
		this.setAutoScroll(true);
103
		this.setAutoScroll(true);
104
		this.setAutoWidth(true);
104
		this.setAutoWidth(true);
105
 
105
 
106
		// creation du store
106
		// creation du store
107
		FieldDef defNumImage = new IntegerFieldDef("num_image");
107
		FieldDef defNumImage = new IntegerFieldDef("num_image");
108
		FieldDef defDatImage = new StringFieldDef("dat_image");
108
		FieldDef defDatImage = new StringFieldDef("dat_image");
109
		FieldDef defLieImage = new StringFieldDef("lie_image");
109
		FieldDef defLieImage = new StringFieldDef("lie_image");
110
		FieldDef defAppImage = new StringFieldDef("app_image");
110
		FieldDef defAppImage = new StringFieldDef("app_image");
111
		FieldDef defUrlImageS = new StringFieldDef("url_image_S");
111
		FieldDef defUrlImageS = new StringFieldDef("url_image_S");
112
		FieldDef defUrlImageM = new StringFieldDef("url_image_M");
112
		FieldDef defUrlImageM = new StringFieldDef("url_image_M");
113
		FieldDef defUrlImage = new StringFieldDef("url_image");
113
		FieldDef defUrlImage = new StringFieldDef("url_image");
114
		FieldDef[] defTab = { defNumImage, defDatImage, defLieImage,
114
		FieldDef[] defTab = { defNumImage, defDatImage, defLieImage,
115
				defAppImage, defUrlImageS, defUrlImageM, defUrlImage };
115
				defAppImage, defUrlImageS, defUrlImageM, defUrlImage };
116
		RecordDef rd = new RecordDef(defTab);
116
		RecordDef rd = new RecordDef(defTab);
117
		st = new Store(rd);
117
		st = new Store(rd);
118
		this.setStore(st);
118
		this.setStore(st);
119
		this.getView().setAutoFill(true);
119
		this.getView().setAutoFill(true);
120
 
120
 
121
		// this.setLoadMask(true) ;
121
		// this.setLoadMask(true) ;
122
		this.setLoadMask("chargement");
122
		this.setLoadMask("chargement");
123
 
123
 
124
		ajouterListeners();
124
		ajouterListeners();
125
 
125
 
126
	}
126
	}
127
 
127
 
128
	public void ajouterListeners() {
128
	public void ajouterListeners() {
129
		this.addListener(new ContainerListenerAdapter() {
129
		this.addListener(new ContainerListenerAdapter() {
130
 
130
 
131
			public void onHide(Component component) {
131
			public void onHide(Component component) {
132
 
132
 
133
			}
133
			}
134
 
134
 
135
			public void onRender(Component component) {
135
			public void onRender(Component component) {
136
 
136
 
137
				if (!isEstInstancie()) {
137
				if (!isEstInstancie()) {
138
					setEstInstancie(true);
138
					setEstInstancie(true);
139
					getIMediateur().synchroniserSelection("galerie");
139
					getIMediateur().synchroniserSelection("galerie");
140
				}
140
				}
141
			}
141
			}
142
 
142
 
143
			public void onShow(Component component) {
143
			public void onShow(Component component) {
144
 
144
 
145
			}
145
			}
146
 
146
 
147
		});
147
		});
148
 
148
 
149
		this.addGridRowListener(new GridRowListener() {
149
		this.addGridRowListener(new GridRowListener() {
150
 
150
 
151
			public void onRowClick(GridPanel grid, int rowIndex, EventObject e) {
151
			public void onRowClick(GridPanel grid, int rowIndex, EventObject e) {
152
 
152
 
153
				getIMediateur().clicListeImage(rowIndex);
153
				getIMediateur().clicListeImage(rowIndex);
154
			}
154
			}
155
 
155
 
156
			public void onRowContextMenu(GridPanel grid, int rowIndex,
156
			public void onRowContextMenu(GridPanel grid, int rowIndex,
157
					EventObject e) {
157
					EventObject e) {
-
 
158
 
158
 
159
				e.stopEvent() ;
159
				getIMediateur().montrerContextMenu(e);
160
				getIMediateur().montrerContextMenu(e);
160
			}
161
			}
161
 
162
 
162
			public void onRowDblClick(GridPanel grid, int rowIndex,
163
			public void onRowDblClick(GridPanel grid, int rowIndex,
163
					EventObject e) {
164
					EventObject e) {
164
 
165
 
165
				getIMediateur().doubleClicListeImage(rowIndex);
166
				getIMediateur().doubleClicListeImage(rowIndex);
166
			}
167
			}
167
		});
168
		});
168
 
169
 
169
		this.getSelectionModel().addListener(new RowSelectionListenerAdapter() {
170
		this.getSelectionModel().addListener(new RowSelectionListenerAdapter() {
170
 
171
 
171
			public void onSelectionChange(RowSelectionModel sm) {
172
			public void onSelectionChange(RowSelectionModel sm) {
172
 
173
 
173
				if (sm.getCount() <= 0) {
174
				if (sm.getCount() <= 0) {
174
					getIMediateur().aucuneSelection();
175
					getIMediateur().aucuneSelection();
175
				} else {
176
				} else {
176
					getIMediateur().selection();
177
					getIMediateur().selection();
177
					getIMediateur().synchroniserSelection("liste");
178
					getIMediateur().synchroniserSelection("liste");
178
				}
179
				}
179
			}
180
			}
180
		});
181
		});
181
	}
182
	}
182
 
183
 
183
	public ColumnConfig getCl() {
184
	public ColumnConfig getCl() {
184
		return cl;
185
		return cl;
185
	}
186
	}
186
 
187
 
187
	public String[] getIdSelectionnees() {
188
	public String[] getIdSelectionnees() {
188
		Record[] selection = this.getSelectionModel().getSelections();
189
		Record[] selection = this.getSelectionModel().getSelections();
189
		int taille = selection.length;
190
		int taille = selection.length;
190
		String id_selection[] = new String[taille];
191
		String id_selection[] = new String[taille];
191
 
192
 
192
		for (int i = 0; i < selection.length; i++) {
193
		for (int i = 0; i < selection.length; i++) {
193
 
194
 
194
			id_selection[i] = selection[i].getAsString("num_image");
195
			id_selection[i] = selection[i].getAsString("num_image");
195
		}
196
		}
196
 
197
 
197
		return id_selection;
198
		return id_selection;
198
	}
199
	}
199
 
200
 
200
	public ImageMediateur getIMediateur() {
201
	public ImageMediateur getIMediateur() {
201
		return iMediateur;
202
		return iMediateur;
202
	}
203
	}
203
 
204
 
204
	public ColumnModel getModeleColonnes() {
205
	public ColumnModel getModeleColonnes() {
205
		return modeleColonnes;
206
		return modeleColonnes;
206
	}
207
	}
207
 
208
 
208
	public ColumnConfig getNumImage() {
209
	public ColumnConfig getNumImage() {
209
		return numImage;
210
		return numImage;
210
	}
211
	}
211
 
212
 
212
	public Store getSt() {
213
	public Store getSt() {
213
		return st;
214
		return st;
214
	}
215
	}
215
 
216
 
216
	public ColumnConfig getUrlImage() {
217
	public ColumnConfig getUrlImage() {
217
		return urlImage;
218
		return urlImage;
218
	}
219
	}
219
 
220
 
220
	/**
221
	/**
221
	 * @return the estInstancie
222
	 * @return the estInstancie
222
	 */
223
	 */
223
	public boolean isEstInstancie() {
224
	public boolean isEstInstancie() {
224
		return estInstancie;
225
		return estInstancie;
225
	}
226
	}
226
 
227
 
227
	public void rafraichir(Object nouvelleDonnees,
228
	public void rafraichir(Object nouvelleDonnees,
228
			boolean repandreRafraichissement) {
229
			boolean repandreRafraichissement) {
229
 
230
 
230
		if (nouvelleDonnees instanceof Store) {
231
		if (nouvelleDonnees instanceof Store) {
231
 
232
 
232
			st = (Store) nouvelleDonnees;
233
			st = (Store) nouvelleDonnees;
233
			st.load();
234
			st.load();
234
			this.reconfigure(st, this.getColumnModel());
235
			this.reconfigure(st, this.getColumnModel());
235
		}
236
		}
236
 
237
 
237
		if (repandreRafraichissement) {
238
		if (repandreRafraichissement) {
238
			getIMediateur().synchroniserDonneesZoomListeGalerie(
239
			getIMediateur().synchroniserDonneesZoomListeGalerie(
239
					nouvelleDonnees, this);
240
					nouvelleDonnees, this);
240
		}
241
		}
241
	}
242
	}
242
 
243
 
243
	public void selectionnerEnregistrements(Record[] sel) {
244
	public void selectionnerEnregistrements(Record[] sel) {
244
 
245
 
245
		if (isEstInstancie()) {
246
		if (isEstInstancie()) {
246
			getSelectionModel().clearSelections();
247
			getSelectionModel().clearSelections();
247
			getSelectionModel().selectRecords(sel);
248
			getSelectionModel().selectRecords(sel);
248
		}
249
		}
249
	}
250
	}
250
 
251
 
251
	/**
252
	/**
252
	 * @param estInstancie
253
	 * @param estInstancie
253
	 *            the estInstancie to set
254
	 *            the estInstancie to set
254
	 */
255
	 */
255
	public void setEstInstancie(boolean estInstancie) {
256
	public void setEstInstancie(boolean estInstancie) {
256
		this.estInstancie = estInstancie;
257
		this.estInstancie = estInstancie;
257
	}
258
	}
258
 
259
 
259
	/**
260
	/**
260
	 * @param mediateur
261
	 * @param mediateur
261
	 *            the iMediateur to set
262
	 *            the iMediateur to set
262
	 */
263
	 */
263
	public void setIMediateur(ImageMediateur mediateur) {
264
	public void setIMediateur(ImageMediateur mediateur) {
264
		iMediateur = mediateur;
265
		iMediateur = mediateur;
265
	}
266
	}
266
 
267
 
267
}
268
}