Subversion Repositories eFlore/Applications.coel

Rev

Rev 210 | 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;
60 jpm 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;
155 jpm 31
import com.extjs.gxt.ui.client.widget.table.TableItem;
60 jpm 32
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
33
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
133 jpm 34
import com.google.gwt.core.client.GWT;
60 jpm 35
 
36
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
37
 
133 jpm 38
	private Rafraichissable structureListePanneauVue = null ;
156 jp_milcent 39
	private Mediateur mediateur = null ;
60 jpm 40
	private Table table = null;
41
	private ListStore<Structure> store = null;
42
	private TableBinder<Structure> binder = null;
155 jpm 43
	private TextToolItem modifier;
44
	private TextToolItem supprimer;
45
	private TextToolItem ajouter;
60 jpm 46
 
47
	public StructureListePanneauVue() {
277 jp_milcent 48
		Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT);
156 jp_milcent 49
		mediateur = Registry.get(RegistreId.MEDIATEUR);
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.setAutoSelect(true);
103
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
104
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
105
				Structure m = (Structure) event.getSelectedItem();
106
				clicListe(m);
107
			}
108
		});
109
 
110
		setLayout(new FitLayout());
111
	}
112
 
113
	public ListStore<Structure> getStore() {
114
		return store;
115
	}
116
 
117
	public TableBinder<Structure> getBinder() {
118
		return binder;
119
	}
120
 
121
	private void clicListe(Structure institution) {
156 jp_milcent 122
		mediateur.clicListeInstitution(institution);
60 jpm 123
	}
124
 
125
	public void rafraichir(Object nouvelleDonnees) {
69 jpm 126
		if (nouvelleDonnees instanceof StructureListe) {
127
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
60 jpm 128
			setHeading("Institutions");
129
 
130
			List<Structure> liste = new ArrayList<Structure>();
131
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
132
				liste.add(listeInstitutions.get(it.next()));
133
			}
134
 
135
			store.removeAll();
136
			store.add((List<Structure>) liste);
137
 
138
			// Test pour savoir si la liste contient des éléments
139
			if (listeInstitutions.size() > 0) {
140
				binder.setSelection((Structure) listeInstitutions.get(0));
141
			}
210 jp_milcent 142
 
133 jpm 143
		} else if (nouvelleDonnees instanceof Information) {
144
			Information info = (Information) nouvelleDonnees;
145
			if (info.getType().equals("suppression_structure")) {
155 jpm 146
				// Affichage d'un message d'information
147
				//GWT.log(info.toString(), null);
153 jpm 148
				Info.display("Suppression d'une Institution", info.toString().replaceAll("\n", "<br />"));
155 jpm 149
 
150
				// Suppression des structures sélectionnées
151
				List<TableItem> selectionStructure = table.getSelectedItems();
152
				final int taille = selectionStructure.size();
153
				for (int i = 0; i < taille; i++) {
154
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
155
					table.remove(selectionStructure.get(i));
156
				}
157
 
158
				// Désactivation des boutons si la liste est vide
159
				if (table.getItemCount() == 0) {
160
					supprimer.disable();
161
					modifier.disable();
162
				}
156 jp_milcent 163
			} else if (info.getType().equals("maj_utilisateur")) {
277 jp_milcent 164
				if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
156 jp_milcent 165
					if (table.getItemCount() != 0) {
166
						supprimer.enable();
167
					}
168
				} else {
169
					supprimer.disable();
170
				}
133 jpm 171
			}
156 jp_milcent 172
		} else {
173
			GWT.log("Ce type d'objet n'est pas pris en compte par la méthode rafraichir de la classe EntetePanneauVue", null);
60 jpm 174
		}
156 jp_milcent 175
		layout();
60 jpm 176
	}
177
}