Subversion Repositories eFlore/Applications.cel

Rev

Rev 135 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 135 Rev 155
Line 1... Line 1...
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
Line 2... Line 2...
2
 
2
 
3
import org.tela_botanica.client.image.ImageMediateur;
3
import org.tela_botanica.client.image.ImageMediateur;
4
import org.tela_botanica.client.interfaces.Filtrable;
4
import org.tela_botanica.client.interfaces.Filtrable;
-
 
5
import org.tela_botanica.client.interfaces.Rafraichissable;
Line -... Line 6...
-
 
6
import org.tela_botanica.client.observation.ObservationMediateur;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
7
 
6
 
8
import com.google.gwt.core.client.JavaScriptObject;
-
 
9
import com.google.gwt.user.client.Window;
7
import com.google.gwt.user.client.Window;
10
import com.google.gwt.user.client.ui.Label;
8
import com.google.gwt.user.client.ui.Label;
11
import com.gwtext.client.core.EventObject;
9
import com.gwtext.client.data.Node;
12
import com.gwtext.client.data.Node;
-
 
13
import com.gwtext.client.data.NodeTraversalCallback;
10
import com.gwtext.client.data.NodeTraversalCallback;
14
import com.gwtext.client.data.Tree;
11
import com.gwtext.client.data.Tree;
15
import com.gwtext.client.widgets.Button;
12
import com.gwtext.client.widgets.Component;
16
import com.gwtext.client.widgets.Component;
-
 
17
import com.gwtext.client.widgets.Container;
-
 
18
import com.gwtext.client.widgets.Panel;
13
import com.gwtext.client.widgets.Container;
19
import com.gwtext.client.widgets.event.ButtonListener;
14
import com.gwtext.client.widgets.Panel;
20
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
15
import com.gwtext.client.widgets.event.ContainerListener;
21
import com.gwtext.client.widgets.event.ContainerListener;
-
 
22
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
-
 
23
import com.gwtext.client.widgets.event.PanelListenerAdapter;
-
 
24
import com.gwtext.client.widgets.layout.RowLayout;
16
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
25
import com.gwtext.client.widgets.layout.RowLayoutData;
17
import com.gwtext.client.widgets.event.PanelListenerAdapter;
26
import com.gwtext.client.widgets.menu.Menu;
-
 
27
import com.gwtext.client.widgets.tree.TreeNode;
-
 
28
import com.gwtext.client.widgets.tree.TreePanel;
Line 18... Line 29...
18
import com.gwtext.client.widgets.tree.TreeNode;
29
import com.gwtext.client.widgets.tree.event.TreeNodeListener;
19
import com.gwtext.client.widgets.tree.TreePanel;
30
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter;
20
 
31
 
21
/**
32
/**
Line 30... Line 41...
30
 
41
 
31
	/**
42
	/**
32
	 * Le médiateur associé à la vue
43
	 * Le médiateur associé à la vue
33
	 */
44
	 */
-
 
45
	private ImageMediateur iMediateur = null;
-
 
46
	
-
 
47
	/**
-
 
48
	 * Le médiateur associé à la vue
-
 
49
	 */
-
 
50
	private ObservationMediateur oMediateur = null;
34
	private ImageMediateur iMediateur = null;
51
	
35
	/**
52
	/**
36
	 * Les mots clés en cours
53
	 * Les mots clés en cours
37
	 */
54
	 */
Line 38... Line 55...
38
	private String motsClesEncours = "";
55
	private String motsClesEncours = "";
39
 
56
 
40
	/**
57
	/**
41
	 * Le treepanel qui affiche l'arbre
58
	 * Le treepanel qui affiche l'arbre
Line 42... Line 59...
42
	 */
59
	 */
43
	private TreePanel arbreMotsCles = null;
60
	private static TreePanel arbreMotsCles = null;
44
 
61
 
45
	/**
62
	/**
-
 
63
	 * booléen d'initialisation
-
 
64
	 */
Line 46... Line 65...
46
	 * booléen d'initialisation
65
	private boolean estInstancie = false;
47
	 */
66
	
48
	private boolean estInstancie = false;
67
	private boolean arbreInitialise = false;
49
 
68
 
-
 
69
	/**
-
 
70
	 * booléen d'etat
-
 
71
	 */
-
 
72
	private boolean filtreModifie = false;
-
 
73
	
-
 
74
	/**
-
 
75
	 * prefixe pour générer des ids adaptées
-
 
76
	 */
