Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
60 jpm 1
package org.tela_botanica.client.vues;
2
 
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
import java.util.List;
6
 
69 jpm 7
import org.tela_botanica.client.ComposantClass;
60 jpm 8
import org.tela_botanica.client.Mediateur;
9
import org.tela_botanica.client.RegistreId;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
133 jpm 11
import org.tela_botanica.client.modeles.Information;
60 jpm 12
import org.tela_botanica.client.modeles.Structure;
69 jpm 13
import org.tela_botanica.client.modeles.StructureListe;
156 jp_milcent 14
import org.tela_botanica.client.modeles.Utilisateur;
60 jpm 15
 
16
import com.extjs.gxt.ui.client.Registry;
17
import com.extjs.gxt.ui.client.Style.SelectionMode;
210 jp_milcent 18
import com.extjs.gxt.ui.client.Style.SortDir;
60 jpm 19
import com.extjs.gxt.ui.client.binder.TableBinder;
69 jpm 20
import com.extjs.gxt.ui.client.event.ComponentEvent;
60 jpm 21
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
22
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
69 jpm 23
import com.extjs.gxt.ui.client.event.SelectionListener;
60 jpm 24
import com.extjs.gxt.ui.client.store.ListStore;
25
import com.extjs.gxt.ui.client.widget.ContentPanel;
133 jpm 26
import com.extjs.gxt.ui.client.widget.Info;
278 jp_milcent 27
import com.extjs.gxt.ui.client.widget.LayoutContainer;
60 jpm 28
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
29
import com.extjs.gxt.ui.client.widget.table.Table;
30
import com.extjs.gxt.ui.client.widget.table.TableColumn;
31
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
155 jpm 32
import com.extjs.gxt.ui.client.widget.table.TableItem;
60 jpm 33
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
34
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
133 jpm 35
import com.google.gwt.core.client.GWT;
60 jpm 36
 
37
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
38
 
133 jpm 39
	private Rafraichissable structureListePanneauVue = null ;
156 jp_milcent 40
	private Mediateur mediateur = null ;
60 jpm 41
	private Table table = null;
42
	private ListStore<Structure> store = null;
43
	private TableBinder<Structure> binder = null;
155 jpm 44
	private TextToolItem modifier;
45
	private TextToolItem supprimer;
46
	private TextToolItem ajouter;
60 jpm 47
 
48
	public StructureListePanneauVue() {
277 jp_milcent 49
		Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT);
156 jp_milcent 50
		mediateur = Registry.get(RegistreId.MEDIATEUR);
133 jpm 51
		structureListePanneauVue = this;
60 jpm 52
 
53
		ToolBar toolBar = new ToolBar();
155 jpm 54
		ajouter = new TextToolItem("Ajouter");
69 jpm 55
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
56
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {
57
			public void componentSelected(ComponentEvent ce) {
156 jp_milcent 58
				mediateur.clicAjouterStructure();
133 jpm 59
			}
69 jpm 60
		});
60 jpm 61
		toolBar.add(ajouter);
62
 
155 jpm 63
		modifier = new TextToolItem("Modifier");
69 jpm 64
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
156 jp_milcent 65
		modifier.addSelectionListener(new SelectionListener<ComponentEvent>() {
66
			public void componentSelected(ComponentEvent ce) {
67
				mediateur.clicModifierStructure(binder.getSelection());
68
			}
69
		});
60 jpm 70
		toolBar.add(modifier);
71
 
155 jpm 72
		supprimer = new TextToolItem("Supprimer");
69 jpm 73
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
133 jpm 74
		supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
75
			public void componentSelected(ComponentEvent ce) {
156 jp_milcent 76
				mediateur.clicSupprimerStructure(structureListePanneauVue, binder.getSelection());
133 jpm 77
			}
78
		});
156 jp_milcent 79
		if (!utilisateur.isIdentifie()) {
80
			supprimer.disable();
81
		}
60 jpm 82
		toolBar.add(supprimer);
83
 
84
		setTopComponent(toolBar);
85
 
86
		List<TableColumn> columns = new ArrayList<TableColumn>();
87
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
88
		columns.add(new TableColumn("ville", "Ville", .3f));
89
		columns.add(new TableColumn("nom", "Nom", .7f));
90
 
91
		TableColumnModel cm = new TableColumnModel(columns);
92
		table = new Table(cm);
93
		table.setSelectionMode(SelectionMode.MULTI);
94
		table.setBorders(false);
210 jp_milcent 95
		table.setStripeRows(true);
60 jpm 96
		add(table);
210 jp_milcent 97
 
98
 
60 jpm 99
		store = new ListStore<Structure>();
210 jp_milcent 100
		store.sort("ville", SortDir.ASC);
101
 
60 jpm 102
		binder = new TableBinder<Structure>(table, store);
103
		binder.setAutoSelect(true);
104
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
105
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
106
				Structure m = (Structure) event.getSelectedItem();
107
				clicListe(m);
108
			}
109
		});
110
 
111
		setLayout(new FitLayout());
112
	}
113
 
114
	public ListStore<Structure> getStore() {
115
		return store;
116
	}
117
 
118
	public TableBinder<Structure> getBinder() {
119
		return binder;
120
	}
121
 
122
	private void clicListe(Structure institution) {
156 jp_milcent 123
		mediateur.clicListeInstitution(institution);
60 jpm 124
	}
125
 
126
	public void rafraichir(Object nouvelleDonnees) {
69 jpm 127
		if (nouvelleDonnees instanceof StructureListe) {
128
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
60 jpm 129
			setHeading("Institutions");
130
 
131
			List<Structure> liste = new ArrayList<Structure>();
132
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
133
				liste.add(listeInstitutions.get(it.next()));
134
			}
135
 
136
			store.removeAll();
137
			store.add((List<Structure>) liste);
278 jp_milcent 138
 
60 jpm 139
			// Test pour savoir si la liste contient des éléments
140
			if (listeInstitutions.size() > 0) {
141
				binder.setSelection((Structure) listeInstitutions.get(0));
142
			}
210 jp_milcent 143
 
278 jp_milcent 144
			// Mise à jour du panneau central
145
			((LayoutContainer) Registry.get(RegistreId.PANNEAU_CENTRE)).layout();
133 jpm 146
		} else if (nouvelleDonnees instanceof Information) {
147
			Information info = (Information) nouvelleDonnees;
148
			if (info.getType().equals("suppression_structure")) {
155 jpm 149
				// Affichage d'un message d'information
150
				//GWT.log(info.toString(), null);
153 jpm 151
				Info.display("Suppression d'une Institution", info.toString().replaceAll("\n", "<br />"));
155 jpm 152
 
153
				// Suppression des structures sélectionnées
154
				List<TableItem> selectionStructure = table.getSelectedItems();
155
				final int taille = selectionStructure.size();
156
				for (int i = 0; i < taille; i++) {
157
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
158
					table.remove(selectionStructure.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
				}
156 jp_milcent 166
			} else if (info.getType().equals("maj_utilisateur")) {
277 jp_milcent 167
				if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
156 jp_milcent 168
					if (table.getItemCount() != 0) {
169
						supprimer.enable();
170
					}
171
				} else {
172
					supprimer.disable();
173
				}
133 jpm 174
			}
156 jp_milcent 175
		} else {
278 jp_milcent 176
			GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
60 jpm 177
		}
156 jp_milcent 178
		layout();
60 jpm 179
	}
180
}