Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 aperonnet 1
package org.tela_botanica.client.vues;
2
 
3
import org.tela_botanica.client.image.ImageMediateur;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
 
6
import com.google.gwt.user.client.ui.Label;
7
import com.gwtext.client.core.EventObject;
8
import com.gwtext.client.core.NameValuePair;
9
import com.gwtext.client.widgets.Button;
10
import com.gwtext.client.widgets.Panel;
11
import com.gwtext.client.widgets.TabPanel;
12
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
13
import com.gwtext.client.widgets.form.DateField;
14
import com.gwtext.client.widgets.form.TextArea;
15
import com.gwtext.client.widgets.form.TextField;
16
import com.gwtext.client.widgets.grid.GridPanel;
17
import com.gwtext.client.widgets.grid.GridView;
18
import com.gwtext.client.widgets.grid.PropertyGridPanel;
19
import com.gwtext.client.widgets.grid.event.GridCellListenerAdapter;
20
import com.gwtext.client.widgets.layout.VerticalLayout;
21
 
22
/**
23
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
24
 * @author aurelien
25
 *
26
 */
27
public class PanneauMetadonneesVue extends TabPanel implements Rafraichissable {
28
 
29
	/**
30
	 * Le médiateur associé à la vue
31
	 */
32
	private ImageMediateur imediateur = null ;
33
	/**
34
	 * Le panneau des Exifs
35
	 */
36
	private PropertyGridPanel ExifGrid = null ;
37
	/**
38
	 * Le panneau des Iptc
39
	 */
40
	private PropertyGridPanel IptcGrid = null ;
41
 
42
	/**
43
	 * La grille pour le panneau des Exifs
44
	 */
45
	private GridView gViewExif = null ;
46
	/**
47
	 * La grille pour le panneau de Iptc
48
	 */
49
	private GridView gViewIptc = null ;
50
 
51
	/**
52
	 * L'onglet des Exifs
53
	 */
54
	private Panel panneauExifGrid = null;
55
	/**
56
	 * L'onglet des Iptc
57
	 */
58
	private Panel panneauIptcGrid = null ;
59
	/**
60
	 * L'onglet des infos
61
	 */
62
	private Panel panneauInfoGrid = null ;
63
	/**
64
	 * L'onglet des mots clés
65
	 */
66
	private ArbreMotsClesVue panneauMotsCles = null ;
67
 
68
	/**
69
	 * Le champ commentaire
70
	 */
71
	private TextField commentaireGeneral = null ;
72
	/**
73
	 * Le champ date
74
	 */
75
	private DateField dateImage = null ;
76
	/**
77
	 * Le bouton de validation
78
	 */
79
	Button validerInfo = null ;
80
 
81
	/**
82
	 * Barre de notation
83
	 */
84
	BarreNotationVue noteVue = null ;
85
 
86
	/**
87
	 * Booleen d'instanciation
88
	 */
89
	boolean estInstancie = false ;
90
 
91
	/**
92
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
93
	 */
94
	@SuppressWarnings("unused")
95
	private PanneauMetadonneesVue()
96
	{
97
		super() ;
98
	}
99
 
100
	/**
101
	 * Constructeur avec argument
102
	 * @param im
103
	 */
104
	public PanneauMetadonneesVue(ImageMediateur im)
105
	{
106
		super() ;
107
 
108
		// on associe le médiateur
109
		imediateur = im ;
110
 
111
		// on crée et dispose les panneaux et les champs
112
		panneauExifGrid = new Panel("Exif") ;
113
		panneauIptcGrid = new Panel("Iptc") ;
114
		panneauInfoGrid = new Panel("info") ;
115
		panneauMotsCles = new ArbreMotsClesVue(im) ;
116
		panneauMotsCles.setHeight("500px") ;
117
 
118
 
119
		Panel sousPanneauInfosGenerales = new Panel("Infos Générales") ;
120
		sousPanneauInfosGenerales.setLayout(new VerticalLayout());
121
		sousPanneauInfosGenerales.setBorder(false) ;
122
		sousPanneauInfosGenerales.setHeight(200);
123
		sousPanneauInfosGenerales.setAutoWidth(true) ;
124
		sousPanneauInfosGenerales.setMargins(5) ;
125
		sousPanneauInfosGenerales.setPaddings(5) ;
126
		sousPanneauInfosGenerales.setCollapsible(true) ;
127
 
128
		Label labelComm = new Label("Commentaires :") ;
129
		labelComm.setHeight("20px") ;
130
		commentaireGeneral = new TextArea() ;
131
		commentaireGeneral.setWidth("90%") ;
132
		Label labelDate = new Label("Date :") ;
133
		Label labelNote = new Label("Note :") ;
134
 
135
		panneauMotsCles.setBorder(false) ;
136
 
137
		labelDate.setHeight("20px") ;
138
 
139
		dateImage = new DateField() ;
140
		dateImage.setAutoWidth(true) ;
141
		dateImage.setFormat("d/m/Y") ;
142
 
143
		validerInfo = new Button("OK") ;
144
 
145
		noteVue = new BarreNotationVue(im, 5) ;
146
 
147
		sousPanneauInfosGenerales.add(labelComm) ;
148
		sousPanneauInfosGenerales.add(commentaireGeneral) ;
149
		sousPanneauInfosGenerales.add(labelDate) ;
150
		sousPanneauInfosGenerales.add(dateImage) ;
151
		sousPanneauInfosGenerales.add(labelNote) ;
152
		sousPanneauInfosGenerales.add(noteVue) ;
153
		sousPanneauInfosGenerales.add(validerInfo) ;
154
		sousPanneauInfosGenerales.setAutoHeight(true);
155
		panneauMotsCles.setAutoHeight(true) ;
156
 
157
		panneauInfoGrid.setBorder(false);
158
		panneauInfoGrid.setAutoHeight(true);
159
 
160
 
161
		panneauInfoGrid.add(sousPanneauInfosGenerales) ;
162
		panneauInfoGrid.add(panneauMotsCles) ;
163
 
164
 
165
		this.add(panneauInfoGrid) ;
166
		this.add(panneauExifGrid) ;
167
		this.add(panneauIptcGrid) ;
168
 
169
		gViewExif = new GridView();
170
		gViewExif.setForceFit(true);
171
 
172
		ExifGrid = new PropertyGridPanel() ;
173
		ExifGrid.setId("meta_exif");
174
		ExifGrid.setView(gViewExif);
175
		ExifGrid.setNameText("Métadonnées Exif");
176
		ExifGrid.setAutoWidth(true);
177
		ExifGrid.setAutoHeight(true);
178
		ExifGrid.setSorted(false);
179
 
180
		gViewIptc = new GridView();
181
		gViewIptc.setForceFit(true);
182
 
183
		IptcGrid = new PropertyGridPanel() ;
184
		IptcGrid.setId("meta_iptc");
185
		IptcGrid.setView(gViewIptc);
186
 
187
		IptcGrid.setNameText("Métadonnées IPTC");
188
		IptcGrid.setAutoWidth(true);
189
		IptcGrid.setAutoHeight(true);
190
		IptcGrid.setSorted(false);
191
 
192
 
193
		panneauExifGrid.add(ExifGrid);
194
		panneauIptcGrid.add(IptcGrid);
195
 
196
		// on ajoute les listeners
197
		ajouterListeners() ;
198
 
199
 
200
		// on effectue le rendu
201
		this.doLayout(true) ;
202
 
203
	}
204
 
205
	private void ajouterListeners()
206
	{
207
		// on ajoute un écouteur
208
		validerInfo.addListener(new ButtonListenerAdapter() {
209
 
210
			// gestion du clic
211
 
212
			public void onClick(Button button, EventObject e) {
213
 
214
				button.focus() ;
215
				// lors du clic sur le bouton valider on met à jour les commentaires et la date
216
				getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ;
217
 
218
			}
219
		});
220
 
221
		// gestion des clics dans la grille
222
		ExifGrid.addGridCellListener(new GridCellListenerAdapter() {
223
 
224
			// lors d'un clic d'une cellule
225
 
226
			public void onCellClick(GridPanel grid, int rowIndex, int colIndex,
227
					EventObject e) {
228
 
229
				// on empeche l'édition
230
				e.stopEvent() ;
231
				ExifGrid.stopEditing() ;
232
 
233
			}
234
 
235
			// lors du double clic sur une cellule
236
 
237
			public void onCellDblClick(GridPanel grid, int rowIndex,
238
					int colIndex, EventObject e) {
239
 
240
				// on empêche l'édition
241
				e.stopEvent() ;
242
				ExifGrid.stopEditing() ;
243
 
244
			}
245
 
246
		}) ;
247
 
248
		IptcGrid.addGridCellListener(new GridCellListenerAdapter() {
249
 
250
			// lors d'un clic d'une cellule
251
 
252
			public void onCellClick(GridPanel grid, int rowIndex, int colIndex,
253
					EventObject e) {
254
				// on empeche l'édition
255
				e.stopEvent() ;
256
				ExifGrid.stopEditing() ;
257
 
258
			}
259
 
260
			// lors d'un double clic d'une cellule
261
 
262
			public void onCellDblClick(GridPanel grid, int rowIndex,
263
					int colIndex, EventObject e) {
264
				// on empeche l'édition
265
				e.stopEvent() ;
266
				ExifGrid.stopEditing() ;
267
 
268
			}
269
 
270
		}) ;
271
	}
272
 
273
	/**
274
	 * Desactive visuellement ce panneau
275
	 */
276
	public void desactiverPanneau()
277
	{
278
		this.setDisabled(true) ;
279
	}
280
 
281
	/**
282
	 * Active visuellement ce panneau
283
	 */
284
	public void activerPanneau()
285
	{
286
		this.setDisabled(false) ;
287
	}
288
 
289
	/**
290
	 * Accesseur pour le médiateur
291
	 * @return le médiateur associé à la vue
292
	 */
293
	public ImageMediateur getIMediateur()
294
	{
295
		return imediateur ;
296
	}
297
 
298
	/**
299
	 * Méthode héritée de l'interface rafraichissable
300
	 * @param nouvelleDonnees les nouvelles données
301
	 * @param repandreRafraichissement le booleen de notification de mise à jour
302
	 */
303
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
304
 
305
		// si on reçoit un tableau d'objets
306
		if(nouvelleDonnees instanceof Object[])
307
		{
308
			// extrait infos, exifs et iptc
309
			Object meta[] = (Object[])nouvelleDonnees ;
310
			String[][] exif = (String[][])meta[0] ;
311
			String[][] iptc = (String[][])meta[1] ;
312
			String[][] gen = (String[][])meta[2] ;
313
 
314
			NameValuePair[] exifSource = new NameValuePair[exif.length] ;
315
			NameValuePair[] iptcSource = new NameValuePair[iptc.length] ;
316
 
317
 
318
			int maxLength ;
319
			if(exif.length <= iptc.length)
320
			{
321
				maxLength = iptc.length ;
322
			}
323
			else
324
			{
325
				maxLength = exif.length ;
326
			}
327
 
328
			for(int i = 0; i < maxLength ; i++)
329
			{
330
				if(i < exif.length && !exif[i][0].equals("null"))
331
				{
332
					exifSource[i] = new NameValuePair(exif[i][0],exif[i][1]) ;
333
				}
334
 
335
				if(i < iptc.length && !iptc[i][0].equals("null"))
336
				{
337
					iptcSource[i] = new NameValuePair(iptc[i][0],iptc[i][1]) ;
338
				}
339
			}
340
 
341
			// on met à jour les champs avec la bonne valeur
342
			commentaireGeneral.setValue(gen[0][1]) ;
343
			dateImage.setRawValue(gen[1][1]) ;
344
 
345
			// et on met à jour les données pour l'affichage
346
			ExifGrid.setSource(exifSource);
347
			IptcGrid.setSource(iptcSource);
348
 
349
		}
350
	}
351
 
352
	/**
353
	 * Accesseur pour le panneau des mots clés
354
	 * @return the panneauMotsCles
355
	 */
356
	public ArbreMotsClesVue getPanneauMotsCles() {
357
		return panneauMotsCles;
358
	}
359
 
360
	public BarreNotationVue getNoteVue() {
361
		return noteVue ;
362
	}
363
}