Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
453 jp_milcent 1
package org.tela_botanica.client.vues;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
import org.tela_botanica.client.ComposantClass;
7
import org.tela_botanica.client.Mediateur;
8
import org.tela_botanica.client.RegistreId;
9
import org.tela_botanica.client.i18n.Constantes;
516 jp_milcent 10
import org.tela_botanica.client.images.Images;
453 jp_milcent 11
import org.tela_botanica.client.interfaces.Rafraichissable;
12
import org.tela_botanica.client.modeles.Collection;
13
import org.tela_botanica.client.modeles.CollectionListe;
14
import org.tela_botanica.client.modeles.Information;
15
import org.tela_botanica.client.modeles.Utilisateur;
16
 
17
import com.extjs.gxt.ui.client.Registry;
18
import com.extjs.gxt.ui.client.Style.SelectionMode;
19
import com.extjs.gxt.ui.client.Style.SortDir;
20
import com.extjs.gxt.ui.client.binder.TableBinder;
499 jp_milcent 21
import com.extjs.gxt.ui.client.event.ButtonEvent;
453 jp_milcent 22
import com.extjs.gxt.ui.client.event.ComponentEvent;
23
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
24
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
25
import com.extjs.gxt.ui.client.event.SelectionListener;
26
import com.extjs.gxt.ui.client.store.ListStore;
27
import com.extjs.gxt.ui.client.widget.ContentPanel;
28
import com.extjs.gxt.ui.client.widget.Info;
499 jp_milcent 29
import com.extjs.gxt.ui.client.widget.button.Button;
453 jp_milcent 30
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
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;
34
import com.extjs.gxt.ui.client.widget.table.TableItem;
35
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
36
import com.google.gwt.core.client.GWT;
37
 
38
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
39
 
40
	private Mediateur mediateur = null ;
41
	private Constantes i18nC = null ;
42
 
43
	private Table table = null;
44
	private ListStore<Collection> store = null;
45
	private TableBinder<Collection> binder = null;
46
 
499 jp_milcent 47
	private Button modifier;
48
	private Button supprimer;
49
	private Button ajouter;
453 jp_milcent 50
 
51
	public CollectionListeVue(Mediateur mediateurCourant) {
52
		mediateur = mediateurCourant;
53
		i18nC = mediateur.i18nC;
54
 
55
		Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT);
56
 
57
		ToolBar toolBar = new ToolBar();
499 jp_milcent 58
		ajouter = new Button(i18nC.ajouter());
516 jp_milcent 59
		ajouter.setIcon(Images.ICONES.ajouter());
499 jp_milcent 60
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
61
			public void componentSelected(ButtonEvent ce) {
453 jp_milcent 62
				mediateur.clicAjouterCollection();
63
			}
64
		});
65
		toolBar.add(ajouter);
66
 
499 jp_milcent 67
		modifier = new Button(i18nC.modifier());
516 jp_milcent 68
		modifier.setIcon(Images.ICONES.formModifier());
499 jp_milcent 69
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
70
			public void componentSelected(ButtonEvent ce) {
453 jp_milcent 71
				mediateur.clicModifierCollection(binder.getSelection());
72
			}
73
		});
74
		toolBar.add(modifier);
75
 
499 jp_milcent 76
		supprimer = new Button(i18nC.supprimer());
516 jp_milcent 77
		supprimer.setIcon(Images.ICONES.supprimer());
499 jp_milcent 78
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
79
			public void componentSelected(ButtonEvent ce) {
453 jp_milcent 80
				clicSupprimerCollection(binder.getSelection());
81
			}
82
		});
83
		if (!utilisateur.isIdentifie()) {
84
			supprimer.disable();
85
		}
86
		toolBar.add(supprimer);
87
 
88
		setTopComponent(toolBar);
89
 
90
		List<TableColumn> columns = new ArrayList<TableColumn>();
91
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
477 jp_milcent 92
		columns.add(new TableColumn("nom", i18nC.nom(), .5f));
468 jp_milcent 93
		columns.add(new TableColumn("structure_nom", i18nC.structure(), .3f));
94
		columns.add(new TableColumn("structure_ville", i18nC.ville(), .2f));
453 jp_milcent 95
 
477 jp_milcent 96
		columns.get(1).setHidden(true);
468 jp_milcent 97
 
453 jp_milcent 98
		TableColumnModel cm = new TableColumnModel(columns);
99
		table = new Table(cm);
100
		table.setSelectionMode(SelectionMode.MULTI);
101
		table.setBorders(false);
102
		table.setStripeRows(true);
103
		add(table);
104
 
105
 
106
		store = new ListStore<Collection>();
107
		store.sort("nom", SortDir.ASC);
108
 
109
		binder = new TableBinder<Collection>(table, store);
468 jp_milcent 110
		binder.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
111
			public void selectionChanged(SelectionChangedEvent<Collection> event) {
112
				Collection m = (Collection) event.getSelectedItem();
453 jp_milcent 113
				clicListe(m);
114
			}
115
		});
116
 
117
		setLayout(new FitLayout());
118
	}
119
 
468 jp_milcent 120
	private void clicListe(Collection m) {
453 jp_milcent 121
		if (store.getCount() > 0) {
468 jp_milcent 122
			mediateur.clicListeCollection(m);
453 jp_milcent 123
		}
124
	}
125
 
126
	private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
127
		if (store.getCount() > 0) {
128
			mediateur.clicSupprimerCollection(this, collectionsASupprimer);
129
		}
130
	}
131
 
132
	public void rafraichir(Object nouvelleDonnees) {
133
		if (nouvelleDonnees instanceof CollectionListe) {
134
			CollectionListe collections = (CollectionListe) nouvelleDonnees;
135
			setHeading(i18nC.collectionListeTitre());
136
 
137
			List<Collection> liste = (List<Collection>) collections.toList();
138
			store.removeAll();
139
			store.add(liste);
140
 
141
			mediateur.actualiserPanneauCentral();
142
 
143
			if (store.getCount() > 0) {
516 jp_milcent 144
				table.getSelectionModel().select(0, 0, true);
453 jp_milcent 145
			}
146
		} else if (nouvelleDonnees instanceof Information) {
147
			Information info = (Information) nouvelleDonnees;
148
			if (info.getType().equals("suppression_collection")) {
149
				// Affichage d'un message d'information
150
				//GWT.log(info.toString(), null);
151
				Info.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
152
 
153
				// Suppression des structures sélectionnées
154
				List<TableItem> selectionCollection = table.getSelectedItems();
155
				final int taille = selectionCollection.size();
156
				for (int i = 0; i < taille; i++) {
157
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
158
					table.remove(selectionCollection.get(i));
159
				}
160
 
161
				// Désactivation des boutons si la liste est vide
162
				if (table.getItemCount() == 0) {
163
					supprimer.disable();
164
					modifier.disable();
165
				}
166
			} else if (info.getType().equals("maj_utilisateur")) {
167
				if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
168
					if (table.getItemCount() != 0) {
169
						supprimer.enable();
170
					}
171
				} else {
172
					supprimer.disable();
173
				}
174
			}
175
		} else {
176
			GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
177
		}
178
		layout();
179
	}
180
}