Subversion Repositories eFlore/Applications.coel

Rev

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