Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 352 Rev 678
Line 3... Line 3...
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;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.observation.ObservationMediateur;
6
import org.tela_botanica.client.observation.ObservationMediateur;
Line 7... Line 7...
7
 
7
 
8
import com.google.gwt.user.client.ui.Label;
8
import com.google.gwt.user.client.Window;
9
import com.gwtext.client.core.EventObject;
9
import com.gwtext.client.core.EventObject;
10
import com.gwtext.client.data.Node;
-
 
11
import com.gwtext.client.data.NodeTraversalCallback;
10
import com.gwtext.client.data.Node;
12
import com.gwtext.client.data.Tree;
-
 
13
import com.gwtext.client.widgets.Button;
11
import com.gwtext.client.data.Tree;
14
import com.gwtext.client.widgets.Component;
12
import com.gwtext.client.widgets.Component;
15
import com.gwtext.client.widgets.Panel;
-
 
16
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
13
import com.gwtext.client.widgets.Panel;
17
import com.gwtext.client.widgets.event.PanelListenerAdapter;
14
import com.gwtext.client.widgets.event.PanelListenerAdapter;
18
import com.gwtext.client.widgets.layout.RowLayout;
15
import com.gwtext.client.widgets.layout.RowLayout;
-
 
16
import com.gwtext.client.widgets.layout.RowLayoutData;
19
import com.gwtext.client.widgets.layout.RowLayoutData;
17
import com.gwtext.client.widgets.tree.MultiSelectionModel;
20
import com.gwtext.client.widgets.tree.TreeNode;
18
import com.gwtext.client.widgets.tree.TreeNode;
21
import com.gwtext.client.widgets.tree.TreePanel;
19
import com.gwtext.client.widgets.tree.TreePanel;
-
 
20
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter;
Line 22... Line 21...
22
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter;
21
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
23
 
22
 
24
/**
23
/**
25
 * fenêtre de recherche affichant l'arbre des mots clés en lecture et un bouton
24
 * fenêtre de recherche affichant l'arbre des mots clés en lecture et un bouton
Line 90... Line 89...
90
 
89
 
91
		// on crée le panel
90
		// on crée le panel
92
		super();
91
		super();
93
		iMediateur = im;
92
		iMediateur = im;
94
		this.prefixe += prefixeImg;
-
 
95
		Label labelRecherche = new Label("Par mots clés :");
-
 
96
		add(labelRecherche);
93
		this.prefixe += prefixeImg;
97
		initialiserPanel();
94
		initialiserPanel();
Line 98... Line 95...
98
	}
95
	}
99
	
96
	
Line 118... Line 115...
118
	public void initialiserPanel() {
115
	public void initialiserPanel() {
119
		// on crée le conteneur de l'arbre
116
		// on crée le conteneur de l'arbre
120
		arbreMotsCles = new TreePanel();
117
		arbreMotsCles = new TreePanel();
121
		arbreMotsCles.setId("x-view-tree-filter"+prefixe);
118
		arbreMotsCles.setId("x-view-tree-filter"+prefixe);
Line -... Line 119...
-
 
119
 
-
 
120
		MultiSelectionModel msModel = new MultiSelectionModel();
-
 
121
		arbreMotsCles.setSelectionModel(msModel);
122
 
122
		
123
		// on crée une racine pour l'arbre
123
		// on crée une racine pour l'arbre
124
		TreeNode root = new TreeNode("Tags");
124
		TreeNode root = new TreeNode("Tags");
125
		root.setId("racine"+prefixe);
125
		root.setId("racine"+prefixe);
126
		String[] usObject = { "Mots clés", "racine"+prefixe };
126
		String[] usObject = { "Mots clés", "racine"+prefixe };
Line 175... Line 175...
175
				arbreMotsCles.setAutoScroll(true);
175
				arbreMotsCles.setAutoScroll(true);
176
				arbreMotsCles.setBorder(false);
176
				arbreMotsCles.setBorder(false);
Line 177... Line 177...
177
 
177
 
178
				// on met en forme le layout
178
				// on met en forme le layout
179
				((Panel) component).add(arbreMotsCles,new RowLayoutData("80%"));
-
 
180
				
-
 
181
				if(iMediateur == null) {
-
 
182
					Panel p = new Panel();
-
 
183
					p.setBorder(false);
-
 
184
					Button valider = new Button("Rechercher") ; 
-
 
185
					valider.addListener(new ButtonListenerAdapter() {
-
 
186
 
-
 
187
						public void onClick(Button button, EventObject e) {
-
 
188
							getOMediateur().obtenirNombreObservation();
-
 
189
						}
-
 
190
						
-
 
191
					});
-
 
192
					p.add(valider,new RowLayoutData());
-
 
193
					add(p);
-
 
Line 194... Line 179...
194
				}
179
				((Panel) component).add(arbreMotsCles,new RowLayoutData("80%"));
195
 
180
 
196
				// on ajoute les listeners d'évenements
181
				// on ajoute les listeners d'évenements
197
				ajouterListeners();
182
				ajouterListeners();
Line 203... Line 188...
203
 
188
 
204
	/**
189
	/**
205
	 * ajoute les listeners pour les boutons et le cochage des mots clés
190
	 * ajoute les listeners pour les boutons et le cochage des mots clés
206
	 */