-
 
77
	private String prefixe = "_filtre" ;
Line 50... Line 78...
50
	/**
78
	
51
	 * booléen d'etat
79
	private final String prefixeImg = "_images" ;
52
	 */
80
	
53
	private boolean filtreModifie = false;
81
	private final String prefixeObs = "_obs" ;
Line 68... Line 96...
68
	 */
96
	 */
69
	public ArbreMotsClesFiltreVue(ImageMediateur im) {
97
	public ArbreMotsClesFiltreVue(ImageMediateur im) {
Line 70... Line 98...
70
 
98
 
71
		// on crée le panel
99
		// on crée le panel
72
		super();
-
 
73
		// this.setLayout(new VerticalLayout());
100
		super();
-
 
101
		iMediateur = im;
-
 
102
		this.prefixe += prefixeImg;
-
 
103
		Label labelRecherche = new Label("Mots clés :");
-
 
104
		add(labelRecherche);
-
 
105
		initialiserPanel();
-
 
106
	}
-
 
107
	
-
 
108
	/**
-
 
109
	 * Constructeur avec paramètres
-
 
110
	 * 
-
 
111
	 * @param im
-
 
112
	 *            le médiateur à associer
-
 
113
	 */
-
 
114
	public ArbreMotsClesFiltreVue(ObservationMediateur om) {
-
 
115
 
-
 
116
		// on crée le panel
-
 
117
		super();
-
 
118
		oMediateur = om;
-
 
119
		this.prefixe += prefixeObs;
-
 
120
		initialiserPanel();
-
 
121
		
Line -... Line 122...
-
 
122
		this.setLayout(new RowLayout());
-
 
123
 
-
 
124
	}
74
		iMediateur = im;
125
	
75
 
-
 
76
		// on crée le conteneur de l'arbre
126
	public void initialiserPanel() {
77
		Label labelRecherche = new Label("Mots clés :");
127
		// on crée le conteneur de l'arbre
Line 78... Line 128...
78
		arbreMotsCles = new TreePanel();
128
		arbreMotsCles = new TreePanel();
79
		arbreMotsCles.setId("x-view-tree-filter");
129
		arbreMotsCles.setId("x-view-tree-filter"+prefixe);
80
 
130
 
81
		// on crée une racine pour l'arbre
131
		// on crée une racine pour l'arbre
82
		TreeNode root = new TreeNode("Tags");
132
		TreeNode root = new TreeNode("Tags");
-
 
133
		root.setId("racine"+prefixe);
-
 
134
		String[] usObject = { "Mots clés", "racine" };
-
 
135
		root.setUserObject(usObject);
83
		root.setId("racine_filtre");
136
		
Line -... Line 137...
-
 
137
		root.setExpandable(true);
-
 
138
		
-
 
139
		arbreMotsCles.setRootNode(root);
-
 
140
		
-
 
141
		arbreMotsCles.getRootNode().addListener(new TreeNodeListenerAdapter() {
-
 
142
 
-
 
143
			public void onClick(Node node, EventObject e) {
-
 
144
				if(!arbreInitialise) {
-
 
145
					expand();
-
 
146
				}
-
 
147
			}
-
 
148
 
-
 
149
			public void onExpand(Node node) {
-
 
150
				if(!arbreInitialise) {
-
 
151
					obtenirArbreMotsCles();
-
 
152
					arbreInitialise = true;
-
 
153
				}
84
		String[] usObject = { "Mots clés", "racine_filtre" };
154
			}
Line 85... Line 155...
85
		root.setUserObject(usObject);
155
 
86
		arbreMotsCles.setRootNode(root);
156
		});
87
		
157
		
Line 88... Line -...
88
		this.setPaddings(5);
-
 
89
 
-
 
90
		this.setBorder(false);
158
		this.setPaddings(5);
91
		this.setCollapsible(true);
159
 
92
		this.setAutoWidth(true);
160
		this.setBorder(false);
93
 
161
		this.setCollapsible(true);
Line 113... Line 181...
113
				arbreMotsCles.setEnableDD(false);
181
				arbreMotsCles.setEnableDD(false);
114
				arbreMotsCles.setAutoWidth(false);
182
				arbreMotsCles.setAutoWidth(false);
115
				arbreMotsCles.setAutoScroll(true);
183
				arbreMotsCles.setAutoScroll(true);
116
				arbreMotsCles.setBorder(false);
184
				arbreMotsCles.setBorder(false);
Line 117... Line -...
117
 
-
 
118
				if(estInstancie)
-
 
119
				{
-
 
120
					// on crée une racine pour l'arbre
-
 
121
					TreeNode root = new TreeNode("Tags");
-
 
122
					root.setId("racine_filtre");
-
 
123
					String[] usObject = { "Mots clés", "racine_filtre" };
-
 
124
					root.setUserObject(usObject);
-
 
125
					arbreMotsCles.setRootNode(root);
-
 
126
				}
-
 
127
					
-
 
128
				arbreMotsCles.setRootVisible(true);
-
 
129
				arbreMotsCles.setBorder(false);
-
 
130
 
185
 
131
				// on met en forme le layout
186
				// on met en forme le layout
-
 
187
				((Panel) component).add(arbreMotsCles,new RowLayoutData("80%"));
-
 
188
				
-
 
189
				if(iMediateur == null) {
-
 
190
					Panel p = new Panel();
-
 
191
					p.setBorder(false);
-
 
192
					Button valider = new Button("Rechercher") ; 
-
 
193
					valider.addListener(new ButtonListenerAdapter() {
-
 
194
 
-
 
195
						public void onClick(Button button, EventObject e) {
-
 
196
							getOMediateur().obtenirNombreObservation();
-
 
197
						}
-
 
198
						
-
 
199
					});
-
 
200
					p.add(valider,new RowLayoutData());
-
 
201
					add(p);
Line 132... Line 202...
132
				((Panel) component).add(arbreMotsCles);
202
				}
133
 
203
 
134
				// on ajoute les listeners d'évenements
-
 
135
				ajouterListeners();
-
 
136
 
204
				// on ajoute les listeners d'évenements
137
				// enfin on considère le composant comme instancié
-
 
138
				estInstancie = true;
205
				ajouterListeners();
139
 
206
				//obtenirArbreMotsCles();
140
			}
207
			}
