Subversion Repositories eFlore/Applications.coel

Rev

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