191
	 */
-
 
192
	private void ajouterListeners() {
-
 
193
		arbreMotsCles.addListener(new TreePanelListenerAdapter() {
-
 
194
								
-
 
195
			// gestion du clic sur un noeud
-
 
196
			public void onClick(TreeNode node, EventObject e) {
-
 
197
 
-
 
198
				e.stopEvent();
-
 
199
								
-
 
200
				boolean multi = false;
-
 
201
				if(e.hasModifier()) {
-
 
202
					multi = true;
-
 
203
				}
-
 
204
				gererClicNoeud(node,multi);
-
 
205
			}
-
 
206
		});
-
 
207
	}
-
 
208
	
-
 
209
	/**
-
 
210
	 * Fonction de gestion sur le clic sur le noeud
-
 
211
	 * 
-
 
212
	 * @param node
-
 
213
	 */
Line -... Line 214...
-
 
214
	public void gererClicNoeud(TreeNode node, boolean multi) {
-
 
215
		
-
 
216
		if(!arbreInitialise) {
-
 
217
			obtenirArbreMotsCles();
-
 
218
		} else {
-
 
219
			if(node.equals(arbreMotsCles.getRootNode())) {
-
 
220
				arbreMotsCles.getSelectionModel().clearSelections();
-
 
221
			} else {
-
 
222
				((MultiSelectionModel)arbreMotsCles.getSelectionModel()).select(node, multi);
-
 
223
			}
-
 
224
			filtreModifie = true;
207
	private void ajouterListeners() {
225
			iMediateur.obtenirPhotoGalerie();
Line 208... Line 226...
208
		
226
		}
209
	}
227
	}
210
 
228
 
Line 243... Line 261...
243
 
261
 
244
			// l'état du filtre est réinitialisé
262
			// l'état du filtre est réinitialisé
245
			filtreModifie = false;
263
			filtreModifie = false;
246
			doLayout() ;
264
			doLayout() ;
247
		}
-
 
248
 
-
 
249
		if (nouvelleDonnees instanceof TreeNode) {
-
 
250
			TreeNode nd = (TreeNode) nouvelleDonnees;
-
 
251
 
-
 
252
			// si le noeud n'existe pas déjà c'est un ajout
-
 
253
			if (arbreMotsCles.getTree().getNodeById(nd.getId() +prefixe) == null) {
-
 
254
				// donc on ne fait rien de spécial
-
 
255
			}
-
 
256
			// si le noeud existe déjà c'est un déplacement
-
 
257
			else {
-
 
258
				// alors on supprime d'abord le noeud concerné
-
 
259
				arbreMotsCles.getTree().getNodeById(nd.getId() +prefixe)
-
 
260
						.remove();
-
 
261
			}
-
 
262
 
-
 
263
			// on chercher le père du nouveau noeud
-
 
264
			Node ndPereOriginal = nd.getParentNode();
-
 
265
 
-
 
266
			
-
 
267
			String idPereFiltre = ndPereOriginal.getId() +prefixe;
-
 
268
 
-
 
269
			String[] usObj = (String[]) nd.getUserObject();
-
 
270
			TreeNode child = new TreeNode(usObj[0]);
-
 
271
			child.setId(usObj[1] +prefixe);
-
 
272
			child.setChecked(false);
-
 
273
			child.setUserObject(usObj);
-
 
274
			arbreMotsCles.getNodeById(idPereFiltre).appendChild(child);
-
 
275
 
-
 
276
			// et on ajoute le nouveau noeud à son père
-
 
277
			copierFilsNoeud(nd, child);
-
 
278
			this.doLayout();
-
 
279
		}
-
 
280
 
-
 
281
		// si on reçoit une string
-
 
282
		if (nouvelleDonnees instanceof String) {
-
 
283
			String idSupp = (String) nouvelleDonnees +prefixe;
-
 
284
			// c'est une suppression et si le noeud existe bien
-
 
285
			if (arbreMotsCles.getTree().getNodeById(idSupp) != null) {
-
 
286
				// on le supprime
-
 
287
				arbreMotsCles.getTree().getNodeById(idSupp).remove();
-
 
288
			}
-
 
289
			
-
 
290
		}
-
 
291
 
265
		}
Line 292... Line 266...
292
	}
266
	}
293
 
267
 
