Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 36 | Rev 46 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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