Subversion Repositories eFlore/Applications.coel

Rev

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