294
	/**
268
	/**
Line 325... Line 299...
325
	 * Renvoie un tableau contenant le nom du champ à filtrer et la valeur
299
	 * Renvoie un tableau contenant le nom du champ à filtrer et la valeur
326
	 * 
300
	 * 
327
	 * @return un tableau contenant le nom du champ à filtrer et sa valeur
301
	 * @return un tableau contenant le nom du champ à filtrer et sa valeur
328
	 */
302
	 */
329
	public String[] renvoyerValeursAFiltrer() {
303
	public String[] renvoyerValeursAFiltrer() {
330
 
-
 
331
		valider();
-
 
332
		String[] valeursFiltrees = new String[2] ;
-
 
333
		valeursFiltrees[1] = motsClesEncours;
-
 
Line -... Line 304...
-
 
304
		
-
 
305
		String val = "";
-
 
306
		
-
 
307
		TreeNode[] noeuds = ((MultiSelectionModel)arbreMotsCles.getSelectionModel()).getSelectedNodes();
-
 
308
		
334
		
309
		for(int i = 0; i< noeuds.length ; i++) {
-
 
310
			if(noeuds[i].getDepth() > 0) {
-
 
311
				
335
		if(iMediateur != null) {
312
				String[] userObj = (String[])noeuds[i].getUserObject();
336
			valeursFiltrees[0] = "ci_meta_mots_cles";
313
				String idMotCle = noeuds[i].getId();
-
 
314
				
-
 
315
				if(userObj != null && userObj[1] != null) {
337
		}
316
					idMotCle = userObj[1];
338
		else
317
				}
339
		{
318
				
-
 
319
				val += ";"+idMotCle;
340
			valeursFiltrees[0] = "mots_cles";
320
			}
-
 
321
		}
-
 
322
		
-
 
323
		val = val.replaceFirst(";", "");
-
 
324
		
Line 341... Line 325...
341
		}
325
		String[] valeursFiltres = {"ci_meta_mots_cles", val};
342
 
326
 
Line 343... Line 327...
343
		return valeursFiltrees;
327
		return valeursFiltres;
344
	}
328
	}
345
 
329
 
Line 359... Line 343...
359
			for (int i = 0; i < ndNodeFils.length; i++) {
343
			for (int i = 0; i < ndNodeFils.length; i++) {
Line 360... Line 344...
360
 
344
 
361
				String[] usObj = (String[]) ndNodeFils[i].getUserObject();
345
				String[] usObj = (String[]) ndNodeFils[i].getUserObject();
362
				TreeNode child = new TreeNode(usObj[0]);
346
				TreeNode child = new TreeNode(usObj[0]);
363
				child.setId(usObj[1] +prefixe);
-
 
364
				child.setChecked(false);
347
				child.setId(usObj[1] +prefixe);
365
				child.setUserObject(usObj);
348
				child.setUserObject(usObj);
Line 366... Line 349...
366
				ndPereCopie.appendChild(child);
349
				ndPereCopie.appendChild(child);
367
 
350
 
Line 404... Line 387...
404
 
387
 
405
	public void valider() {
388
	public void valider() {
406
		if (estInstancie) {
389
		if (estInstancie) {
407
			// on vide les mots clés en cours
390
			// on vide les mots clés en cours
408
			motsClesEncours = "";
-
 
409
			// pour chaque noeud à partir de la racine
-
 
410
			getArbreMotsCles().getRootNode().cascade(
-
 
411
					new NodeTraversalCallback() {
391
			motsClesEncours = "";
412
 
-
 
413
						// on éxécute une fonction
-
 
414
						public boolean execute(Node node) {
-
 
415
 
-
 
416
							// on récupère le mot clé associé au noeud et ses
-
 
417
							// infos
-
 
418
							TreeNode tn = getArbreMotsCles().getNodeById(
-
 
419
									node.getId());
-
 
420
 
-
 
421
							String[] usObject = (String[]) tn.getUserObject();
-
 
422
							mettreAJourMotsCles(usObject[0], usObject[1]);
-
 
423
 
-
 
424
							if (tn.getUI().isChecked()) {
-
 
425
								// et les concatène à la string des mots clés en
-
 
426
								// cours
-
 
427
								motsClesEncours += usObject[1] + ",";
-
 
428
							}
-
 
429
 
-
 
430
							return true;
-
 
431
						}
392
			
432
 
-
 
Line 433... Line 393...
433
					});
393
			
434
 
394
 
435
			// on suppose que le filtre a change
395
			// on suppose que le filtre a change
436
			filtreModifie = true;
396
			filtreModifie = true;
Line 475... Line 435...
475
				}
435
				}
476
			});
436
			});
477
		}
437
		}
478
	}
438
	}
Line -... Line 439...
-
 
439
 
-
 
440
	public void viderFiltre() {
-
 
441
		motsClesEncours = "";
-
 
442
		arbreMotsCles.getSelectionModel().clearSelections();
-
 
443
	}
479
 
444