Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
127 gduche 1
package org.tela_botanica.client.vues;
2
 
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
import java.util.List;
6
 
7
import org.tela_botanica.client.ComposantClass;
8
import org.tela_botanica.client.Mediateur;
9
import org.tela_botanica.client.RegistreId;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
353 gduche 11
import org.tela_botanica.client.modeles.Information;
127 gduche 12
import org.tela_botanica.client.modeles.Personne;
13
import org.tela_botanica.client.modeles.PersonneListe;
14
 
15
import com.extjs.gxt.ui.client.Registry;
287 gduche 16
import com.extjs.gxt.ui.client.Style.Scroll;
127 gduche 17
import com.extjs.gxt.ui.client.Style.SelectionMode;
377 gduche 18
import com.extjs.gxt.ui.client.Style.SortDir;
127 gduche 19
import com.extjs.gxt.ui.client.binder.TableBinder;
20
import com.extjs.gxt.ui.client.event.ComponentEvent;
21
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
22
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
23
import com.extjs.gxt.ui.client.event.SelectionListener;
24
import com.extjs.gxt.ui.client.store.ListStore;
25
import com.extjs.gxt.ui.client.widget.ContentPanel;
353 gduche 26
import com.extjs.gxt.ui.client.widget.Info;
278 jp_milcent 27
import com.extjs.gxt.ui.client.widget.LayoutContainer;
417 gduche 28
import com.extjs.gxt.ui.client.widget.form.LabelField;
127 gduche 29
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
287 gduche 30
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
127 gduche 31
import com.extjs.gxt.ui.client.widget.table.Table;
32
import com.extjs.gxt.ui.client.widget.table.TableColumn;
33
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
417 gduche 34
import com.extjs.gxt.ui.client.widget.table.TableItem;
127 gduche 35
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
36
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
278 jp_milcent 37
import com.google.gwt.core.client.GWT;
353 gduche 38
import com.google.gwt.user.client.Window;
127 gduche 39
 
436 gduche 40
public class PersonneListeVue extends ContentPanel implements Rafraichissable {
127 gduche 41
 
278 jp_milcent 42
	private Mediateur mediateur = null ;
127 gduche 43
	private Table table = null;
44
	private ListStore<Personne> store = null;
45
	private TableBinder<Personne> binder = null;
287 gduche 46
	private Personne personneSelectionnee = null;
258 gduche 47
 
436 gduche 48
	public PersonneListeVue() {
278 jp_milcent 49
		mediateur = Registry.get(RegistreId.MEDIATEUR);
127 gduche 50
 
51
		//Définition de la barre d'outil
52
		ToolBar toolBar = new ToolBar();
462 gduche 53
		TextToolItem ajouter = new TextToolItem(mediateur.i18nC.ajouter());
127 gduche 54
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
55
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {
56
			public void componentSelected(ComponentEvent ce) {
278 jp_milcent 57
				mediateur.clicAjouterPersonne();
127 gduche 58
			}
59
		});
60
		toolBar.add(ajouter);
217 aurelien 61
 
62
 
63
		final Rafraichissable r = this ;
127 gduche 64
 
217 aurelien 65
		// TODO : ajouter btn mod & supp
462 gduche 66
		final TextToolItem modifier = new TextToolItem(mediateur.i18nC.modifier());
127 gduche 67
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
217 aurelien 68
		modifier.addSelectionListener(new SelectionListener<ComponentEvent>() {
69
			public void componentSelected(ComponentEvent ce) {
287 gduche 70
				mediateur.clicModifierPersonne(personneSelectionnee);
217 aurelien 71
			}
72
		});
127 gduche 73
		toolBar.add(modifier);
74
 
462 gduche 75
		final TextToolItem supprimer = new TextToolItem(mediateur.i18nC.supprimer());
217 aurelien 76
		supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
77
			public void componentSelected(ComponentEvent ce) {
78
 
417 gduche 79
				mediateur.clicSupprimerPersonne(r, binder.getSelection());
217 aurelien 80
			}
81
		});
417 gduche 82
 
127 gduche 83
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
84
		toolBar.add(supprimer);