141
 
208
			
Line 142... Line 209...
142
		});
209
		});
143
	}
210
	}
Line 156... Line 223...
156
			boolean repandreRaffraichissement) {
223
			boolean repandreRaffraichissement) {
Line 157... Line 224...
157
 
224
 
158
		// si on a reçu un arbre
225
		// si on a reçu un arbre
159
		if (nouvelleDonnees instanceof Tree) {
226
		if (nouvelleDonnees instanceof Tree) {
160
			Tree nouvelArbre = (Tree) nouvelleDonnees;
227
			Tree nouvelArbre = (Tree) nouvelleDonnees;
161
 
228
			
162
			// on vide tous les noeuds de l'ancien arbre
229
			// on vide tous les noeuds de l'ancien arbre
163
			Node[] rootChild = arbreMotsCles.getRootNode().getChildNodes();
230
			Node[] rootChild = arbreMotsCles.getRootNode().getChildNodes();
Line 164... Line 231...
164
			for (int i = 0; i < rootChild.length; i++) {
231
			for (int i = 0; i < rootChild.length; i++) {
Line 174... Line 241...
174
			if (!estInstancie) {
241
			if (!estInstancie) {
175
				// on signale que oui
242
				// on signale que oui
176
				estInstancie = true;
243
				estInstancie = true;
177
			}
244
			}
Line -... Line 245...
-
 
245
			
-
 
246
			if(!arbreInitialise) {
-
 
247
				arbreInitialise = true;
-
 
248
			}
178
			
249
			
Line 179... Line 250...
179
			arbreMotsCles.setRootNode(arbreMotsCles.getRootNode());
250
			arbreMotsCles.setRootNode(arbreMotsCles.getRootNode());
180
 
251
 
181
			// l'état du filtre est réinitialisé
252
			// l'état du filtre est réinitialisé
182
			filtreModifie = false;
253
			filtreModifie = false;
Line 183... Line 254...
183
			show() ;
254
			doLayout() ;
184
		}
255
		}
Line 185... Line 256...
185
 
256
 
186
		if (nouvelleDonnees instanceof TreeNode) {
257
		if (nouvelleDonnees instanceof TreeNode) {
187
			TreeNode nd = (TreeNode) nouvelleDonnees;
258
			TreeNode nd = (TreeNode) nouvelleDonnees;
188
 
259
 
189
			// si le noeud n'existe pas déjà c'est un ajout
260
			// si le noeud n'existe pas déjà c'est un ajout
190
			if (arbreMotsCles.getTree().getNodeById(nd.getId() + "_filtre") == null) {
261
			if (arbreMotsCles.getTree().getNodeById(nd.getId() +prefixe) == null) {
191
				// donc on ne fait rien de spécial
262
				// donc on ne fait rien de spécial
192
			}
263
			}
193
			// si le noeud existe déjà c'est un déplacement
264
			// si le noeud existe déjà c'est un déplacement
194
			else {
265
			else {
Line 195... Line 266...
195
				// alors on supprime d'abord le noeud concerné
266
				// alors on supprime d'abord le noeud concerné
196
				arbreMotsCles.getTree().getNodeById(nd.getId() + "_filtre")
267
				arbreMotsCles.getTree().getNodeById(nd.getId() +prefixe)
Line 197... Line 268...
197
						.remove();
268
						.remove();
Line 198... Line 269...
198
			}
269
			}
199
 
270
 
200
			// on chercher le père du nouveau noeud
271
			// on chercher le père du nouveau noeud
201
			Node ndPereOriginal = nd.getParentNode();
272
			Node ndPereOriginal = nd.getParentNode();
202
 
273
 
203
			
274
			
Line 204... Line 275...
204
			String idPereFiltre = ndPereOriginal.getId() + "_filtre";
275
			String idPereFiltre = ndPereOriginal.getId() +prefixe;
Line 215... Line 286...
215
			this.doLayout();
286
			this.doLayout();
216
		}
287
		}
Line 217... Line 288...
217
 
288
 
218
		// si on reçoit une string
289
		// si on reçoit une string
219
		if (nouvelleDonnees instanceof String) {
290
		if (nouvelleDonnees instanceof String) {
220
			String idSupp = (String) nouvelleDonnees + "_filtre";
291
			String idSupp = (String) nouvelleDonnees +prefixe;
221
			// c'est une suppression et si le noeud existe bien
292
			// c'est une suppression et si le noeud existe bien
222
			if (arbreMotsCles.getTree().getNodeById(idSupp) != null) {
293
			if (arbreMotsCles.getTree().getNodeById(idSupp) != null) {
223
				// on le supprime
294
				// on le supprime
224
				arbreMotsCles.getTree().getNodeById(idSupp).remove();
295
				arbreMotsCles.getTree().getNodeById(idSupp).remove();
Line 234... Line 305...
234
	 * @return le médiateur associé
305
	 * @return le médiateur associé
235
	 */
306
	 */
236
	public ImageMediateur getIMediateur() {
307
	public ImageMediateur getIMediateur() {
237
		return iMediateur;
308
		return iMediateur;
238
	}
309
	}
-
 
310
	
-
 
311
	public ObservationMediateur getOMediateur() {
-
 
312
		return oMediateur ;
-
 
313
	}
Line 239... Line 314...
239
 
314
 
240
	/**
315
	/**
241
	 * Accesseur pour le panneau contenant l'arbre
316
	 * Accesseur pour le panneau contenant l'arbre
242
	 * 
317
	 * 
Line 260... Line 335...
260
	 * @return un tableau contenant le nom du champ à filtrer et sa valeur
335
	 * @return un tableau contenant le nom du champ à filtrer et sa valeur
261
	 */
336
	 */
262
	public String[] renvoyerValeursAFiltrer() {
337
	public String[] renvoyerValeursAFiltrer() {
Line 263... Line 338...
263
 
338
 
-
 
339
		valider();
-
 
340
		String[] valeursFiltrees = new String[2] ;
264
		valider();
341
		valeursFiltrees[1] = motsClesEncours;
-
 
342
		
265
 
343
		if(iMediateur != null) {
-
 
344
			valeursFiltrees[0] = "ci_meta_mots_cles";
-
 
345
		}
-
 
346
		else
-
 
347
		{
-
 
348
			valeursFiltrees[0] = "mots_cles";
Line 266... Line 349...
266
		String[] valeursFiltrees = { "ci_meta_mots_cles", motsClesEncours };
349
		}
267
 
350
 
Line 268... Line 351...
268
		return valeursFiltrees;
351
		return valeursFiltrees;
Line 283... Line 366...
283
			
366
			
Line 284... Line 367...
284
			for (int i = 0; i < ndNodeFils.length; i++) {
367
			for (int i = 0; i < ndNodeFils.length; i++) {
285
 
368
 
286
				String[] usObj = (String[]) ndNodeFils[i].getUserObject();
369
				String[] usObj = (String[]) ndNodeFils[i].getUserObject();
287
				TreeNode child = new TreeNode(usObj[0]);
370
				TreeNode child = new TreeNode(usObj[0]);
288
				child.setId(usObj[1] + "_filtre");
371
				child.setId(usObj[1] +prefixe);
289
				child.setChecked(false);
372
				child.setChecked(false);
Line 290... Line 373...
290
				child.setUserObject(usObj);
373
				child.setUserObject(usObj);
Line 303... Line 386...
303
	 */
386
	 */
304
	public boolean renvoyerEtatFiltre() {
387
	public boolean renvoyerEtatFiltre() {
Line 305... Line 388...
305
 
388
 
306
		return filtreModifie;
389
		return filtreModifie;
-
 
390
	}
-
 
391
	
-
 
392
	public void mettreAJourMotsCles(String valeur, String id) {
-
 
393
		if(getIMediateur() != null) {
-
 
394
			getIMediateur().mettreAjourMotsClesId(valeur,
-
 
395
				id);
-
 
396
		}
-
 
397
		else
-
 
398
		{
-
 
399
			getOMediateur().mettreAjourMotsClesId(valeur, id);
-
 
400
		}
-
 
401
	}
-
 
402
	
-
 
403
	public void obtenirArbreMotsCles() {
-
 
404
		if(getIMediateur() != null) {
-
 
405
			getIMediateur().obtenirArbreMotsCles(this);
-
 
406
		}
-
 
407
		else
-
 
408
		{
-
 
409
			getOMediateur().obtenirArbreMotsCles(this);
-
 
410
		}
Line 307... Line 411...
307
	}
411
	}
308
 
412
 
309
	public void valider() {
413
	public void valider() {
310
		if (estInstancie) {
414
		if (estInstancie) {
Line 321... Line 425...
321
							// infos
425
							// infos
322
							TreeNode tn = getArbreMotsCles().getNodeById(
426
							TreeNode tn = getArbreMotsCles().getNodeById(
323
									node.getId());
427
									node.getId());
Line 324... Line 428...
324
 
428
 
325
							String[] usObject = (String[]) tn.getUserObject();
429
							String[] usObject = (String[]) tn.getUserObject();
326
							getIMediateur().mettreAjourMotsClesId(usObject[0],
-
 
Line 327... Line 430...
327
									usObject[1]);
430
							mettreAJourMotsCles(usObject[0], usObject[1]);
328
 
431
 
329
							if (tn.getUI().isChecked()) {
432
							if (tn.getUI().isChecked()) {
330
								// et les concatène à la string des mots clés en
433
								// et les concatène à la string des mots clés en
Line 340... Line 443...
340
			// on suppose que le filtre a change
443
			// on suppose que le filtre a change
341
			filtreModifie = true;
444
			filtreModifie = true;
342
		}
445
		}
343
	}
446
	}
Line -... Line 447...
-
 
447
 
-
 
448
	public void raz() {
-
 
449
		
-
 
450
		// on vide tous les noeuds de l'ancien arbre
-
 
451
		Node[] rootChild = arbreMotsCles.getRootNode().getChildNodes();
-
 
452
		for (int i = 0; i < rootChild.length; i++) {
-
 
453
			
-
 
454
			rootChild[i].remove();
-
 
455
		}
-
 
456
		
-
 
457
		arbreInitialise = false ;
-
 
458
		
-
 
459
		// on crée une racine pour l'arbre
-
 
460
		TreeNode root = new TreeNode("Tags");
-
 
461
		root.setId("racine"+prefixe);
-
 
462
		String[] usObject = { "Mots clés", "racine" };
-
 
463
		root.setUserObject(usObject);
-
 
464
		
-
 
465
		root.setExpandable(true);
-
 
466
		
-
 
467
		arbreMotsCles.setRootNode(root);
-
 
468
		
-
 
469
		arbreMotsCles.getRootNode().addListener(new TreeNodeListenerAdapter() {
-
 
470
 
-
 
471
			public void onClick(Node node, EventObject e) {
-
 
472
				if(!arbreInitialise) {
-
 
473
					expand();
-
 
474
				}
-
 
475
			}
-
 
476
 
-
 
477
			public void onExpand(Node node) {
-
 
478
				if(!arbreInitialise) {
-
 
479
					obtenirArbreMotsCles();
-
 
480
					arbreInitialise = true;
-
 
481
				}
-
 
482
			}
-
 
483
		});
-
 
484
	}
344
 
485