Subversion Repositories eFlore/Applications.coel

Rev

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