Subversion Repositories eFlore/Applications.coel

Rev

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