258 gduche 85
 
127 gduche 86
		setTopComponent(toolBar);
258 gduche 87
 
127 gduche 88
		List<TableColumn> columns = new ArrayList<TableColumn>();
89
 
90
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
462 gduche 91
		columns.add(new TableColumn("fmt_nom_complet", mediateur.i18nC.personneNomComplet(), .30f));
92
		columns.add(new TableColumn("code_postal", mediateur.i18nC.personneCodePostal(), .10f));
93
		columns.add(new TableColumn("ville", mediateur.i18nC.personneVille(), .20f));
94
		columns.add(new TableColumn("courriel_princ", mediateur.i18nC.personneCourriel(), .25f));
95
		columns.add(new TableColumn("nom", mediateur.i18nC.personneNom(), .10f));
96
		columns.add(new TableColumn("prenom", mediateur.i18nC.personnePrenom(), .10f));
127 gduche 97
 
462 gduche 98
		columns.get(4).setHidden(true);
99
		columns.get(5).setHidden(true);
100
 
127 gduche 101
		TableColumnModel cm = new TableColumnModel(columns);
102
 
103
		table = new Table(cm);
104
		table.setSelectionMode(SelectionMode.MULTI);
105
		table.setBorders(false);
287 gduche 106
 
107
		table.setHorizontalScroll(true);
108
 
127 gduche 109
		add(table);
110
 
111
		store = new ListStore<Personne>();
112
 
113
		binder = new TableBinder<Personne>(table, store);
114
		binder.setAutoSelect(true);
150 gduche 115
 
116
		binder.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
117
		public void selectionChanged(SelectionChangedEvent<Personne> event) {
118
				Personne p = (Personne) event.getSelectedItem();
287 gduche 119
				personneSelectionnee = p;
150 gduche 120
				clicListe(p);
127 gduche 121
			}
150 gduche 122
		});
287 gduche 123
 
127 gduche 124
		setLayout(new FitLayout());
125
	}
126
 
150 gduche 127
	private void clicListe(Personne personne) {
278 jp_milcent 128
		mediateur.clicListePersonne(personne);
127 gduche 129
	}
130
 
353 gduche 131
	public void rafraichir(Object nouvellesDonnees) {
417 gduche 132
 
353 gduche 133
		if (nouvellesDonnees instanceof PersonneListe) {
417 gduche 134
 
462 gduche 135
			setHeading(mediateur.i18nC.personneListeLabel());
353 gduche 136
			PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
127 gduche 137
 
138
			List<Personne> liste = new ArrayList<Personne>();
139
			for (Iterator<String> it = listePersonnes.keySet().iterator(); it.hasNext();) {
140
				liste.add(listePersonnes.get(it.next()));
141
			}
142
 
278 jp_milcent 143
			store.removeAll();
144
			store.add(liste);
377 gduche 145
 
417 gduche 146
			mediateur.actualiserPanneauCentral();
377 gduche 147
 
434 gduche 148
			table.sort(0, SortDir.ASC);
417 gduche 149
			if (store.getCount() > 0) {
150
				table.getSelectionModel().select(0);
151
			}
377 gduche 152
 
153
 
154
 
417 gduche 155
		} else if (nouvellesDonnees instanceof Information)	{
377 gduche 156
 
417 gduche 157
			Information info = (Information) nouvellesDonnees;
158
			Info.display("Erreur", info.getMessages().toString());
159
 
160
			if (info.getType().equals("suppression_personne")) 	{
161
 
162
					List<TableItem> selectionPersonnes = table.getSelectedItems();
163
					final int taille = selectionPersonnes.size();
164
					for (int i = 0; i < taille; i++) {
165
						//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
166
						table.remove(selectionPersonnes.get(i));
167
					}
361 jp_milcent 168
			}
169
 
417 gduche 170
 
171
 
361 jp_milcent 172
		} else {
474 gduche 173
			GWT.log(mediateur.messages.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
127 gduche 174
		}
278 jp_milcent 175
		layout();
127 gduche 176
	}
177
}
189 gduche 178
 
179
 
180
 
181
 
182
 
183